-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #677 from camptocamp/ebillpostfinance-financialdis…
…count [14.0][ADD] ebill_postfinance_financial_discount
- Loading branch information
Showing
14 changed files
with
326 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import ebill_postfinance_invoice_message |
20 changes: 20 additions & 0 deletions
20
ebill_postfinance_financial_discount/models/ebill_postfinance_invoice_message.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Thierry Ducrest <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
186
ebill_postfinance_financial_discount/tests/examples/invoice_qr_yb.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 & 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> |
82 changes: 82 additions & 0 deletions
82
ebill_postfinance_financial_discount/tests/test_postfinance_financial_discount.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
1 change: 1 addition & 0 deletions
1
setup/ebill_postfinance_financial_discount/odoo/addons/ebill_postfinance_financial_discount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../ebill_postfinance_financial_discount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |