Skip to content

Commit

Permalink
Add ebill_postfinance_stock
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TDu committed Dec 6, 2023
1 parent eb536eb commit 8950d74
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 28 deletions.
1 change: 0 additions & 1 deletion ebill_postfinance/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"l10n_ch_qriban",
"queue_job",
"sale",
"sale_stock",
],
"external_dependencies": {
"python": [
Expand Down
12 changes: 2 additions & 10 deletions ebill_postfinance/messages/invoice-yellowbill.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<FixedReference>
<ReferencePosition>{{ ref.position }}</ReferencePosition>
<ReferenceType>DeliveryNoteNumber</ReferenceType>
<ReferenceValue>{{ picking.name }}</ReferenceValue>
</FixedReference>
{%- endif %}
{% endfor %}
{% include invoice_line_stock_template ignore missing %}

</LineItem>
{% endfor %}
</LineItems>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions ebill_postfinance/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions ebill_postfinance/tests/examples/invoice_qr_yb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@
<ReferenceType>OrderNumberByBuyer</ReferenceType>
<ReferenceValue>CustomerRef</ReferenceValue>
</FixedReference>
<FixedReference>
<ReferencePosition>4</ReferencePosition>
<ReferenceType>DeliveryNoteNumber</ReferenceType>
<ReferenceValue>Picking Name</ReferenceValue>
</FixedReference>
</LineItem>
<LineItem>
<LineItemType>NORMAL</LineItemType>
Expand All @@ -144,20 +139,15 @@
<AmountInclusiveTax>0.0</AmountInclusiveTax>
<AmountExclusiveTax>0.0</AmountExclusiveTax>
<FixedReference>
<ReferencePosition>5</ReferencePosition>
<ReferencePosition>4</ReferencePosition>
<ReferenceType>OrderNumberBySupplier</ReferenceType>
<ReferenceValue>Order123</ReferenceValue>
</FixedReference>
<FixedReference>
<ReferencePosition>6</ReferencePosition>
<ReferencePosition>5</ReferencePosition>
<ReferenceType>OrderNumberByBuyer</ReferenceType>
<ReferenceValue>CustomerRef</ReferenceValue>
</FixedReference>
<FixedReference>
<ReferencePosition>7</ReferencePosition>
<ReferenceType>DeliveryNoteNumber</ReferenceType>
<ReferenceValue>Picking Name</ReferenceValue>
</FixedReference>
</LineItem>
<LineItem>
<LineItemType>NORMAL</LineItemType>
Expand Down
5 changes: 5 additions & 0 deletions ebill_postfinance/tests/test_ebill_postfinance_message_yb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions ebill_postfinance_stock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions ebill_postfinance_stock/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
@@ -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 %}
<FixedReference>
<ReferencePosition>{{ ref.position }}</ReferencePosition>
<ReferenceType>DeliveryNoteNumber</ReferenceType>
<ReferenceValue>{{ picking.name }}</ReferenceValue>
</FixedReference>
{%- endif %}
{% endfor %}
1 change: 1 addition & 0 deletions ebill_postfinance_stock/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ebill_postfinance_invoice_message
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions ebill_postfinance_stock/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Thierry Ducrest <[email protected]>
1 change: 1 addition & 0 deletions ebill_postfinance_stock/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module adds some information related to delivery in the eBill Postfinance integration.
1 change: 1 addition & 0 deletions ebill_postfinance_stock/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_ebill_postfinance_message_yb
60 changes: 60 additions & 0 deletions ebill_postfinance_stock/tests/test_ebill_postfinance_message_yb.py
Original file line number Diff line number Diff line change
@@ -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"<!--")
]
expected_nocomment = b"\n".join(expected_nocomment)
self.assertFalse(self.compare_xml_line_by_line(payload, expected_nocomment))
6 changes: 6 additions & 0 deletions setup/ebill_postfinance_stock/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 8950d74

Please sign in to comment.