From fb80957fbae2e7ca39fe054c4c0c518eca5fb3f5 Mon Sep 17 00:00:00 2001 From: Magno Costa Date: Tue, 4 Feb 2025 14:41:04 -0300 Subject: [PATCH 1/2] [REF] l10n_br_purchase: Load Demo Data by hook --- l10n_br_purchase/__manifest__.py | 5 - .../demo/fiscal_operation_generic.xml | 71 ---------- .../demo/fiscal_operation_simple.xml | 134 ------------------ l10n_br_purchase/hooks.py | 117 ++++++++++++--- 4 files changed, 100 insertions(+), 227 deletions(-) delete mode 100644 l10n_br_purchase/demo/fiscal_operation_generic.xml delete mode 100644 l10n_br_purchase/demo/fiscal_operation_simple.xml diff --git a/l10n_br_purchase/__manifest__.py b/l10n_br_purchase/__manifest__.py index 6901587bd1cd..47411a7f3835 100644 --- a/l10n_br_purchase/__manifest__.py +++ b/l10n_br_purchase/__manifest__.py @@ -22,11 +22,6 @@ "reports/purchase_report_views.xml", # "reports/purchase_order_templates.xml", ], - "demo": [ - "demo/company.xml", - "demo/product.xml", - "demo/l10n_br_purchase.xml", - ], "installable": True, "post_init_hook": "post_init_hook", "auto_install": False, diff --git a/l10n_br_purchase/demo/fiscal_operation_generic.xml b/l10n_br_purchase/demo/fiscal_operation_generic.xml deleted file mode 100644 index 6b12055d52f6..000000000000 --- a/l10n_br_purchase/demo/fiscal_operation_generic.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - fiscal_operation_journal_id - - - - - - - - - fiscal_operation_journal_id - - - - - - - - - fiscal_operation_journal_id - - - - - - - diff --git a/l10n_br_purchase/demo/fiscal_operation_simple.xml b/l10n_br_purchase/demo/fiscal_operation_simple.xml deleted file mode 100644 index 8930361c7cb4..000000000000 --- a/l10n_br_purchase/demo/fiscal_operation_simple.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - - fiscal_operation_journal_id - - - - - - - - fiscal_operation_journal_id - - - - - - - - - fiscal_operation_journal_id - - - - - - - - fiscal_operation_journal_id - - - - - - - - - fiscal_operation_journal_id - - - - - - - - fiscal_operation_journal_id - - - - - - - diff --git a/l10n_br_purchase/hooks.py b/l10n_br_purchase/hooks.py index 5493430237eb..fbb73bbdebd5 100644 --- a/l10n_br_purchase/hooks.py +++ b/l10n_br_purchase/hooks.py @@ -1,12 +1,48 @@ # Copyright (C) 2020 Renato Lima - Akretion # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from odoo import SUPERUSER_ID, api, tools +import logging + +from odoo import SUPERUSER_ID, _, api, tools + +from odoo.addons.l10n_br_fiscal.tools import inform_journal_in_fiscal_operation + +_logger = logging.getLogger(__name__) def post_init_hook(cr, registry): - cr.execute("select demo from ir_module_module where name='l10n_br_purchase';") - if cr.fetchone()[0]: + if not tools.config["without_demo"]: + _logger.info(_("Loading l10n_br_purchase/demo/company.xml ...")) + tools.convert_file( + cr, + "l10n_br_purchase", + "demo/company.xml", + None, + mode="init", + noupdate=True, + kind="init", + ) + _logger.info(_("Loading l10n_br_purchase/demo/product.xml ...")) + tools.convert_file( + cr, + "l10n_br_purchase", + "demo/product.xml", + None, + mode="init", + noupdate=True, + kind="init", + ) + _logger.info(_("Loading l10n_br_purchase/demo/l10n_br_purchase.xml ...")) + tools.convert_file( + cr, + "l10n_br_purchase", + "demo/l10n_br_purchase.xml", + None, + mode="init", + noupdate=True, + kind="init", + ) + env = api.Environment(cr, SUPERUSER_ID, {}) purchase_orders = env["purchase.order"].search( [("company_id", "!=", env.ref("base.main_company").id)] @@ -25,6 +61,13 @@ def post_init_hook(cr, registry): ) order.write(defaults) + # Load COA Fiscal Operation properties + purchase_inform_journal_in_fiscal_operation(cr) + + +def purchase_inform_journal_in_fiscal_operation(cr): + if not tools.config["without_demo"]: + env = api.Environment(cr, SUPERUSER_ID, {}) # Load COA Fiscal Operation properties company = env.ref( "l10n_br_base.empresa_simples_nacional", raise_if_not_found=False @@ -36,14 +79,44 @@ def post_init_hook(cr, registry): ("state", "=", "installed"), ] ): - tools.convert_file( + # Load Fiscal Operation Main Company + inform_journal_in_fiscal_operation( + cr, + env.ref("base.main_company"), + [ + { + "fiscal_operation": "l10n_br_fiscal.fo_compras", + "journal": "l10n_br_coa_simple.purchase_journal_main_company", + }, + { + "fiscal_operation": "l10n_br_fiscal.fo_devolucao_compras", + "journal": "l10n_br_coa_simple.general_journal_main_company", + }, + { + "fiscal_operation": "l10n_br_fiscal.fo_entrada_remessa", + "journal": "l10n_br_coa_simple.general_journal_main_company", + }, + ], + ) + + # Load Fiscal Operation for Simples Nacional + inform_journal_in_fiscal_operation( cr, - "l10n_br_purchase", - "demo/fiscal_operation_simple.xml", - None, - mode="init", - noupdate=True, - kind="init", + company, + [ + { + "fiscal_operation": "l10n_br_fiscal.fo_compras", + "journal": "l10n_br_coa_simple.purchase_journal_empresa_sn", + }, + { + "fiscal_operation": "l10n_br_fiscal.fo_devolucao_compras", + "journal": "l10n_br_coa_simple.general_journal_empresa_sn", + }, + { + "fiscal_operation": "l10n_br_fiscal.fo_entrada_remessa", + "journal": "l10n_br_coa_simple.general_journal_empresa_sn", + }, + ], ) company_lc = env.ref( @@ -57,12 +130,22 @@ def post_init_hook(cr, registry): ("state", "=", "installed"), ] ): - tools.convert_file( + # Load Fiscal Operation for Lucro Presumido + inform_journal_in_fiscal_operation( cr, - "l10n_br_purchase", - "demo/fiscal_operation_generic.xml", - None, - mode="init", - noupdate=True, - kind="init", + company_lc, + [ + { + "fiscal_operation": "l10n_br_fiscal.fo_compras", + "journal": "l10n_br_coa_generic.purchase_journal_empresa_lp", + }, + { + "fiscal_operation": "l10n_br_fiscal.fo_devolucao_compras", + "journal": "l10n_br_coa_generic.general_journal_empresa_lp", + }, + { + "fiscal_operation": "l10n_br_fiscal.fo_entrada_remessa", + "journal": "l10n_br_coa_generic.general_journal_empresa_lp", + }, + ], ) From f7dfa1a90cda64d4e1bbf6c523c03b51ad9f1373 Mon Sep 17 00:00:00 2001 From: Magno Costa Date: Tue, 4 Feb 2025 14:41:56 -0300 Subject: [PATCH 2/2] [UPD] l10n_br_purchase: README pre-commit --- l10n_br_purchase/README.rst | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/l10n_br_purchase/README.rst b/l10n_br_purchase/README.rst index 4fc52bc75fa5..072bf28f67de 100644 --- a/l10n_br_purchase/README.rst +++ b/l10n_br_purchase/README.rst @@ -53,8 +53,8 @@ Installation This module depends on: -- purchase -- l10n_br_account +- purchase +- l10n_br_account Configuration ============= @@ -77,22 +77,22 @@ Changelog 14.0.1.0.0 (2022-06-02) ----------------------- -- Module migration. +- Module migration. 13.0.1.0.0 (2021-01-14) ----------------------- -- Module migration. +- Module migration. 12.0.1.0.0 (2021-01-30) ----------------------- -- Module migration. +- Module migration. 10.0.1.0.0 (2019-09-20) ----------------------- -- Module migration. +- Module migration. Bug Tracker =========== @@ -115,21 +115,21 @@ Authors Contributors ------------ -- `Akretion `__: +- `Akretion `__: - - Renato Lima - - Raphaël Valyi + - Renato Lima + - Raphaël Valyi -- `KMEE `__: +- `KMEE `__: - - Luis Felipe Mileo + - Luis Felipe Mileo Other credits ------------- The development of this module has been financially supported by: -- AKRETION LTDA - `www.akretion.com `__ +- AKRETION LTDA - `www.akretion.com `__ Maintainers -----------