diff --git a/edi_account/__init__.py b/edi_account/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/edi_account/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/edi_account/__manifest__.py b/edi_account/__manifest__.py new file mode 100644 index 00000000000..23bf81da5f0 --- /dev/null +++ b/edi_account/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2020 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Edi Account", + "summary": """ + Define EDI Configuration for Account Moves""", + "version": "12.0.1.0.0", + "license": "LGPL-3", + "author": "Creu Blanca,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/edi", + "depends": ["account", "edi_oca", "component_event"], + "data": [ + "views/account_invoice.xml", + ], + "demo": [], +} diff --git a/edi_account/models/__init__.py b/edi_account/models/__init__.py new file mode 100644 index 00000000000..8e072db8f3e --- /dev/null +++ b/edi_account/models/__init__.py @@ -0,0 +1 @@ +from . import account_invoice diff --git a/edi_account/models/account_invoice.py b/edi_account/models/account_invoice.py new file mode 100644 index 00000000000..16258c0475e --- /dev/null +++ b/edi_account/models/account_invoice.py @@ -0,0 +1,31 @@ +# Copyright 2020 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import models + + +class AccountInvoice(models.Model): + _name = "account.invoice" + _inherit = ["account.invoice", "edi.exchange.consumer.mixin"] + + 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/tests/__init__.py b/edi_account/tests/__init__.py new file mode 100644 index 00000000000..25aeb70b83e --- /dev/null +++ b/edi_account/tests/__init__.py @@ -0,0 +1 @@ +from . import test_edi diff --git a/edi_account/tests/test_edi.py b/edi_account/tests/test_edi.py new file mode 100644 index 00000000000..08e910ae0de --- /dev/null +++ b/edi_account/tests/test_edi.py @@ -0,0 +1,112 @@ +# Copyright 2020 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +import logging +import datetime + +from odoo import fields + +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 SavepointComponentRegistryCase + +_logger = logging.getLogger(__name__) + + +class EDIBackendTestCase(TestAccountNoChartCommon, SavepointComponentRegistryCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + 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.company.id)] + )[0] + + class AccountInvoiceEventListenerDemo(Component): + _name = "account.invoice.event.listener.demo" + _inherit = "base.event.listener" + + def on_post_account_invoice(self, invoice): + invoice.name = "new_name" + + def on_paid_account_invoice(self, invoice): + invoice.name = "paid" + + def on_cancel_account_invoice(self, invoice): + invoice.name = "cancelled" + + AccountInvoiceEventListenerDemo._build_component(cls.comp_registry) + cls.comp_registry._cache.clear() + cls.test_invoice = ( + cls.env["account.invoice"] + .with_context(components_registry=cls.comp_registry) + .create( + { + "partner_id": cls.partner_a.id, + "date_invoice": fields.Date.from_string("2016-01-01"), + "invoice_line_ids": [ + ( + 0, + None, + { + "name": "revenue line 1", + "account_id": cls.company_data[ + "default_account_revenue" + ].id, + "quantity": 1.0, + "price_unit": 100.0, + }, + ), + ( + 0, + None, + { + "name": "revenue line 2", + "account_id": cls.company_data[ + "default_account_revenue" + ].id, + "quantity": 1.0, + "price_unit": 100.0, + "tax_ids": [ + (6, 0, cls.company_data["default_tax_sale"].ids) + ], + }, + ), + ], + } + ) + ) + cls.test_invoice.refresh() + + def test_paid_move(self): + self.test_invoice.action_invoice_open() + self.assertEqual(self.test_invoice.name, "new_name") + + invoice_ctx = { + "active_model": "account.invoice", + "active_ids": [self.test_invoice.id], + } + register_payments = ( + self.env["account.register.payments"] + .with_context(invoice_ctx) + .create( + { + "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, + } + ) + ) + register_payments.with_context( + components_registry=self.comp_registry + ).create_payments() + self.assertEqual(self.test_invoice.name, "paid") + + def test_cancel_move(self): + 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/views/account_invoice.xml b/edi_account/views/account_invoice.xml new file mode 100644 index 00000000000..49c77221008 --- /dev/null +++ b/edi_account/views/account_invoice.xml @@ -0,0 +1,28 @@ + + + + + account.invoice.form (in edi_account) + account.invoice + + + + + + + +