mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
[FIX+IMP] intrastat_product: reporting level + move methods to IntrastatProductDeclaration class
This commit is contained in:
committed by
Luc De Meyer
parent
49f272443c
commit
4dd21d0f7c
@@ -668,6 +668,51 @@ class IntrastatProductDeclaration(models.Model):
|
||||
hashcode = '-'.join([str(f) for f in hc_fields.values()])
|
||||
return hashcode
|
||||
|
||||
@api.model
|
||||
def _prepare_grouped_fields(self, computation_line, fields_to_sum):
|
||||
vals = {
|
||||
'src_dest_country_id': computation_line.src_dest_country_id.id,
|
||||
'intrastat_unit_id': computation_line.intrastat_unit_id.id,
|
||||
'hs_code_id': computation_line.hs_code_id.id,
|
||||
'transaction_id': computation_line.transaction_id.id,
|
||||
'transport_id': computation_line.transport_id.id,
|
||||
'region_id': computation_line.region_id.id,
|
||||
'parent_id': computation_line.parent_id.id,
|
||||
'product_origin_country_id':
|
||||
computation_line.product_origin_country_id.id,
|
||||
'amount_company_currency': 0.0,
|
||||
}
|
||||
for field in fields_to_sum:
|
||||
vals[field] = 0.0
|
||||
return vals
|
||||
|
||||
def _fields_to_sum(self):
|
||||
fields_to_sum = [
|
||||
'weight',
|
||||
'suppl_unit_qty',
|
||||
]
|
||||
return fields_to_sum
|
||||
|
||||
@api.model
|
||||
def _prepare_declaration_line(self, computation_lines):
|
||||
fields_to_sum = self._fields_to_sum()
|
||||
vals = self._prepare_grouped_fields(
|
||||
computation_lines[0], fields_to_sum)
|
||||
for computation_line in computation_lines:
|
||||
for field in fields_to_sum:
|
||||
vals[field] += computation_line[field]
|
||||
vals['amount_company_currency'] += (
|
||||
computation_line['amount_company_currency'] +
|
||||
computation_line['amount_accessory_cost_company_currency'])
|
||||
# round, otherwise odoo with truncate (6.7 -> 6... instead of 7 !)
|
||||
for field in fields_to_sum:
|
||||
vals[field] = int(round(vals[field]))
|
||||
if not vals['weight']:
|
||||
vals['weight'] = 1
|
||||
vals['amount_company_currency'] = int(round(
|
||||
vals['amount_company_currency']))
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def generate_declaration(self):
|
||||
""" generate declaration lines """
|
||||
@@ -686,7 +731,7 @@ class IntrastatProductDeclaration(models.Model):
|
||||
dl_group[hashcode] = [cl]
|
||||
ipdl = self.declaration_line_ids
|
||||
for cl_lines in list(dl_group.values()):
|
||||
vals = ipdl._prepare_declaration_line(cl_lines)
|
||||
vals = self._prepare_declaration_line(cl_lines)
|
||||
declaration_line = ipdl.create(vals)
|
||||
for cl in cl_lines:
|
||||
cl.write({'declaration_line_id': declaration_line.id})
|
||||
@@ -881,6 +926,11 @@ class IntrastatProductDeclarationLine(models.Model):
|
||||
|
||||
@api.model
|
||||
def _prepare_grouped_fields(self, computation_line, fields_to_sum):
|
||||
"""
|
||||
This method is DEPRECATED.
|
||||
You should use the _prepare_grouped_fields method on the
|
||||
IntrastatProductDeclaration class.
|
||||
"""
|
||||
vals = {
|
||||
'src_dest_country_id': computation_line.src_dest_country_id.id,
|
||||
'intrastat_unit_id': computation_line.intrastat_unit_id.id,
|
||||
@@ -898,6 +948,11 @@ class IntrastatProductDeclarationLine(models.Model):
|
||||
return vals
|
||||
|
||||
def _fields_to_sum(self):
|
||||
"""
|
||||
This method is DEPRECATED.
|
||||
You should use the _fields_to_sum method on the
|
||||
IntrastatProductDeclaration class.
|
||||
"""
|
||||
fields_to_sum = [
|
||||
'weight',
|
||||
'suppl_unit_qty',
|
||||
@@ -906,6 +961,11 @@ class IntrastatProductDeclarationLine(models.Model):
|
||||
|
||||
@api.model
|
||||
def _prepare_declaration_line(self, computation_lines):
|
||||
"""
|
||||
This method is DEPRECATED.
|
||||
You should use the _fields_to_sum method on the
|
||||
IntrastatProductDeclaration class.
|
||||
"""
|
||||
fields_to_sum = self._fields_to_sum()
|
||||
vals = self._prepare_grouped_fields(
|
||||
computation_lines[0], fields_to_sum)
|
||||
|
||||
Reference in New Issue
Block a user