[FIX+IMP] intrastat_*: Several things:

* Add readonly on some fields when state of declaration is done
* Division by zero in computation of accessory costs
* Add FR translation
* Fix strings
* Minor code updates
This commit is contained in:
Alexis de Lattre
2018-12-10 15:07:40 +01:00
committed by João Marques
parent e5df4fb98b
commit e6e95c04d2
3 changed files with 1217 additions and 47 deletions

1182
intrastat_product/i18n/fr.po Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -79,15 +79,15 @@ class IntrastatProductDeclaration(models.Model):
return 'replace' return 'replace'
company_id = fields.Many2one( company_id = fields.Many2one(
'res.company', string='Company', readonly=True, 'res.company', string='Company', readonly=True, required=True,
default=lambda self: self.env['res.company']._company_default_get()) default=lambda self: self.env['res.company']._company_default_get())
company_country_code = fields.Char( company_country_code = fields.Char(
compute='_compute_company_country_code', compute='_compute_company_country_code',
string='Company Country Code', readonly=True, store=True, string='Company Country Code', readonly=True, store=True,
help="Used in views and methods of localization modules.") help="Used in views and methods of localization modules.")
year = fields.Integer( year = fields.Integer(
string='Year', required=True, string='Year', required=True, default=_get_year,
default=_get_year) states={'done': [('readonly', True)]})
month = fields.Selection([ month = fields.Selection([
(1, '01'), (1, '01'),
(2, '02'), (2, '02'),
@@ -101,8 +101,8 @@ class IntrastatProductDeclaration(models.Model):
(10, '10'), (10, '10'),
(11, '11'), (11, '11'),
(12, '12') (12, '12')
], string='Month', required=True, ], string='Month', required=True, default=_get_month,
default=_get_month) states={'done': [('readonly', True)]})
year_month = fields.Char( year_month = fields.Char(
compute='_compute_year_month', string='Period', readonly=True, compute='_compute_year_month', string='Period', readonly=True,
track_visibility='onchange', store=True, track_visibility='onchange', store=True,
@@ -136,8 +136,7 @@ class IntrastatProductDeclaration(models.Model):
compute='_compute_numbers', string='Total Fiscal Amount', store=True, compute='_compute_numbers', string='Total Fiscal Amount', store=True,
help="Total fiscal amount in company currency of the declaration.") help="Total fiscal amount in company currency of the declaration.")
currency_id = fields.Many2one( currency_id = fields.Many2one(
'res.currency', related='company_id.currency_id', readonly=True, related='company_id.currency_id', readonly=True, string='Company Currency')
string='Currency')
state = fields.Selection([ state = fields.Selection([
('draft', 'Draft'), ('draft', 'Draft'),
('done', 'Done'), ('done', 'Done'),
@@ -149,13 +148,12 @@ class IntrastatProductDeclaration(models.Model):
string='Notes', string='Notes',
help="You can add some comments here if you want.") help="You can add some comments here if you want.")
reporting_level = fields.Selection( reporting_level = fields.Selection(
'_get_reporting_level', '_get_reporting_level', string='Reporting Level',
string='Reporting Level') states={'done': [('readonly', True)]})
valid = fields.Boolean( valid = fields.Boolean(
compute='_check_validity', compute='_check_validity',
string='Valid') string='Valid')
@api.model
@api.constrains('year') @api.constrains('year')
def _check_year(self): def _check_year(self):
for this in self: for this in self:
@@ -178,7 +176,7 @@ class IntrastatProductDeclaration(models.Model):
if this.company_id: if this.company_id:
if not this.company_id.country_id: if not this.company_id.country_id:
raise ValidationError( raise ValidationError(
_("You must set company's country !")) _("You must set the country of the company!"))
this.company_country_code = \ this.company_country_code = \
this.company_id.country_id.code.lower() this.company_id.country_id.code.lower()
@@ -292,7 +290,7 @@ class IntrastatProductDeclaration(models.Model):
elif source_uom.category_id == pce_uom_categ: elif source_uom.category_id == pce_uom_categ:
if not product.weight: # re-create weight_net ? if not product.weight: # re-create weight_net ?
note = "\n" + _( note = "\n" + _(
"Missing net weight on product %s." "Missing weight on product %s."
) % product.name_get()[0][1] ) % product.name_get()[0][1]
note += "\n" + _( note += "\n" + _(
"Please correct the product record and regenerate " "Please correct the product record and regenerate "
@@ -418,13 +416,18 @@ class IntrastatProductDeclaration(models.Model):
total_inv_accessory_costs_cc * total_inv_accessory_costs_cc *
ac_line_vals['amount_company_currency'] / ac_line_vals['amount_company_currency'] /
total_inv_product_cc) total_inv_product_cc)
else: elif total_inv_weight:
# pro-rata of the weight # pro-rata of the weight
for ac_line_vals in lines_current_invoice: for ac_line_vals in lines_current_invoice:
ac_line_vals['amount_accessory_cost_company_currency'] = ( ac_line_vals['amount_accessory_cost_company_currency'] = (
total_inv_accessory_costs_cc * total_inv_accessory_costs_cc *
ac_line_vals['weight'] / ac_line_vals['weight'] /
total_inv_weight) total_inv_weight)
else:
for ac_line_vals in lines_current_invoice:
ac_line_vals['amount_accessory_cost_company_currency'] = (
total_inv_accessory_costs_cc /
len(lines_current_invoice))
def _prepare_invoice_domain(self): def _prepare_invoice_domain(self):
""" """
@@ -763,34 +766,27 @@ class IntrastatProductDeclaration(models.Model):
class IntrastatProductComputationLine(models.Model): class IntrastatProductComputationLine(models.Model):
_name = 'intrastat.product.computation.line' _name = 'intrastat.product.computation.line'
_description = "Intrastat Product Computataion Lines" _description = "Intrastat Product Computation Lines"
parent_id = fields.Many2one( parent_id = fields.Many2one(
'intrastat.product.declaration', 'intrastat.product.declaration',
string='Intrastat Product Declaration', string='Intrastat Product Declaration',
ondelete='cascade', readonly=True) ondelete='cascade', readonly=True)
company_id = fields.Many2one( company_id = fields.Many2one(
'res.company', related='parent_id.company_id', related='parent_id.company_id', readonly=True)
string="Company", readonly=True)
company_currency_id = fields.Many2one( company_currency_id = fields.Many2one(
'res.currency', related='company_id.currency_id', related='company_id.currency_id', readonly=True)
string="Company currency", readonly=True)
type = fields.Selection( type = fields.Selection(
related='parent_id.type', related='parent_id.type', readonly=True)
string='Type',
readonly=True)
reporting_level = fields.Selection( reporting_level = fields.Selection(
related='parent_id.reporting_level', related='parent_id.reporting_level', readonly=True)
string='Reporting Level',
readonly=True)
valid = fields.Boolean( valid = fields.Boolean(
compute='_check_validity', compute='_check_validity',
string='Valid') string='Valid')
invoice_line_id = fields.Many2one( invoice_line_id = fields.Many2one(
'account.invoice.line', string='Invoice Line', readonly=True) 'account.invoice.line', string='Invoice Line', readonly=True)
invoice_id = fields.Many2one( invoice_id = fields.Many2one(
'account.invoice', related='invoice_line_id.invoice_id', related='invoice_line_id.invoice_id', string='Invoice', readonly=True)
string='Invoice', readonly=True)
declaration_line_id = fields.Many2one( declaration_line_id = fields.Many2one(
'intrastat.product.declaration.line', 'intrastat.product.declaration.line',
string='Declaration Line', readonly=True) string='Declaration Line', readonly=True)
@@ -799,12 +795,11 @@ class IntrastatProductComputationLine(models.Model):
help="Country of Origin/Destination", help="Country of Origin/Destination",
domain=[('intrastat', '=', True)]) domain=[('intrastat', '=', True)])
product_id = fields.Many2one( product_id = fields.Many2one(
'product.product', related='invoice_line_id.product_id', related='invoice_line_id.product_id', readonly=True)
string='Product', readonly=True)
hs_code_id = fields.Many2one( hs_code_id = fields.Many2one(
'hs.code', string='Intrastat Code') 'hs.code', string='Intrastat Code')
intrastat_unit_id = fields.Many2one( intrastat_unit_id = fields.Many2one(
'intrastat.unit', related='hs_code_id.intrastat_unit_id', related='hs_code_id.intrastat_unit_id',
string='Suppl. Unit', readonly=True, string='Suppl. Unit', readonly=True,
help="Intrastat Supplementary Unit") help="Intrastat Supplementary Unit")
weight = fields.Float( weight = fields.Float(
@@ -871,19 +866,12 @@ class IntrastatProductDeclarationLine(models.Model):
string='Intrastat Product Declaration', string='Intrastat Product Declaration',
ondelete='cascade', readonly=True) ondelete='cascade', readonly=True)
company_id = fields.Many2one( company_id = fields.Many2one(
'res.company', related='parent_id.company_id', related='parent_id.company_id', readonly=True)
string="Company", readonly=True)
company_currency_id = fields.Many2one( company_currency_id = fields.Many2one(
'res.currency', related='company_id.currency_id', related='company_id.currency_id', readonly=True)
string="Company currency", readonly=True) type = fields.Selection(related='parent_id.type', readonly=True)
type = fields.Selection(
related='parent_id.type',
string='Type',
readonly=True)
reporting_level = fields.Selection( reporting_level = fields.Selection(
related='parent_id.reporting_level', related='parent_id.reporting_level', readonly=True)
string='Reporting Level',
readonly=True)
computation_line_ids = fields.One2many( computation_line_ids = fields.One2many(
'intrastat.product.computation.line', 'declaration_line_id', 'intrastat.product.computation.line', 'declaration_line_id',
string='Computation Lines', readonly=True) string='Computation Lines', readonly=True)

