[13.0]fix stack trace when entering invoice line without product

This commit is contained in:
Luc De Meyer
2020-08-01 15:34:12 +02:00
committed by João Marques
parent 6aba251aee
commit 00ed38be3f
4 changed files with 32 additions and 5 deletions

View File

@@ -7,11 +7,11 @@
{
"name": "Intrastat Product",
"version": "13.0.1.0.3",
"version": "13.0.1.1.0",
"category": "Intrastat",
"license": "AGPL-3",
"summary": "Base module for Intrastat Product",
"author": "brain-tec AG, Akretion, Noviat, " "Odoo Community Association (OCA)",
"author": "brain-tec AG, Akretion, Noviat, Odoo Community Association (OCA)",
"depends": [
"intrastat_base",
"product_harmonized_system",

View File

@@ -67,9 +67,16 @@ class AccountMoveLine(models.Model):
hs_code_id = fields.Many2one(
comodel_name="hs.code", string="Intrastat Code", ondelete="restrict"
)
weight = fields.Integer(string="Weight", help="Net weight in Kg")
product_origin_country_id = fields.Many2one(
comodel_name="res.country",
string="Country of Origin",
help="Country of origin of the product i.e. product " "'made in ____'.",
)
@api.onchange("product_id")
def intrastat_product_id_change(self):
if self.product_id:
hs_code = self.product_id.get_hs_code_recursively()
self.hs_code_id = hs_code and hs_code.id or False
self.hs_code_id = self.product_id.get_hs_code_recursively()
self.product_origin_country_id = self.product_id.origin_country_id
self.weight = self.product_id.weight

View File

@@ -272,6 +272,20 @@ class IntrastatProductDeclaration(models.Model):
pce_uom = self._get_uom_refs("pce_uom")
weight = suppl_unit_qty = 0.0
if not product:
weight = inv_line.weight
if not weight:
note = "\n" + _(
"Missing weight on invoice %s, line with intrastat code %s."
) % (inv_line.move_id.name, inv_line.hs_code_id.local_code)
note += "\n" + _(
"Please correct the product record and regenerate "
"the lines or adjust the impacted lines manually"
)
self._note += note
return weight, suppl_unit_qty
return weight, suppl_unit_qty
if not source_uom:
note = "\n" + _(
"Missing unit of measure on the line with %d "
@@ -435,7 +449,9 @@ class IntrastatProductDeclaration(models.Model):
return incoterm
def _get_product_origin_country(self, inv_line):
return inv_line.product_id.origin_country_id
return (
inv_line.product_origin_country_id or inv_line.product_id.origin_country_id
)
def _update_computation_line_vals(self, inv_line, line_vals):
""" placeholder for localization modules """

View File

@@ -24,12 +24,16 @@
position="after"
>
<field name="hs_code_id" optional="hide" />
<field name="weight" optional="hide" />
<field name="product_origin_country_id" optional="hide" />
</xpath>
<xpath
expr="//field[@name='line_ids']//field[@name='account_id']"
position="after"
>
<field name="hs_code_id" optional="hide" />
<field name="weight" optional="hide" />
<field name="product_origin_country_id" optional="hide" />
</xpath>
</field>
</record>