diff --git a/edi_account_oca/__manifest__.py b/edi_account_oca/__manifest__.py index 1ec73e2c185..5952d24abfd 100644 --- a/edi_account_oca/__manifest__.py +++ b/edi_account_oca/__manifest__.py @@ -4,8 +4,8 @@ { "name": "Edi Account", "summary": """ - Define EDI Configuration for Account Moves""", - "version": "16.0.1.1.0", + Define EDI Configuration for Account Invoices""", + "version": "12.0.1.0.0", "license": "LGPL-3", "author": "Creu Blanca,Odoo Community Association (OCA)", "maintainers": ["etobella"], @@ -15,7 +15,7 @@ "data": [ "views/account_journal.xml", "views/res_partner.xml", - "views/account_move.xml", + "views/account_invoice.xml", "views/edi_exchange_record.xml", ], "demo": [], diff --git a/edi_account_oca/models/__init__.py b/edi_account_oca/models/__init__.py index 9c0a4213854..8e072db8f3e 100644 --- a/edi_account_oca/models/__init__.py +++ b/edi_account_oca/models/__init__.py @@ -1 +1 @@ -from . import account_move +from . import account_invoice diff --git a/edi_account_oca/models/account_invoice.py b/edi_account_oca/models/account_invoice.py new file mode 100644 index 00000000000..fcc19c2785f --- /dev/null +++ b/edi_account_oca/models/account_invoice.py @@ -0,0 +1,37 @@ +# Copyright 2020 Creu Blanca +# Copyright 2024 ForgeFlow +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class AccountInvoice(models.Model): + _name = "account.invoice" + _inherit = ["account.invoice", "edi.exchange.consumer.mixin"] + + disable_edi_auto = fields.Boolean( + readonly=True, + states={"draft": [("readonly", False)]}, + ) + + def action_invoice_open(self): + result = super().action_invoice_open() + # We will use this event to know which documents needs to be executed + if self: + self._event("on_open_account_invoice").notify(self) + return result + + def action_cancel(self): + """This could be used to notify our provider that we are not accepting the + invoice""" + result = super().action_cancel() + if self: + self._event("on_cancel_account_invoice").notify(self) + return result + + def action_invoice_paid(self): + """This could be used to notify our provider that we are paying""" + result = super().action_invoice_paid() + if self: + self._event("on_paid_account_invoice").notify(self) + return result diff --git a/edi_account_oca/models/account_move.py b/edi_account_oca/models/account_move.py deleted file mode 100644 index 8f3b61a3b41..00000000000 --- a/edi_account_oca/models/account_move.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2020 Creu Blanca -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). - -from odoo import fields, models - - -class AccountMove(models.Model): - _name = "account.move" - _inherit = ["account.move", "edi.exchange.consumer.mixin"] - - edi_disable_auto = fields.Boolean( - readonly=True, - states={"draft": [("readonly", False)]}, - ) - - def _post(self, soft=True): - result = super()._post(soft=soft) - # We will use this event to know which documents needs to be executed - if self: - self._event("on_post_account_move").notify(self) - return result - - def button_cancel(self): - """This could be used to notify our provider that we are not accepting the - invoice""" - result = super().button_cancel() - if self: - self._event("on_cancel_account_move").notify(self) - return result - - def _invoice_paid_hook(self): - """This could be used to notify our provider that we are paying""" - result = super()._invoice_paid_hook() - if self: - self._event("on_paid_account_move").notify(self) - return result diff --git a/edi_account_oca/readme/CONTRIBUTORS.rst b/edi_account_oca/readme/CONTRIBUTORS.rst index 93ec993e044..0379e94bf67 100644 --- a/edi_account_oca/readme/CONTRIBUTORS.rst +++ b/edi_account_oca/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ * Enric Tobella +* Jordi Masvidal diff --git a/edi_account_oca/tests/test_edi.py b/edi_account_oca/tests/test_edi.py index e26e94f1592..f3683563ff4 100644 --- a/edi_account_oca/tests/test_edi.py +++ b/edi_account_oca/tests/test_edi.py @@ -2,57 +2,59 @@ # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). import logging +from datetime import datetime from odoo import fields -from odoo.tests.common import tagged -from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.account.tests.account_test_no_chart import TestAccountNoChartCommon from odoo.addons.component.core import Component -from odoo.addons.component.tests.common import TransactionComponentRegistryCase +from odoo.addons.component.tests.common import SavepointComponentRegistryCase _logger = logging.getLogger(__name__) -@tagged("-at_install", "post_install") -class EDIBackendTestCase(AccountTestInvoicingCommon, TransactionComponentRegistryCase): +class EDIBackendTestCase(TestAccountNoChartCommon, SavepointComponentRegistryCase): @classmethod - def setUpClass(cls, chart_template_ref=None): - super().setUpClass(chart_template_ref=chart_template_ref) - cls._setup_registry(cls) + def setUpClass(cls): + super().setUpClass() + cls.setUpAdditionalAccounts() + cls.setUpAccountJournal() cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.cash_journal = cls.env["account.journal"].search( + [("type", "=", "cash"), ("company_id", "=", cls.env.user.company_id.id)] + )[0] + cls.journal_sale.update_posted = True - class AccountMoveEventListenerDemo(Component): - _name = "account.move.event.listener.demo" + class AccountInvoiceEventListenerDemo(Component): + _name = "account.invoice.event.listener.demo" _inherit = "base.event.listener" - def on_post_account_move(self, move): - move.name = "new_name" + def on_open_account_invoice(self, invoice): + invoice.name = "new_name" - def on_paid_account_move(self, move): - move.name = "paid" + def on_paid_account_invoice(self, invoice): + invoice.name = "paid" - def on_cancel_account_move(self, move): - move.name = "cancelled" + def on_cancel_account_invoice(self, invoice): + invoice.name = "cancelled" - AccountMoveEventListenerDemo._build_component(cls.comp_registry) + AccountInvoiceEventListenerDemo._build_component(cls.comp_registry) cls.comp_registry._cache.clear() - cls.test_move = ( - cls.env["account.move"] + cls.test_invoice = ( + cls.env["account.invoice"] .with_context(components_registry=cls.comp_registry) .create( { - "move_type": "out_invoice", - "partner_id": cls.partner_a.id, - "date": fields.Date.from_string("2016-01-01"), + "partner_id": cls.partner_customer_usd.id, + "date_invoice": fields.Date.from_string("2016-01-01"), + "journal_id": cls.journal_sale.id, "invoice_line_ids": [ ( 0, None, { "name": "revenue line 1", - "account_id": cls.company_data[ - "default_account_revenue" - ].id, + "account_id": cls.account_revenue.id, "quantity": 1.0, "price_unit": 100.0, }, @@ -62,43 +64,46 @@ def on_cancel_account_move(self, move): None, { "name": "revenue line 2", - "account_id": cls.company_data[ - "default_account_revenue" - ].id, + "account_id": cls.account_revenue.id, "quantity": 1.0, "price_unit": 100.0, - "tax_ids": [ - (6, 0, cls.company_data["default_tax_sale"].ids) - ], }, ), ], } ) ) - cls.test_move.invalidate_recordset() + cls.test_invoice.refresh() def test_paid_move(self): - self.test_move.action_post() - self.assertEqual(self.test_move.name, "new_name") + self.test_invoice.action_invoice_open() + self.assertEqual(self.test_invoice.name, "new_name") - payment_action = self.test_move.action_register_payment() - payment = ( - self.env[payment_action["res_model"]] - .with_context(**payment_action["context"]) + invoice_ctx = { + "active_model": "account.invoice", + "active_ids": [self.test_invoice.id], + } + register_payments = ( + self.env["account.register.payments"] + .with_context(invoice_ctx) .create( { - "journal_id": self.company_data["default_journal_bank"].id, + "payment_date": datetime.now().strftime("%Y-%m-%d"), + "payment_method_id": self.env.ref( + "account.account_payment_method_manual_in" + ).id, + "journal_id": self.cash_journal.id, + "amount": 200.0, } ) ) - payment.with_context( + register_payments.with_context( components_registry=self.comp_registry - ).action_create_payments() - self.assertEqual(self.test_move.name, "paid") + ).create_payments() + self.assertEqual(self.test_invoice.name, "paid") def test_cancel_move(self): - self.test_move.action_post() - self.assertEqual(self.test_move.name, "new_name") - self.test_move.button_cancel() - self.assertEqual(self.test_move.name, "cancelled") + self.test_invoice.action_invoice_open() + self.assertEqual(self.test_invoice.name, "new_name") + self.test_invoice.action_cancel() + self.assertEqual(self.test_invoice.name, "cancelled") diff --git a/edi_account_oca/views/account_move.xml b/edi_account_oca/views/account_invoice.xml similarity index 65% rename from edi_account_oca/views/account_move.xml rename to edi_account_oca/views/account_invoice.xml index 0970fafcde8..d9b215a701f 100644 --- a/edi_account_oca/views/account_move.xml +++ b/edi_account_oca/views/account_invoice.xml @@ -1,17 +1,13 @@ - - account.move.form (in edi_account) - account.move - + + account.invoice.form (in edi_account) + account.invoice + - - - - -