[13.0][MIG] excel_import_export, excel_import_export_demo

pull/2329/head
Kitti U 2020-08-24 17:58:31 +07:00 committed by Mantux11
parent 5a8d9946fa
commit e279ae215c
27 changed files with 344 additions and 217 deletions

View File

@ -1,135 +0,0 @@
===============================
Excel Import/Export/Report Demo
===============================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/12.0/excel_import_export_demo
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-excel_import_export_demo
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/149/12.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module provide some example use case for excel_import_export
1. Import/Export Sales Order (import_export_sale_order)
2. Import New Sales Orders (import_sale_orders)
3. Sales Orders Report (report_sale_order)
4. Print Quoation / Order (.xlsx) (report_action/sale_order)
5. Run Partner List Report (report_action/partner_list)
.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_
**Table of contents**
.. contents::
:local:
Installation
============
To install this module, you need to install **excel_import_export**
Then, simply install **excel_import_export_demo**.
Usage
=====
**Example 1:** Export/Import Excel on existing document
To test this use case, go to any Sales Order and use Export Excel or Import Excel in action menu.
**Example 2:** Import Excel Files
To test this use case, go to Settings > Excel Import/Export > Sample Import Sales Order
**Example 3:** Create Excel Report
To test this use case, go to Settings > Excel Import/Export > Sample Sales Report
**Example 4:** Printout Excel on existing document, using report action
To test this use case, go to any Sales Order and click print "Quotation / Order (.xlsx)".
**Example 5:** Run Partner List Report, using report action
To test this use case, go to menu Sales > Reporting > Partner List Report
Changelog
=========
12.0.1.0.0 (2019-08-09)
~~~~~~~~~~~~~~~~~~~~~~~
* Add 2 new examples using report action, 1) sale_order 2) partner_list
12.0.1.0.0 (2019-02-24)
~~~~~~~~~~~~~~~~~~~~~~~
* Start of the history
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20excel_import_export_demo%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Ecosoft
Contributors
~~~~~~~~~~~~
* Kitti Upariphutthiphong. <kittiu@gmail.com> (http://ecosoft.co.th)
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
.. |maintainer-kittiu| image:: https://github.com/kittiu.png?size=40px
:target: https://github.com/kittiu
:alt: kittiu
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-kittiu|
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/12.0/excel_import_export_demo>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -3,4 +3,5 @@
from . import import_export_sale_order
from . import report_sale_order
from . import report_crm_lead
from . import report_action

View File

@ -3,17 +3,21 @@
{
"name": "Excel Import/Export/Report Demo",
"version": "12.0.1.0.0",
"version": "13.0.1.0.0",
"author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/server-tools/",
"website": "https://github.com/OCA/server-tools",
"category": "Tools",
"depends": ["excel_import_export", "sale_management"],
"depends": ["excel_import_export", "sale_management", "purchase", "crm"],
"data": [
"import_export_sale_order/actions.xml",
"import_export_sale_order/templates.xml",
"import_export_purchase_order/actions.xml",
"import_export_purchase_order/templates.xml",
"report_sale_order/report_sale_order.xml",
"report_sale_order/templates.xml",
"report_crm_lead/report_crm_lead.xml",
"report_crm_lead/templates.xml",
"import_sale_orders/menu_action.xml",
"import_sale_orders/templates.xml",
# Use report action
@ -24,6 +28,6 @@
"report_action/partner_list/report_partner_list.xml",
],
"installable": True,
"development_status": "alpha",
"development_status": "Beta",
"maintainers": ["kittiu"],
}

View File

@ -24,12 +24,6 @@ msgstr ""
msgid "Allow Choose Template"
msgstr ""
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_partner_list__attachment_ids
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_sale_order__attachment_ids
msgid "Attachments"
msgstr ""
#. module: excel_import_export_demo
#: model_terms:ir.ui.view,arch_db:excel_import_export_demo.partner_list_wizard
msgid "Cancel"
@ -52,11 +46,6 @@ msgstr ""
msgid "Created on"
msgstr ""
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_partner_list__customer
msgid "Customer"
msgstr ""
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_partner_list__display_name
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_sale_order__display_name
@ -162,11 +151,6 @@ msgstr ""
msgid "State"
msgstr ""
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_partner_list__supplier
msgid "Supplier"
msgstr ""
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_sale_order__template_id
msgid "Template"
@ -191,4 +175,3 @@ msgstr ""
#: model:ir.model,name:excel_import_export_demo.model_report_sale_order
msgid "Wizard for report.sale.order"
msgstr ""

View File

@ -18,8 +18,7 @@ msgstr ""
#. module: excel_import_export_demo
#: model:ir.model.fields,help:excel_import_export_demo.field_report_sale_order__state
msgid ""
"* Choose: wizard show in user selection mode\n"
msgid "* Choose: wizard show in user selection mode\n"
"* Get: wizard show results from user action"
msgstr ""
"* 选择:用户选择模式下的向导显示\n"
@ -30,12 +29,6 @@ msgstr ""
msgid "Allow Choose Template"
msgstr "添加表单部分"
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_partner_list__attachment_ids
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_sale_order__attachment_ids
msgid "Attachments"
msgstr ""
#. module: excel_import_export_demo
#: model_terms:ir.ui.view,arch_db:excel_import_export_demo.partner_list_wizard
msgid "Cancel"
@ -58,11 +51,6 @@ msgstr "创建者"
msgid "Created on"
msgstr "创建时间"
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_partner_list__customer
msgid "Customer"
msgstr "客户"
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_partner_list__display_name
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_sale_order__display_name
@ -168,11 +156,6 @@ msgstr "销售报告样本"
msgid "State"
msgstr "状态"
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_partner_list__supplier
msgid "Supplier"
msgstr "供应商"
#. module: excel_import_export_demo
#: model:ir.model.fields,field_description:excel_import_export_demo.field_report_sale_order__template_id
msgid "Template"

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2019 Ecosoft Co., Ltd.
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).-->
<odoo>
<act_window
id="action_purchase_order_export_xlsx"
name="Export Excel"
res_model="export.xlsx.wizard"
binding_model="purchase.order"
view_mode="form"
target="new"
context="{
'template_domain': [('res_model', '=', 'purchase.order'),
('fname', '=', 'purchase_order.xlsx'),
('gname', '=', False)],
}"
/>
<act_window
id="action_purchase_order_import_xlsx"
name="Import Excel"
res_model="import.xlsx.wizard"
binding_model="purchase.order"
view_mode="form"
target="new"
context="{
'template_domain': [('res_model', '=', 'purchase.order'),
('fname', '=', 'purchase_order.xlsx'),
('gname', '=', False)],
'template_context': {},
'template_import_states': [],
}"
/>
</odoo>

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2019 Ecosoft Co., Ltd.
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).-->
<odoo>
<record id="purchase_order_xlsx_template" model="xlsx.template">
<field name="res_model">purchase.order</field>
<field name="fname">purchase_order.xlsx</field>
<field name="name">Purchase Order Template (import/export)</field>
<field name="description">Sample Purchase Order Template for testing</field>
<field
name="import_action_id"
eval="ref('action_purchase_order_import_xlsx')"
/>
<field
name="export_action_id"
eval="ref('action_purchase_order_export_xlsx')"
/>
<field name="input_instruction">
{
'__EXPORT__': {
'purchase': {
'_HEAD_': {
'B1': 'partner_id.contact_address',
'F4': 'display_name',
'H4': 'date_order',
'B8': 'user_id.display_name',
'B10': 'company_id.name',
'B12': '${"%s, %s, %s" % (object.company_id.street, object.company_id.city, object.company_id.state_id.name)}',
'B15': 'company_id.phone',
'B17': 'company_id.email',
'E8': 'partner_id.name',
'E10': 'partner_id.parent_id.name',
'E15': 'partner_id.phone',
'E17': 'partner_id.email',
'H20': 'date_planned${value or ""}#{style=date}',
'I37': 'amount_untaxed#{style=number}',
'O38': 'amount_tax#{style=number}',
'I39': 'amount_total#{style=number}',
},
'order_line': {
'B22': 'product_id.default_code',
'C22': 'name',
'E22': 'product_qty${value or 0}#{style=number}',
'F22': 'product_uom.name',
'G22': 'price_unit${value or 0}#{style=number}',
'H22': 'taxes_id.name',
}
}
},
'__IMPORT__': {
'purchase': {
'order_line': {
'B22': 'product_id',
'C22': 'name',
'E22': 'product_qty',
'F22': 'product_uom',
'G22': 'price_unit',
'H22': 'taxes_id',
'I22': 'date_planned${time.strftime("%Y-%m-%d %H:%M:%S")}',
}
}
},
}
</field>
</record>
<function model="xlsx.template" name="load_xlsx_template">
<value eval="[ref('purchase_order_xlsx_template')]" />
</function>
</odoo>

