[14.0][IMP] intrastat_product: Add test for purchase lines

This commit is contained in:
Denis Roussel
2021-10-24 13:45:19 +02:00
parent 75c6978d5d
commit cc243da726
3 changed files with 133 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
from . import common
from . import common_purchase
from . import common_sale
from . import test_intrastat_product
from . import test_company
from . import test_purchase_order
from . import test_sale_order

View File

@@ -0,0 +1,78 @@
# Copyright 2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import Form
from .common import IntrastatProductCommon
class IntrastatPurchaseCommon(IntrastatProductCommon):
"""
We define common flow:
- Supplier in Germany
"""
def _check_line_values(self, final=False, declaration=None, purchase=None):
"""
This method allows to test computation lines and declaration
lines values from original sale order line
"""
if declaration is None:
declaration = self.declaration
if purchase is None:
purchase = self.purchase
for line in purchase.order_line:
expected_vals = {
"declaration_type": "arrivals",
"suppl_unit_qty": line.qty_received,
"hs_code_id": line.product_id.hs_code_id,
"product_origin_country_id": line.product_id.origin_country_id,
"amount_company_currency": line.price_subtotal,
"src_dest_country_id": line.partner_id.country_id,
}
comp_line = declaration.computation_line_ids.filtered(
lambda cline: cline.product_id == line.product_id
)
self.assertTrue(
all(comp_line[key] == val for key, val in expected_vals.items())
)
if final:
decl_line = declaration.declaration_line_ids.filtered(
lambda dline: comp_line in dline.computation_line_ids
)
self.assertTrue(
all(decl_line[key] == val for key, val in expected_vals.items())
)
@classmethod
def _init_supplier(cls, vals=None):
values = {
"name": "DE Supplier",
"country_id": cls.env.ref("base.de").id,
"property_account_position_id": cls.position.id,
}
if vals is not None:
values.update(vals)
cls.supplier = cls.partner_obj.create(values)
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.purchase_obj = cls.env["purchase.order"]
cls.move_obj = cls.env["account.move"]
cls._init_supplier()
@classmethod
def _create_purchase_order(cls, vals=None):
vals = {
"partner_id": cls.supplier.id,
}
purchase_new = cls.purchase_obj.new(vals)
purchase_new.onchange_partner_id()
purchase_vals = purchase_new._convert_to_write(purchase_new._cache)
cls.purchase = cls.purchase_obj.create(purchase_vals)
with Form(cls.purchase) as purchase_form:
with purchase_form.order_line.new() as line:
line.product_id = cls.product_c3po.product_variant_ids[0]
line.product_qty = 3.0
# Price should not be void - if no purchase pricelist
line.price_unit = 150.0

View File

@@ -0,0 +1,53 @@
# Copyright 2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from freezegun import freeze_time
from odoo import fields
from odoo.tests.common import SavepointCase
from .common_purchase import IntrastatPurchaseCommon
class TestIntrastatProductPurchase(IntrastatPurchaseCommon):
"""Tests for this module"""
def test_purchase_to_invoice_default(self):
date_order = "2021-09-01"
declaration_date = "2021-10-01"
with freeze_time(date_order):
self._create_purchase_order()
self.purchase.button_confirm()
self.purchase.picking_ids.action_assign()
for line in self.purchase.picking_ids.move_line_ids:
line.qty_done = line.product_uom_qty
self.purchase.picking_ids._action_done()
self.assertEqual("done", self.purchase.picking_ids.state)
with freeze_time(date_order):
action = self.purchase.action_create_invoice()
invoice_id = action["res_id"]
invoice = self.move_obj.browse(invoice_id)
invoice.invoice_date = fields.Date.from_string(date_order)
invoice.action_post()
# Check if transport mode has been transmitted to invoice
# It should be None as not defined on sale order
self.assertFalse(
invoice.intrastat_transport_id,
)
vals = {
"declaration_type": "arrivals",
}
with freeze_time(declaration_date):
self._create_declaration(vals)
self.declaration.action_gather()
self._check_line_values()
self.declaration.generate_declaration()
self._check_line_values(final=True)
class TestIntrastatProductPurchaseCase(TestIntrastatProductPurchase, SavepointCase):
""" Test Intrastat Purchase """