mirror of
https://gitlab.com/flectra-community/l10n-switzerland-flectra.git
synced 2024-12-23 12:51:45 +00:00
22ee40100d
[FIX] l10n_ch_zip [ADD] Added latest OCA Modules [REMOVE] Removed QR modules which are not required anymore
78 lines
3.0 KiB
Python
78 lines
3.0 KiB
Python
# Copyright 2019 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 flectra.tools import file_open
|
|
|
|
from .common import CommonCase
|
|
|
|
|
|
@freeze_time("2019-06-21 09:06:00")
|
|
class TestInvoiceMessage(CommonCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super().setUpClass()
|
|
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
|
|
|
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_paynet_message()
|
|
message.payload = message._generate_payload()
|
|
# Remove the PDF file data from the XML to ease testing
|
|
lines = message.payload.splitlines()
|
|
for pos, line in enumerate(lines):
|
|
if line.find("Back-Pack") != -1:
|
|
lines.pop(pos)
|
|
break
|
|
payload = "\n".join(lines).encode("utf8")
|
|
self.assertXmlDocument(payload)
|
|
# Prepare the XML file that is expected
|
|
expected_tmpl = Template(
|
|
file_open("ebill_paynet/tests/examples/invoice_qr_b2b.xml").read()
|
|
)
|
|
expected = expected_tmpl.substitute(IC_REF=message.ic_ref).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))
|
|
self.assertXmlEquivalentOutputs(payload, expected_nocomment)
|
|
|
|
def test_invoice_esr(self):
|
|
""" Check XML payload genetated for an invoice."""
|
|
self.contract.payment_type = "isr"
|
|
self.invoice.name = "INV_TEST_01"
|
|
self.invoice.invoice_date_due = "2019-07-01"
|
|
message = self.invoice.create_paynet_message()
|
|
message.payload = message._generate_payload()
|
|
# Remove the PDF file data from the XML to ease testing
|
|
lines = message.payload.splitlines()
|
|
for pos, line in enumerate(lines):
|
|
if line.find("Back-Pack") != -1:
|
|
lines.pop(pos)
|
|
break
|
|
payload = "\n".join(lines).encode("utf8")
|
|
self.assertXmlDocument(payload)
|
|
# Prepare the XML file that is expected
|
|
expected_tmpl = Template(
|
|
file_open("ebill_paynet/tests/examples/invoice_isr_b2b.xml").read()
|
|
)
|
|
expected = expected_tmpl.substitute(IC_REF=message.ic_ref).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))
|
|
self.assertXmlEquivalentOutputs(payload, expected_nocomment)
|