View File

@ -7,7 +7,7 @@
id="action_sale_oder_export_xlsx"
name="Export Excel"
res_model="export.xlsx.wizard"
src_model="sale.order"
binding_model="sale.order"
view_mode="form"
target="new"
context="{
@ -20,7 +20,7 @@
id="action_sale_oder_import_xlsx"
name="Import Excel"
res_model="import.xlsx.wizard"
src_model="sale.order"
binding_model="sale.order"
view_mode="form"
target="new"
context="{

View File

@ -6,8 +6,10 @@
<record id="sale_order_xlsx_template" model="xlsx.template">
<field name="res_model">sale.order</field>
<field name="fname">sale_order.xlsx</field>
<field name="name">Sale Order Template</field>
<field name="description">Sample Sales Order Tempalte for testing</field>
<field name="name">Sale Order Template (import/export)</field>
<field name="description">Sample Sales Order Template for testing</field>
<field name="import_action_id" eval="ref('action_sale_oder_export_xlsx')" />
<field name="export_action_id" eval="ref('action_sale_oder_import_xlsx')" />
<field name="input_instruction">
{
'__EXPORT__': {

View File

@ -6,7 +6,7 @@
<record id="action_import_sale_order" model="ir.actions.act_window">
<field name="name">Sample Import Sale Order</field>
<field name="res_model">import.xlsx.wizard</field>
<field name="view_type">form</field>
<field name="binding_view_types">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{

View File

@ -1,9 +1,4 @@
12.0.1.0.0 (2019-08-09)
13.0.1.0.0 (2020-08-23)
~~~~~~~~~~~~~~~~~~~~~~~
* Add 2 new examples using report action, 1) sale_order 2) partner_list
12.0.1.0.0 (2019-02-24)
~~~~~~~~~~~~~~~~~~~~~~~
* Start of the history
* Migration to Odoo 13

View File

@ -1,16 +1,14 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from odoo import api, fields, models
from odoo import fields, models
class ReportPartnerList(models.TransientModel):
_name = "report.partner.list"
_description = "Wizard for report.partner.list"
partner_ids = fields.Many2many(comodel_name="res.partner",)
supplier = fields.Boolean(default=True,)
customer = fields.Boolean(default=True,)
partner_ids = fields.Many2many(comodel_name="res.partner")
results = fields.Many2many(
"res.partner",
string="Results",
@ -18,17 +16,12 @@ class ReportPartnerList(models.TransientModel):
help="Use compute fields, so there is nothing store in database",
)
@api.multi
def _compute_results(self):
"""On the wizard, result will be computed and added to results line
before export to excel by report_excel action
"""
self.ensure_one()
domain = [
"|",
("supplier", "=", self.supplier),
("customer", "=", self.customer),
]
domain = []
if self.partner_ids:
domain.append(("id", "in", self.partner_ids.ids))
self.results = self.env["res.partner"].search(domain, order="id")

View File

@ -10,8 +10,6 @@
<field name="partner_ids" widget="many2many_tags" />
</group>
<group>
<field name="customer" />
<field name="supplier" />
</group>
</group>
<footer>
@ -29,7 +27,7 @@
<record id='action_report_partner_list' model='ir.actions.act_window'>
<field name='name'>Partner List Report</field>
<field name='res_model'>report.partner.list</field>
<field name='view_type'>form</field>
<field name='binding_view_types'>form</field>
<field name='view_mode'>form</field>
<field name='target'>new</field>
</record>

View File

@ -0,0 +1,4 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from . import report_crm_lead

View File

@ -0,0 +1,65 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from odoo import fields, models
class ReportCRMLead(models.TransientModel):
_name = "report.crm.lead"
_description = "Wizard for report.crm.lead"
_inherit = "xlsx.report"
# Search Criteria
team_id = fields.Many2one("crm.team", string="Sales Team")
# Report Result, crm.lead
results = fields.Many2many(
"crm.lead",
compute="_compute_results",
)
revenue_by_country = fields.Many2many(
"crm.lead",
compute="_compute_revenue_by_country",
)
revenue_by_team = fields.Many2many(
"crm.lead",
compute="_compute_revenue_by_team",
)
def _compute_results(self):
self.ensure_one()
domain = []
if self.team_id:
domain += [("team_id", "=", self.team_id.id)]
self.results = self.env["crm.lead"].search(domain)
def _compute_revenue_by_country(self):
self.ensure_one()
domain = []
if self.team_id:
domain += [("team_id", "=", self.team_id.id)]
results = self.env["crm.lead"].read_group(
domain,
["country_id", "planned_revenue"],
["country_id"],
orderby="country_id",
)
for row in results:
self.revenue_by_country += self.env["crm.lead"].new(
{
"country_id": row["country_id"],
"planned_revenue": row["planned_revenue"],
}
)
def _compute_revenue_by_team(self):
self.ensure_one()
domain = []
if self.team_id:
domain += [("team_id", "=", self.team_id.id)]
results = self.env["crm.lead"].read_group(
domain, ["team_id", "planned_revenue"], ["team_id"], orderby="team_id"
)
for row in results:
self.revenue_by_team += self.env["crm.lead"].new(
{"team_id": row["team_id"], "planned_revenue": row["planned_revenue"]}
)

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2019 Ecosoft Co., Ltd.
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).-->
<odoo>
<record id="report_crm_lead" model="ir.ui.view">
<field name="name">report.crm.lead</field>
<field name="model">report.crm.lead</field>
<field name="inherit_id" ref="excel_import_export.xlsx_report_view" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//group[@name='criteria']" position="inside">
<group>
<field name="team_id" />
</group>
<group>
</group>
</xpath>
</field>
</record>
<record id="action_report_crm_lead" model="ir.actions.act_window">
<field name="name">Sample Lead Report</field>
<field name="res_model">report.crm.lead</field>
<field name="binding_view_types">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">
{'template_domain': [('res_model', '=', 'report.crm.lead'),
('fname', '=', 'report_crm_lead.xlsx'),
('gname', '=', False)]}
</field>
</record>
<menuitem
id="menu_report_crm_lead"
parent="excel_import_export.menu_excel_import_export"
action="action_report_crm_lead"
sequence="20"
/>
</odoo>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2019 Ecosoft Co., Ltd.
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).-->
<odoo>
<record id="report_crm_lead_template" model="xlsx.template">
<field name="res_model">report.crm.lead</field>
<field name="fname">report_crm_lead.xlsx</field>
<field name="name">Report CRM Lead Template</field>
<field name="description">Sample Report Sales Order Tempalte for testing</field>
<field name="input_instruction">
{
'__EXPORT__': {
'crm_lead': {
'results': {
'A4': 'name',
'B4': 'partner_id.name',
'C4': 'country_id.name',
'D4': 'activity_date_deadline${value or ""}#{style=date}',
'E4': 'activity_summary',
'F4': 'stage_id.name',
'G4': 'planned_revenue${value or 0}#{style=number}',
'H4': 'team_id.name',
},
},
'revenue_by_country': {
'revenue_by_country': {
'A3': 'country_id.name',
'B3': 'planned_revenue${value or 0}#{style=number}'
},
},
'revenue_by_team': {
'revenue_by_team': {
'A3': 'team_id.name',
'B3': 'planned_revenue${value or 0}#{style=number}'
},
},
},
}
</field>
</record>
<function model="xlsx.template" name="load_xlsx_template">
<value eval="[ref('report_crm_lead_template')]" />
</function>
</odoo>

