Skip to content

Commit

Permalink
Merge pull request #677 from camptocamp/ebillpostfinance-financialdis…
Browse files Browse the repository at this point in the history
…count

[14.0][ADD] ebill_postfinance_financial_discount
  • Loading branch information
TDu authored Nov 15, 2024
2 parents 82c8edf + 0870d0e commit f764ce1
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 6 deletions.
14 changes: 10 additions & 4 deletions ebill_postfinance/messages/invoice-yellowbill.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,16 @@
<TotalTax>{{ invoice.amount_tax|round(6) }}</TotalTax>
</Tax>
{% endif -%}
{# <Discount> #}
{# <Days></Days> #}
{# <Rate></Rate> #}
{# </Discount> #}
{% for discount in discounts %}
<Discount>
{% if discount.days %}
<Days>{{ discount.days }}</Days>
{% else %}
<DiscountDate>{{ discount.date }}</DiscountDate>
{% endif -%}
<Rate>{{ discount.percentage }}</Rate>
</Discount>
{% endfor -%}
<TotalAmountExclusiveTax>{{ invoice.amount_untaxed * amount_sign }}</TotalAmountExclusiveTax>
<TotalAmountInclusiveTax>{{ invoice.amount_total * amount_sign }}</TotalAmountInclusiveTax>
{# <TotalAmountPaid></TotalAmountPaid> #}
Expand Down
4 changes: 2 additions & 2 deletions ebill_postfinance/models/ebill_postfinance_invoice_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _get_payload_params(self):
"format_date": self.format_date,
"ebill_account_number": self.ebill_account_number,
"discount_template": "",
"discount": {},
"discounts": [],
}
amount_by_group = []
# Get the percentage of the tax from the name of the group
Expand Down Expand Up @@ -292,7 +292,7 @@ def _get_payload_params_yb(self):
"format_date": self.format_date_yb,
"ebill_account_number": self.ebill_account_number,
"discount_template": "",
"discount": {},
"discounts": [],
"invoice_line_stock_template": "",
}
amount_by_group = []
Expand Down
1 change: 1 addition & 0 deletions ebill_postfinance_financial_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions ebill_postfinance_financial_discount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "eBill Postfinance Financial Discount",
"summary": "Integrate the discount from account_financial_discount into ebill_postfinance",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Camptocamp,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-switzerland",
"depends": ["ebill_postfinance", "account_financial_discount"],
"auto_install": True,
}
Empty file.
1 change: 1 addition & 0 deletions ebill_postfinance_financial_discount/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,20 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import models


class EbillPostfinanceInvoiceMessage(models.Model):
_inherit = "ebill.postfinance.invoice.message"

def _get_payload_params_yb(self):
params = super()._get_payload_params_yb()
if self.invoice_id.invoice_payment_term_id.percent_discount:
terms = self.invoice_id.invoice_payment_term_id
params["discounts"].append(
{
"percentage": terms.percent_discount,
"days": terms.days_discount,
}
)
return params
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Thierry Ducrest <[email protected]>
2 changes: 2 additions & 0 deletions ebill_postfinance_financial_discount/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module interconnects the `account_financial_discount` from account-payment with
the `ebill_postfinance` module.
1 change: 1 addition & 0 deletions ebill_postfinance_financial_discount/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_postfinance_financial_discount
186 changes: 186 additions & 0 deletions ebill_postfinance_financial_discount/tests/examples/invoice_qr_yb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" type="string">
<Header>
<From>Camptocamp SA</From>
<To>IPECeBILLServer</To>
<UseCase>CreateybInvoice</UseCase>
<SessionID>1</SessionID>
<Version>2.0</Version>
<Status>0</Status>
<SoftwareName>Odoo</SoftwareName>
<SoftwareVersion>14.0</SoftwareVersion>
</Header>
<Body>
<DeliveryInfo>
<BillerID>41101000001021209</BillerID>
<eBillAccountID>41010198248040391</eBillAccountID>
<DeliveryDate>2019-06-21</DeliveryDate>
<TransactionID>$TRANSACTION_ID</TransactionID>
<BillDetailsType>PDFAppendix</BillDetailsType>
<URLBillDetails/>
</DeliveryInfo>
<Bill>
<Header>
<DocumentType>BILL</DocumentType>
<DocumentID>INV_TEST_01</DocumentID>
<DocumentDate>2019-06-21</DocumentDate>
<SenderParty>
<TaxLiability>VAT</TaxLiability>
<PartyType>
<Address>
<CompanyName>Camptocamp SA</CompanyName>
<Address1>StreetOne</Address1>
<ZIP>1015</ZIP>
<City>Lausanne</City>
<Country>CH</Country>
<Email>[email protected]</Email>
</Address>
<TaxID>CHE012345678</TaxID>
</PartyType>
</SenderParty>
<ReceiverParty>
<PartyType>
<CustomerID>$CUSTOMER_ID</CustomerID>
<Address>
<CompanyName>Test RAD Customer XML</CompanyName>
<Address1>Teststrasse 100</Address1>
<Address2>This is a very long street name that should be sna</Address2>
<ZIP>1700</ZIP>
<City>Fribourg</City>
<Country>CH</Country>
</Address>
<!-- <TaxID>CHE333222111</TaxID> -->
</PartyType>
</ReceiverParty>
<DeliveryPlace>
<Address>
<CompanyName>Test RAD Customer XML</CompanyName>
<ZIP>1700</ZIP>
<City>Fribourg</City>
<Country>CH</Country>
<!-- <Contact1>0000000001</Contact1> -->
</Address>
</DeliveryPlace>
<AchievementDate>
<StartDateAchievement>2019-06-21</StartDateAchievement>
<EndDateAchievement>2019-06-21</EndDateAchievement>
</AchievementDate>
<Currency>CHF</Currency>
<AccountAssignment>
<OrderReference>
<ReferencePosition>1</ReferencePosition>
<ReferenceType>OrderReference</ReferenceType>
<ReferenceValue>CustomerRef</ReferenceValue>
</OrderReference>
<OrderDate>2019-06-01</OrderDate>
</AccountAssignment>
<Language>en</Language>
<PaymentInformation>
<PaymentDueDate>2019-08-20</PaymentDueDate>
<PaymentType>IBAN</PaymentType>
<fixAmount>Yes</fixAmount>
<IBAN>
<BIC>777</BIC>
<BankName>Reserve</BankName>
<IBAN>CH2130808001234567827</IBAN>
<CreditorReference>1234567890</CreditorReference>
</IBAN>
</PaymentInformation>
<!-- <FreeText>Dies ist eine Musterrechnung mit QR-IBAN Angaben</FreeText> -->
</Header>
<LineItems>
<LineItem>
<LineItemType>NORMAL</LineItemType>
<LineItemID>1</LineItemID>
<ProductDescription>Product Q &amp; A</ProductDescription>
<ProductID>370003021</ProductID>
<Quantity>4.0</Quantity>
<QuantityDescription>Units</QuantityDescription>
<PriceUnit>1</PriceUnit>
<Tax>
<TaxDetail>
<Rate>7.7</Rate>
<Amount>37.88</Amount>
<BaseAmountExclusiveTax>492.0</BaseAmountExclusiveTax>
<BaseAmountInclusiveTax>529.88</BaseAmountInclusiveTax>
</TaxDetail>
<TotalTax>37.88</TotalTax>
</Tax>
<AmountInclusiveTax>529.88</AmountInclusiveTax>
<AmountExclusiveTax>492.0</AmountExclusiveTax>
<FixedReference>
<ReferencePosition>2</ReferencePosition>
<ReferenceType>OrderNumberBySupplier</ReferenceType>
<ReferenceValue>Order123</ReferenceValue>
</FixedReference>
<FixedReference>
<ReferencePosition>3</ReferencePosition>
<ReferenceType>OrderNumberByBuyer</ReferenceType>
<ReferenceValue>CustomerRef</ReferenceValue>
</FixedReference>
</LineItem>
<LineItem>
<LineItemType>NORMAL</LineItemType>
<LineItemID>2</LineItemID>
<ProductDescription>Product With a Very Long Name That Need To Be Truncated</ProductDescription>
<ProductID>370003022</ProductID>
<Quantity>1.0</Quantity>
<QuantityDescription>Units</QuantityDescription>
<PriceUnit>1</PriceUnit>
<Tax>
<TaxDetail>
<Rate>7.7</Rate>
<Amount>0.0</Amount>
<BaseAmountExclusiveTax>0.0</BaseAmountExclusiveTax>
<BaseAmountInclusiveTax>0.0</BaseAmountInclusiveTax>
</TaxDetail>
<TotalTax>0.0</TotalTax>
</Tax>
<AmountInclusiveTax>0.0</AmountInclusiveTax>
<AmountExclusiveTax>0.0</AmountExclusiveTax>
<FixedReference>
<ReferencePosition>4</ReferencePosition>
<ReferenceType>OrderNumberBySupplier</ReferenceType>
<ReferenceValue>Order123</ReferenceValue>
</FixedReference>
<FixedReference>
<ReferencePosition>5</ReferencePosition>
<ReferenceType>OrderNumberByBuyer</ReferenceType>
<ReferenceValue>CustomerRef</ReferenceValue>
</FixedReference>
</LineItem>
<LineItem>
<LineItemType>NORMAL</LineItemType>
<LineItemID>3</LineItemID>
<ProductDescription>Phone support</ProductDescription>
<Quantity>4.0</Quantity>
<QuantityDescription>PCE</QuantityDescription>
<PriceUnit>1</PriceUnit>
<AmountInclusiveTax>0.0</AmountInclusiveTax>
<AmountExclusiveTax>0.0</AmountExclusiveTax>
</LineItem>
</LineItems>
<Summary>
<Tax>
<TaxDetail>
<Rate>7.7</Rate>
<Amount>37.88</Amount>
<BaseAmountExclusiveTax>492.0</BaseAmountExclusiveTax>
<BaseAmountInclusiveTax>529.88</BaseAmountInclusiveTax>
</TaxDetail>
<TotalTax>37.88</TotalTax>
</Tax>
<Discount>
<Days>10</Days>
<Rate>2.0</Rate>
</Discount>
<TotalAmountExclusiveTax>492.0</TotalAmountExclusiveTax>
<TotalAmountInclusiveTax>529.88</TotalAmountInclusiveTax>
<!-- <TotalAmountPaid>200.00</TotalAmountPaid> -->
<TotalAmountDue>529.88</TotalAmountDue>
</Summary>
</Bill>
<Appendix>
</Appendix>
</Body>
</Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

import os
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 ...ebill_postfinance.tests.common import CommonCase


@freeze_time("2019-06-21 09:06:00")
class TestEbillPosfinanceFinancialDiscount(CommonCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.schema_file = os.path.join(
get_module_path("ebill_postfinance"), "messages", "ybInvoice_V2.0.4.xsd"
)
cls.payment_term = cls.env["account.payment.term"].create(
{
"name": "Skonto",
"days_discount": 10,
"percent_discount": 2.0,
"line_ids": [
(
0,
0,
{
"value": "balance",
"days": 60,
"option": "day_after_invoice_date",
},
)
],
}
)
cls.invoice.invoice_payment_term_id = cls.payment_term

def test_discount_is_in_payload_params(self):
message = self.invoice.create_postfinance_ebill()
params = message._get_payload_params_yb()
self.assertTrue(params.get("discounts"))

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_financial_discount/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_financial_discount/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 f764ce1

Please sign in to comment.