-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ff590f
commit 12a4beb
Showing
1 changed file
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# @author Emilie SOUTIRAS <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo.tests import TransactionCase | ||
from odoo.tests.common import Form | ||
|
||
from odoo.addons.intrastat_product.tests.common import IntrastatProductCommon | ||
|
||
|
@@ -57,3 +58,67 @@ def test_hs_code_ids_category(self): | |
).get_hs_code_recursively(), | ||
hs_code_7049, | ||
) | ||
|
||
|
||
class TestInvoiceReportHSCode(IntrastatProductCommon, TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.hs_code_84715 = cls.env.ref("product_harmonized_system.84715000") | ||
cls.hs_code_7050 = cls.env.ref("product_harmonized_system.84717050") | ||
cls.hs_code_7050.parent_id = cls.hs_code_84715 | ||
cls.hs_code_7050.country_id = cls.env.ref("base.fr") | ||
cls.product = cls.env["product.product"].create( | ||
{ | ||
"name": "Test product", | ||
"hs_code_id": cls.hs_code_84715.id, | ||
"origin_country_id": cls.env.ref("base.de").id, | ||
"weight": 1.25, | ||
} | ||
) | ||
cls.partner = cls.partner_obj.create( | ||
{ | ||
"name": "Test partner", | ||
"country_id": cls.env.ref("base.fr").id, | ||
"invoice_intrastat_detail": True, | ||
} | ||
) | ||
cls.env["account.journal"].create( | ||
{"name": "Test sale journal", "type": "sale", "code": "TEST-sale"} | ||
) | ||
cls.report_obj = cls.env["ir.actions.report"] | ||
cls.sale_order = cls._create_sale_order(cls) | ||
cls.sale_order.action_confirm() | ||
cls.sale_order.order_line.qty_delivered = 1 | ||
cls.invoice = cls.sale_order._create_invoices() | ||
|
||
def _create_sale_order(self): | ||
order_form = Form(self.env["sale.order"]) | ||
order_form.partner_id = self.partner | ||
with order_form.order_line.new() as line_form: | ||
line_form.product_id = self.product | ||
with order_form.order_line.new() as line_form: | ||
line_form.product_id = self.product | ||
return order_form.save() | ||
|
||
def _test_invoice_report(self, weight): | ||
"""We need to check weight because if intrastat_line_ids already exist | ||
the weight will be different because weight field in model is integer.""" | ||
res = self.report_obj._render( | ||
"account.report_invoice_with_payments", self.invoice.ids | ||
) | ||
self.assertRegex(str(res[0]), self.hs_code_7050.hs_code) | ||
self.assertRegex(str(res[0]), self.product.origin_country_id.name) | ||
res = list(self.invoice._get_intrastat_lines_info()) | ||
self.assertEqual(len(res), 1) | ||
self.assertEqual(res[0]["product_id"], self.product) | ||
self.assertNotEqual(res[0]["hs_code_id"], self.product.hs_code_id) | ||
self.assertEqual(res[0]["hs_code_id"], self.hs_code_7050) | ||
self.assertEqual(res[0]["origin_country_id"], self.product.origin_country_id) | ||
self.assertEqual(res[0]["weight"], weight) | ||
|
||
def test_invoice_report_hs_codes(self): | ||
self.assertTrue(self.sale_order) | ||
self.assertTrue(self.invoice) | ||
self.invoice.compute_intrastat_lines() | ||
self._test_invoice_report(2) |