View File

@ -1,7 +1,7 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from openerp import api, fields, models
from odoo import fields, models
class ReportSaleOrder(models.TransientModel):
@ -10,7 +10,7 @@ class ReportSaleOrder(models.TransientModel):
_inherit = "xlsx.report"
# Search Criteria
partner_id = fields.Many2one("res.partner", string="Partner",)
partner_id = fields.Many2one("res.partner", string="Partner")
# Report Result, sale.order
results = fields.Many2many(
"sale.order",
@ -19,7 +19,6 @@ class ReportSaleOrder(models.TransientModel):
help="Use compute fields, so there is nothing stored in database",
)
@api.multi
def _compute_results(self):
"""On the wizard, result will be computed and added to results line
before export to excel, by using xlsx.export

View File

@ -21,7 +21,7 @@
<record id="action_report_sale_order" model="ir.actions.act_window">
<field name="name">Sample Sales Report</field>
<field name="res_model">report.sale.order</field>
<field name="view_type">form</field>
<field name="binding_view_types">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">

View File

@ -15,9 +15,9 @@
'_HEAD_': {
'B2': 'partner_id.display_name${value or ""}#{align=left;style=text}',
},
'results': {
'_EXTEND_results': {
'A5': 'name${value or ""}#{style=text}',
'B5': 'confirmation_date${value or ""}#{style=date}',
'B5': 'date_order${value or ""}#{style=date}',
'C5': 'amount_untaxed${value or 0}#{style=number}@{sum}',
'D5': 'amount_tax${value or 0}#{style=number}@{sum}',
'E5': 'amount_total${value or 0}#{style=number}@{sum}',

View File

@ -50,7 +50,7 @@ class TestExcelImportExport(SingleTransactionCase):
"res_model": "sale.order",
"fname": "sale_order.xlsx",
"name": "Sale Order Template",
"description": "Sample Sales Order Tempalte for testing",
"description": "Sample Sales Order Template for testing",
"input_instruction": str(input_instruction),
}
cls.sample_template = cls.template_obj.create(vals)
@ -86,7 +86,7 @@ class TestExcelImportExport(SingleTransactionCase):
"price_unit": cls.product_order.list_price,
"tax_id": False,
}
for i in range(10):
for _i in range(10):
cls.env["sale.order"].create(
{
"partner_id": cls.partner.id,
@ -98,14 +98,14 @@ class TestExcelImportExport(SingleTransactionCase):
def setUpPrepSaleOrder(cls):
categ_ids = cls.env["res.partner.category"].search([]).ids
cls.partner = cls.env["res.partner"].create(
{"name": "Test Partner", "category_id": [(6, 0, categ_ids)],}
{"name": "Test Partner", "category_id": [(6, 0, categ_ids)]}
)
# Create a Product
user_type_income = cls.env.ref("account.data_account_type_direct_costs")
cls.account_income_product = cls.env["account.account"].create(
{
"code": "INCOME_PROD111",
"name": "Icome - Test Account",
"name": "Income - Test Account",
"user_type_id": user_type_income.id,
}
)

View File

@ -29,7 +29,7 @@ class TestXLSXImportExport(TestExcelImportExport):
# Test whether it loads correct template
self.assertEqual(
export_wizard.template_id,
self.env.ref("excel_import_export_demo." "sale_order_xlsx_template"),
self.env.ref("excel_import_export_demo.sale_order_xlsx_template"),
)
# Export excel
export_wizard.action_export()
@ -56,7 +56,23 @@ class TestXLSXImportExport(TestExcelImportExport):
# Test whether it loads correct template
self.assertEqual(
import_wizard.template_id,
self.env.ref("excel_import_export_demo." "sale_order_xlsx_template"),
self.env.ref("excel_import_export_demo.sale_order_xlsx_template"),
)
# Import Excel
import_wizard.action_import()
def test_add_remove_export_import_action(self):
""" On the template itself, test add / remove action """
template = self.env.ref("excel_import_export_demo.sale_order_xlsx_template")
self.assertTrue(template.import_action_id)
self.assertTrue(template.export_action_id)
# Remove actions
template.remove_export_action()
template.remove_import_action()
self.assertFalse(template.import_action_id)
self.assertFalse(template.export_action_id)
# Add actions back again
template.add_export_action()
template.add_import_action()
self.assertTrue(template.import_action_id)
self.assertTrue(template.export_action_id)

View File

@ -19,7 +19,7 @@ class TestXLSXReport(TestExcelImportExport):
("res_model", "=", "report.sale.order"),
("fname", "=", "report_sale_order.xlsx"),
("gname", "=", False),
],
]
}
with Form(self.env["report.sale.order"].with_context(ctx)) as f:
f.partner_id = self.partner

View File

@ -2,6 +2,9 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from ast import literal_eval
from odoo.exceptions import UserError
from odoo.tests.common import Form
from .test_common import TestExcelImportExport
@ -10,8 +13,8 @@ class TestXLSXTemplate(TestExcelImportExport):
def setUpClass(cls):
super(TestExcelImportExport, cls).setUpClass()
def test_xlsx_tempalte(self):
""" Test XLSX Tempalte input and output instruction """
def test_xlsx_template(self):
""" Test XLSX Template input and output instruction """
self.setUpXLSXTemplate()
instruction_dict = literal_eval(self.sample_template.instruction)
self.assertDictEqual(
@ -58,3 +61,31 @@ class TestXLSXTemplate(TestExcelImportExport):
[self.sample_template.id], addon="excel_import_export_demo"
)
self.assertTrue(self.sample_template.datas) # Loaded successfully
def test_xlsx_template_easy_reporting(self):
""" Test XLSX template using easy reporting option """
sale_model = self.env["ir.model"].search([("model", "=", "sale.order")])
# Create the template
with Form(self.env["xlsx.template"]) as f:
f.name = "Test Easy Reporting"
f.use_report_wizard = True
f.result_model_id = sale_model
template = f.save()
self.assertEqual(template.res_model, "report.xlsx.wizard")
self.assertFalse(template.redirect_action, False)
self.assertTrue(template.result_field)
self.assertFalse(template.report_menu_id)
self.assertEqual(len(template.export_ids), 3)
with self.assertRaises(UserError):
template.add_report_menu()
template.fname = "test.xlsx"
# Add the menu
template.add_report_menu()
self.assertTrue(template.report_menu_id)
res = template.report_menu_id.action.read()[0]
ctx = literal_eval(res["context"])
f = Form(self.env[res["res_model"]].with_context(ctx))
report_wizard = f.save()
res = report_wizard.action_report()
# Finally reture the report action
self.assertEqual(res["type"], "ir.actions.report")