View File

@@ -79,7 +79,7 @@
<field name="revision"/> <field name="revision"/>
<field name="type"/> <field name="type"/>
<field name="num_decl_lines"/> <field name="num_decl_lines"/>
<field name="total_amount" sum="Total amount"/> <field name="total_amount" sum="1"/>
<field name="currency_id"/> <field name="currency_id"/>
<field name="state"/> <field name="state"/>
</tree> </tree>
@@ -168,10 +168,10 @@
<field name="product_id"/> <field name="product_id"/>
<field name="hs_code_id"/> <field name="hs_code_id"/>
<field name="src_dest_country_id" domain="[('intrastat', '=', True)]"/> <field name="src_dest_country_id" domain="[('intrastat', '=', True)]"/>
<field name="amount_company_currency"/> <field name="amount_company_currency" sum="1"/>
<field name="amount_accessory_cost_company_currency"/> <field name="amount_accessory_cost_company_currency" sum="1"/>
<field name="transaction_id"/> <field name="transaction_id"/>
<field name="weight"/> <field name="weight" sum="1"/>
<field name="suppl_unit_qty" <field name="suppl_unit_qty"
attrs="{'invisible': [('intrastat_unit_id', '=', False)], 'required': [('intrastat_unit_id', '!=', False)]}"/> attrs="{'invisible': [('intrastat_unit_id', '=', False)], 'required': [('intrastat_unit_id', '!=', False)]}"/>
<field name="intrastat_unit_id"/> <field name="intrastat_unit_id"/>
@@ -230,9 +230,9 @@
invisible="not context.get('intrastat_product_declaration_line_main_view')"/> invisible="not context.get('intrastat_product_declaration_line_main_view')"/>
<field name="hs_code_id"/> <field name="hs_code_id"/>
<field name="src_dest_country_id" domain="[('intrastat', '=', True)]"/> <field name="src_dest_country_id" domain="[('intrastat', '=', True)]"/>
<field name="amount_company_currency"/> <field name="amount_company_currency" sum="1"/>
<field name="transaction_id"/> <field name="transaction_id"/>
<field name="weight"/> <field name="weight" sum="1"/>
<field name="suppl_unit_qty"/> <field name="suppl_unit_qty"/>
<field name="intrastat_unit_id"/> <field name="intrastat_unit_id"/>
<field name="reporting_level" invisible="1"/> <field name="reporting_level" invisible="1"/>