From 8950d746f77d7edc32caea6cc952677f52a9a692 Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Mon, 17 Oct 2022 15:47:52 +0200 Subject: [PATCH] Add ebill_postfinance_stock Remove the dependency on stock in the `ebill_postfinance` module. And add a new module `ebill_postfinance_stock` that will integrate in the xml invoice informations related to the deliveries. This is for Odoo implementation that sell only services and have no stock to manage. And do not use the `stock` module. --- ebill_postfinance/__manifest__.py | 1 - .../messages/invoice-yellowbill.jinja | 12 +--- .../ebill_postfinance_invoice_message.py | 1 + ebill_postfinance/tests/common.py | 5 -- .../tests/examples/invoice_qr_yb.xml | 14 +---- .../test_ebill_postfinance_message_yb.py | 5 ++ ebill_postfinance_stock/__init__.py | 1 + ebill_postfinance_stock/__manifest__.py | 17 ++++++ .../invoice-line-stock-yellowbill.jinja | 10 ++++ ebill_postfinance_stock/models/__init__.py | 1 + .../ebill_postfinance_invoice_message.py | 24 ++++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + ebill_postfinance_stock/tests/__init__.py | 1 + .../test_ebill_postfinance_message_yb.py | 60 +++++++++++++++++++ .../odoo/addons/ebill_postfinance_stock | 1 + setup/ebill_postfinance_stock/setup.py | 6 ++ 17 files changed, 133 insertions(+), 28 deletions(-) create mode 100644 ebill_postfinance_stock/__init__.py create mode 100644 ebill_postfinance_stock/__manifest__.py create mode 100644 ebill_postfinance_stock/messages/invoice-line-stock-yellowbill.jinja create mode 100644 ebill_postfinance_stock/models/__init__.py create mode 100644 ebill_postfinance_stock/models/ebill_postfinance_invoice_message.py create mode 100644 ebill_postfinance_stock/readme/CONTRIBUTORS.rst create mode 100644 ebill_postfinance_stock/readme/DESCRIPTION.rst create mode 100644 ebill_postfinance_stock/tests/__init__.py create mode 100644 ebill_postfinance_stock/tests/test_ebill_postfinance_message_yb.py create mode 120000 setup/ebill_postfinance_stock/odoo/addons/ebill_postfinance_stock create mode 100644 setup/ebill_postfinance_stock/setup.py diff --git a/ebill_postfinance/__manifest__.py b/ebill_postfinance/__manifest__.py index 53ebd3dc9..3e12ce926 100644 --- a/ebill_postfinance/__manifest__.py +++ b/ebill_postfinance/__manifest__.py @@ -17,7 +17,6 @@ "l10n_ch_qriban", "queue_job", "sale", - "sale_stock", ], "external_dependencies": { "python": [ diff --git a/ebill_postfinance/messages/invoice-yellowbill.jinja b/ebill_postfinance/messages/invoice-yellowbill.jinja index c4e6e9dd4..49aee5d00 100644 --- a/ebill_postfinance/messages/invoice-yellowbill.jinja +++ b/ebill_postfinance/messages/invoice-yellowbill.jinja @@ -191,16 +191,8 @@ {%- endif %} {% endfor %} - {% for picking in line.sale_line_ids.move_ids.mapped('picking_id') %} - {%- if picking.state != 'cancel' %} - {% set ref.position = ref.position + 1 %} - - {{ ref.position }} - DeliveryNoteNumber - {{ picking.name }} - - {%- endif %} - {% endfor %} + {% include invoice_line_stock_template ignore missing %} + {% endfor %} diff --git a/ebill_postfinance/models/ebill_postfinance_invoice_message.py b/ebill_postfinance/models/ebill_postfinance_invoice_message.py index 3af477674..747eea29a 100644 --- a/ebill_postfinance/models/ebill_postfinance_invoice_message.py +++ b/ebill_postfinance/models/ebill_postfinance_invoice_message.py @@ -293,6 +293,7 @@ def _get_payload_params_yb(self): "ebill_account_number": self.ebill_account_number, "discount_template": "", "discount": {}, + "invoice_line_stock_template": "", } amount_by_group = [] # Get the percentage of the tax from the name of the group diff --git a/ebill_postfinance/tests/common.py b/ebill_postfinance/tests/common.py index 89eee2006..a3349f1ff 100644 --- a/ebill_postfinance/tests/common.py +++ b/ebill_postfinance/tests/common.py @@ -163,11 +163,6 @@ def setUpClass(cls): ) cls.sale.action_confirm() cls.sale.date_order = "2019-06-01" - cls.pickings = cls.sale.order_line.move_ids.mapped("picking_id") - cls.pickings[0].name = "Picking Name" - for line in cls.pickings.move_lines.move_line_ids: - line.qty_done = line.product_qty - cls.pickings._action_done() # Generate the invoice from the sale order cls.invoice = cls.sale._create_invoices() # And add some more lines on the invoice diff --git a/ebill_postfinance/tests/examples/invoice_qr_yb.xml b/ebill_postfinance/tests/examples/invoice_qr_yb.xml index 5c8e1daf5..fa60b3c59 100644 --- a/ebill_postfinance/tests/examples/invoice_qr_yb.xml +++ b/ebill_postfinance/tests/examples/invoice_qr_yb.xml @@ -118,11 +118,6 @@ OrderNumberByBuyer CustomerRef - - 4 - DeliveryNoteNumber - Picking Name - NORMAL @@ -144,20 +139,15 @@ 0.0 0.0 - 5 + 4 OrderNumberBySupplier Order123 - 6 + 5 OrderNumberByBuyer CustomerRef - - 7 - DeliveryNoteNumber - Picking Name - NORMAL diff --git a/ebill_postfinance/tests/test_ebill_postfinance_message_yb.py b/ebill_postfinance/tests/test_ebill_postfinance_message_yb.py index f1fdba3ba..ea27e9038 100644 --- a/ebill_postfinance/tests/test_ebill_postfinance_message_yb.py +++ b/ebill_postfinance/tests/test_ebill_postfinance_message_yb.py @@ -25,6 +25,11 @@ def setUpClass(cls): def test_invoice_qr(self): """Check XML payload genetated for an invoice.""" + # If ebill_postfinance_stock is installed it will break the test + try: + self.invoice.invoice_line_ids.sale_line_ids.write({"move_ids": False}) + except Exception: + pass self.invoice.name = "INV_TEST_01" self.invoice.invoice_date_due = "2019-07-01" message = self.invoice.create_postfinance_ebill() diff --git a/ebill_postfinance_stock/__init__.py b/ebill_postfinance_stock/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/ebill_postfinance_stock/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/ebill_postfinance_stock/__manifest__.py b/ebill_postfinance_stock/__manifest__.py new file mode 100644 index 000000000..fdea40247 --- /dev/null +++ b/ebill_postfinance_stock/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "eBill Postfinance Stock", + "summary": """Add stock integration to Postfinance eBill""", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "author": "Camptocamp,Odoo Community Association (OCA)", + "maintainers": ["TDu"], + "website": "https://github.com/OCA/l10n-switzerland", + "depends": [ + "ebill_postfinance", + "sale_stock", + ], + "auto_install": True, +} diff --git a/ebill_postfinance_stock/messages/invoice-line-stock-yellowbill.jinja b/ebill_postfinance_stock/messages/invoice-line-stock-yellowbill.jinja new file mode 100644 index 000000000..521b51ec7 --- /dev/null +++ b/ebill_postfinance_stock/messages/invoice-line-stock-yellowbill.jinja @@ -0,0 +1,10 @@ +{% for picking in line.sale_line_ids.move_ids.mapped('picking_id') %} +{%- if picking.state != 'cancel' %} +{% set ref.position = ref.position + 1 %} + + {{ ref.position }} + DeliveryNoteNumber + {{ picking.name }} + +{%- endif %} +{% endfor %} diff --git a/ebill_postfinance_stock/models/__init__.py b/ebill_postfinance_stock/models/__init__.py new file mode 100644 index 000000000..6c45f0783 --- /dev/null +++ b/ebill_postfinance_stock/models/__init__.py @@ -0,0 +1 @@ +from . import ebill_postfinance_invoice_message diff --git a/ebill_postfinance_stock/models/ebill_postfinance_invoice_message.py b/ebill_postfinance_stock/models/ebill_postfinance_invoice_message.py new file mode 100644 index 000000000..89bda52eb --- /dev/null +++ b/ebill_postfinance_stock/models/ebill_postfinance_invoice_message.py @@ -0,0 +1,24 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +import os + +from odoo import models +from odoo.modules.module import get_module_root + +MODULE_PATH = get_module_root(os.path.dirname(__file__)) +INVOICE_LINE_STOCK_TEMPLATE = "invoice-line-stock-yellowbill.jinja" +TEMPLATE_DIR = [MODULE_PATH + "/messages"] + + +class EbillPostfinanceInvoiceMessage(models.Model): + _inherit = "ebill.postfinance.invoice.message" + + def _get_jinja_env(self, template_dir): + template_dir += TEMPLATE_DIR + return super()._get_jinja_env(template_dir) + + def _get_payload_params_yb(self): + params = super()._get_payload_params_yb() + params["invoice_line_stock_template"] = INVOICE_LINE_STOCK_TEMPLATE + return params diff --git a/ebill_postfinance_stock/readme/CONTRIBUTORS.rst b/ebill_postfinance_stock/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..0dd376fae --- /dev/null +++ b/ebill_postfinance_stock/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Thierry Ducrest diff --git a/ebill_postfinance_stock/readme/DESCRIPTION.rst b/ebill_postfinance_stock/readme/DESCRIPTION.rst new file mode 100644 index 000000000..4789bf4f1 --- /dev/null +++ b/ebill_postfinance_stock/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds some information related to delivery in the eBill Postfinance integration. diff --git a/ebill_postfinance_stock/tests/__init__.py b/ebill_postfinance_stock/tests/__init__.py new file mode 100644 index 000000000..d5235b1f0 --- /dev/null +++ b/ebill_postfinance_stock/tests/__init__.py @@ -0,0 +1 @@ +from . import test_ebill_postfinance_message_yb diff --git a/ebill_postfinance_stock/tests/test_ebill_postfinance_message_yb.py b/ebill_postfinance_stock/tests/test_ebill_postfinance_message_yb.py new file mode 100644 index 000000000..30d9b5fdf --- /dev/null +++ b/ebill_postfinance_stock/tests/test_ebill_postfinance_message_yb.py @@ -0,0 +1,60 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from string import Template + +from freezegun import freeze_time +from lxml import etree as ET + +from odoo.modules.module import get_module_path +from odoo.tools import file_open + +from odoo.addons.ebill_postfinance.tests.common import CommonCase + + +@freeze_time("2019-06-21 09:06:00") +class TestEbillPostfinanceMessageYB(CommonCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.schema_file = ( + get_module_path("ebill_postfinance") + "/messages/ybInvoice_V2.0.4.xsd" + ) + cls.pickings = cls.sale.order_line.move_ids.mapped("picking_id") + cls.pickings[0].name = "Picking Name" + for line in cls.pickings.move_lines.move_line_ids: + line.qty_done = line.product_qty + cls.pickings._action_done() + + def test_invoice_qr(self): + """Check XML payload genetated for an invoice.""" + self.invoice.name = "INV_TEST_01" + self.invoice.invoice_date_due = "2019-07-01" + message = self.invoice.create_postfinance_ebill() + message.set_transaction_id() + message.payload = message._generate_payload_yb() + # Validate the xml generated on top of the xsd schema + node = ET.fromstring(message.payload.encode("utf-8")) + self.assertXmlValidXSchema(node, xschema=None, filename=self.schema_file) + # Remove the PDF file data from the XML to ease diff check + lines = message.payload.splitlines() + for pos, line in enumerate(lines): + if line.find("MimeType") != -1: + lines.pop(pos) + break + payload = "\n".join(lines).encode("utf8") + # Prepare the XML file that is expected + expected_tmpl = Template( + file_open("ebill_postfinance_stock/tests/examples/invoice_qr_yb.xml").read() + ) + expected = expected_tmpl.substitute( + TRANSACTION_ID=message.transaction_id, CUSTOMER_ID=self.customer.id + ).encode("utf8") + # Remove the comments in the expected xml + expected_nocomment = [ + line + for line in expected.split(b"\n") + if not line.lstrip().startswith(b"