[MIG] Migrate all modules from v11 to v12

This commit is contained in:
Alexis de Lattre
2019-05-28 19:09:32 +02:00
committed by João Marques
parent 24f4161e5e
commit fb4032fac0
20 changed files with 180 additions and 170 deletions

View File

@@ -7,7 +7,7 @@
{ {
'name': 'Intrastat Product', 'name': 'Intrastat Product',
'version': '11.0.1.2.0', 'version': '12.0.1.0.0',
'category': 'Intrastat', 'category': 'Intrastat',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': 'Base module for Intrastat Product', 'summary': 'Base module for Intrastat Product',
@@ -17,10 +17,10 @@
'intrastat_base', 'intrastat_base',
'product_harmonized_system', 'product_harmonized_system',
'sale_stock', 'sale_stock',
'purchase', 'purchase_stock',
'report_xlsx_helper', 'report_xlsx_helper',
], ],
'excludes': ['report_intrastat'], 'excludes': ['account_intrastat'],
'data': [ 'data': [
'views/hs_code.xml', 'views/hs_code.xml',
'views/intrastat_region.xml', 'views/intrastat_region.xml',
@@ -38,5 +38,5 @@
'data/intrastat_unit.xml', 'data/intrastat_unit.xml',
], ],
'demo': ['demo/intrastat_demo.xml'], 'demo': ['demo/intrastat_demo.xml'],
'installable': False, 'installable': True,
} }

View File

@@ -18,7 +18,7 @@
<record id="intrastat_unit_g" model="intrastat.unit"> <record id="intrastat_unit_g" model="intrastat.unit">
<field name="name">g</field> <field name="name">g</field>
<field name="description">Gram</field> <field name="description">Gram</field>
<field name="uom_id" ref="product.product_uom_gram"/> <field name="uom_id" ref="uom.product_uom_gram"/>
</record> </record>
<record id="intrastat_unit_gi_FS" model="intrastat.unit"> <record id="intrastat_unit_gi_FS" model="intrastat.unit">
<field name="name">gi F/S</field> <field name="name">gi F/S</field>
@@ -71,7 +71,7 @@
<record id="intrastat_unit_l" model="intrastat.unit"> <record id="intrastat_unit_l" model="intrastat.unit">
<field name="name">l</field> <field name="name">l</field>
<field name="description">Litre</field> <field name="description">Litre</field>
<field name="uom_id" ref="product.product_uom_litre"/> <field name="uom_id" ref="uom.product_uom_litre"/>
</record> </record>
<record id="intrastat_unit_1000l" model="intrastat.unit"> <record id="intrastat_unit_1000l" model="intrastat.unit">
<field name="name">1000 l</field> <field name="name">1000 l</field>
@@ -84,7 +84,7 @@
<record id="intrastat_unit_m" model="intrastat.unit"> <record id="intrastat_unit_m" model="intrastat.unit">
<field name="name">m</field> <field name="name">m</field>
<field name="description">Metre</field> <field name="description">Metre</field>
<field name="uom_id" ref="product.product_uom_meter"/> <field name="uom_id" ref="uom.product_uom_meter"/>
</record> </record>
<record id="intrastat_unit_m2" model="intrastat.unit"> <record id="intrastat_unit_m2" model="intrastat.unit">
<field name="name">m2</field> <field name="name">m2</field>
@@ -105,7 +105,7 @@
<record id="intrastat_unit_pce" model="intrastat.unit"> <record id="intrastat_unit_pce" model="intrastat.unit">
<field name="name">items</field> <field name="name">items</field>
<field name="description">Number of items</field> <field name="description">Number of items</field>
<field name="uom_id" ref="product.product_uom_unit"/> <field name="uom_id" ref="uom.product_uom_unit"/>
</record> </record>
<record id="intrastat_unit_100pce" model="intrastat.unit"> <record id="intrastat_unit_100pce" model="intrastat.unit">
<field name="name">100 items</field> <field name="name">100 items</field>

View File

@@ -18,7 +18,7 @@
<record id="base.main_company" model="res.company"> <record id="base.main_company" model="res.company">
<field name="intrastat_arrivals">extended</field> <field name="intrastat_arrivals">extended</field>
<field name="intrastat_dispatches">extended</field> <field name="intrastat_dispatches">extended</field>
<field name="intrastat_incoterm_id" ref="stock.incoterm_DDU"/> <field name="intrastat_incoterm_id" ref="account.incoterm_DDU"/>
<field name="intrastat_transport_id" ref="intrastat_transport_3"/> <field name="intrastat_transport_id" ref="intrastat_transport_3"/>
</record> </record>

View File

@@ -1,4 +1,4 @@
# Copyright 2011-2017 Akretion (http://www.akretion.com) # Copyright 2011-2017 Akretion France (http://www.akretion.com)
# Copyright 2009-2018 Noviat (http://www.noviat.com) # Copyright 2009-2018 Noviat (http://www.noviat.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com> # @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com> # @author Luc de Meyer <info@noviat.com>
@@ -9,8 +9,6 @@ from odoo import api, fields, models
class AccountInvoice(models.Model): class AccountInvoice(models.Model):
_inherit = 'account.invoice' _inherit = 'account.invoice'
# in v10, the sale_stock module defines an incoterms_id
# Odoo v8 name: incoterm_id
intrastat_transaction_id = fields.Many2one( intrastat_transaction_id = fields.Many2one(
comodel_name='intrastat.transaction', comodel_name='intrastat.transaction',
string='Intrastat Transaction Type', string='Intrastat Transaction Type',
@@ -29,7 +27,7 @@ class AccountInvoice(models.Model):
"arrivals.") "arrivals.")
intrastat_country = fields.Boolean( intrastat_country = fields.Boolean(
compute='_compute_intrastat_country', string='Intrastat Country', compute='_compute_intrastat_country', string='Intrastat Country',
store=True, readonly=True, compute_sudo=True) store=True, compute_sudo=True)
src_dest_region_id = fields.Many2one( src_dest_region_id = fields.Many2one(
comodel_name='intrastat.region', comodel_name='intrastat.region',
string='Origin/Destination Region', string='Origin/Destination Region',
@@ -39,9 +37,8 @@ class AccountInvoice(models.Model):
ondelete='restrict') ondelete='restrict')
intrastat = fields.Char( intrastat = fields.Char(
string='Intrastat Declaration', string='Intrastat Declaration',
related='company_id.intrastat', readonly=True, compute_sudo=True) related='company_id.intrastat')
@api.multi
@api.depends('partner_shipping_id.country_id', 'partner_id.country_id') @api.depends('partner_shipping_id.country_id', 'partner_id.country_id')
def _compute_intrastat_country(self): def _compute_intrastat_country(self):
for inv in self: for inv in self:
@@ -55,7 +52,7 @@ class AccountInvoice(models.Model):
@api.model @api.model
def _default_src_dest_region_id(self): def _default_src_dest_region_id(self):
rco = self.env['res.company'] rco = self.env['res.company']
company = rco._company_default_get('account.invoice') company = rco._company_default_get()
return company.intrastat_region_id return company.intrastat_region_id

View File

@@ -1,4 +1,4 @@
# Copyright 2011-2017 Akretion (http://www.akretion.com) # Copyright 2011-2017 Akretion France (http://www.akretion.com)
# Copyright 2009-2018 Noviat (http://www.noviat.com) # Copyright 2009-2018 Noviat (http://www.noviat.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com> # @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com> # @author Luc de Meyer <info@noviat.com>
@@ -27,35 +27,24 @@ class IntrastatProductDeclaration(models.Model):
] ]
@api.model @api.model
def _default_year(self): def default_get(self, fields_list):
if datetime.now().month == 1: res = super(IntrastatProductDeclaration, self).default_get(fields_list)
year = datetime.now().year - 1 decl_date = fields.Date.context_today(self) - relativedelta(months=1)
else: res.update({
year = datetime.now().year 'year': str(decl_date.year),
return str(year) 'month': decl_date.month,
})
@api.model return res
def _default_month(self):
if datetime.now().month == 1:
return 12
else:
return datetime.now().month - 1
@api.model
def _default_action(self):
return 'replace'
company_id = fields.Many2one( company_id = fields.Many2one(
comodel_name='res.company', string='Company', readonly=True, comodel_name='res.company', string='Company', readonly=True,
default=lambda self: self.env['res.company']._company_default_get( default=lambda self: self.env['res.company']._company_default_get())
'intrastat.product.declaration'))
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.Char( year = fields.Char(
string='Year', required=True, string='Year', required=True,
default=lambda self: self._default_year(),
states={'done': [('readonly', True)]}) states={'done': [('readonly', True)]})
month = fields.Selection([ month = fields.Selection([
(1, '01'), (1, '01'),
@@ -71,7 +60,6 @@ class IntrastatProductDeclaration(models.Model):
(11, '11'), (11, '11'),
(12, '12') (12, '12')
], string='Month', required=True, ], string='Month', required=True,
default=lambda self: self._default_month(),
states={'done': [('readonly', True)]}) 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,
@@ -84,7 +72,7 @@ class IntrastatProductDeclaration(models.Model):
action = fields.Selection( action = fields.Selection(
selection='_get_action', selection='_get_action',
string='Action', required=True, string='Action', required=True,
default=lambda self: self._default_action(), default='replace',
states={'done': [('readonly', True)]}, states={'done': [('readonly', True)]},
track_visibility='onchange') track_visibility='onchange')
revision = fields.Integer( revision = fields.Integer(
@@ -107,8 +95,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, 'res.currency', related='company_id.currency_id', string='Currency')
string='Currency')
state = fields.Selection( state = fields.Selection(
selection=[('draft', 'Draft'), selection=[('draft', 'Draft'),
('done', 'Done')], ('done', 'Done')],
@@ -152,7 +139,6 @@ class IntrastatProductDeclaration(models.Model):
('append', 'Append'), ('append', 'Append'),
('nihil', 'Nihil')] ('nihil', 'Nihil')]
@api.multi
@api.depends('company_id') @api.depends('company_id')
def _compute_company_country_code(self): def _compute_company_country_code(self):
for this in self: for this in self:
@@ -163,7 +149,6 @@ class IntrastatProductDeclaration(models.Model):
this.company_country_code = \ this.company_country_code = \
this.company_id.country_id.code.lower() this.company_id.country_id.code.lower()
@api.multi
@api.depends('year', 'month') @api.depends('year', 'month')
def _compute_year_month(self): def _compute_year_month(self):
for this in self: for this in self:
@@ -171,7 +156,6 @@ class IntrastatProductDeclaration(models.Model):
this.year_month = '-'.join( this.year_month = '-'.join(
[this.year, format(this.month, '02')]) [this.year, format(this.month, '02')])
@api.multi
@api.depends('month') @api.depends('month')
def _compute_check_validity(self): def _compute_check_validity(self):
""" TO DO: logic based upon computation lines """ """ TO DO: logic based upon computation lines """
@@ -196,7 +180,6 @@ class IntrastatProductDeclaration(models.Model):
self.company_id.intrastat_dispatches == 'extended' \ self.company_id.intrastat_dispatches == 'extended' \
and 'extended' or 'standard' and 'extended' or 'standard'
@api.multi
def copy(self, default=None): def copy(self, default=None):
self.ensure_one() self.ensure_one()
default = default or {} default = default or {}
@@ -322,10 +305,9 @@ class IntrastatProductDeclaration(models.Model):
def _get_amount(self, inv_line): def _get_amount(self, inv_line):
invoice = inv_line.invoice_id invoice = inv_line.invoice_id
amount = invoice.currency_id.with_context( amount = invoice.currency_id._convert(
date=invoice.date_invoice).compute( inv_line.price_subtotal, self.company_id.currency_id,
inv_line.price_subtotal, self.company_id, invoice.date_invoice)
self.company_id.currency_id)
return amount return amount
def _get_region(self, inv_line): def _get_region(self, inv_line):
@@ -379,7 +361,10 @@ class IntrastatProductDeclaration(models.Model):
return transport return transport
def _get_incoterm(self, inv_line): def _get_incoterm(self, inv_line):
incoterm = inv_line.invoice_id.incoterms_id \ # WARNING for v12: there are 2 incoterm fields on account.invoice
# cf https://github.com/odoo/odoo/issues/31641
# the field to use is 'incoterm_id' defined in the 'account' module
incoterm = inv_line.invoice_id.incoterm_id \
or self.company_id.intrastat_incoterm_id or self.company_id.intrastat_incoterm_id
if not incoterm: if not incoterm:
msg = _( msg = _(
@@ -441,7 +426,7 @@ class IntrastatProductDeclaration(models.Model):
domain = [ domain = [
('date_invoice', '>=', start_date), ('date_invoice', '>=', start_date),
('date_invoice', '<=', end_date), ('date_invoice', '<=', end_date),
('state', 'in', ['open', 'paid']), ('state', 'in', ['open', 'in_payment', 'paid']),
('intrastat_country', '=', True), ('intrastat_country', '=', True),
('company_id', '=', self.company_id.id)] ('company_id', '=', self.company_id.id)]
return domain return domain
@@ -479,10 +464,11 @@ class IntrastatProductDeclaration(models.Model):
accessory_costs and accessory_costs and
inv_line.product_id and inv_line.product_id and
inv_line.product_id.is_accessory_cost): inv_line.product_id.is_accessory_cost):
acost = invoice.currency_id.with_context( acost = invoice.currency_id._convert(
date=invoice.date_invoice).compute( inv_line.price_subtotal,
inv_line.price_subtotal, self.company_id.currency_id,
self.company_id.currency_id) self.company_id,
invoice.date_invoice)
total_inv_accessory_costs_cc += acost total_inv_accessory_costs_cc += acost
continue continue
@@ -599,14 +585,13 @@ class IntrastatProductDeclaration(models.Model):
def _get_uom_refs(self, ref): def _get_uom_refs(self, ref):
uom_refs = { uom_refs = {
'weight_uom_categ': self.env.ref('product.product_uom_categ_kgm'), 'weight_uom_categ': self.env.ref('uom.product_uom_categ_kgm'),
'kg_uom': self.env.ref('product.product_uom_kgm'), 'kg_uom': self.env.ref('uom.product_uom_kgm'),
'pce_uom_categ': self.env.ref('product.product_uom_categ_unit'), 'pce_uom_categ': self.env.ref('uom.product_uom_categ_unit'),
'pce_uom': self.env.ref('product.product_uom_unit') 'pce_uom': self.env.ref('uom.product_uom_unit')
} }
return uom_refs[ref] return uom_refs[ref]
@api.multi
def action_gather(self): def action_gather(self):
self.ensure_one() self.ensure_one()
self.message_post(body=_("Generate Lines from Invoices")) self.message_post(body=_("Generate Lines from Invoices"))
@@ -716,7 +701,6 @@ class IntrastatProductDeclaration(models.Model):
vals['amount_company_currency'])) vals['amount_company_currency']))
return vals return vals
@api.multi
def generate_declaration(self): def generate_declaration(self):
""" generate declaration lines """ """ generate declaration lines """
self.ensure_one() self.ensure_one()
@@ -740,7 +724,6 @@ class IntrastatProductDeclaration(models.Model):
cl.write({'declaration_line_id': declaration_line.id}) cl.write({'declaration_line_id': declaration_line.id})
return True return True
@api.multi
def generate_xml(self): def generate_xml(self):
""" generate the INTRASTAT Declaration XML file """ """ generate the INTRASTAT Declaration XML file """
self.ensure_one() self.ensure_one()
@@ -756,7 +739,6 @@ class IntrastatProductDeclaration(models.Model):
raise UserError( raise UserError(
_("No XML File has been generated.")) _("No XML File has been generated."))
@api.multi
def create_xls(self): def create_xls(self):
if self.env.context.get('computation_lines'): if self.env.context.get('computation_lines'):
report_file = 'instrastat_transactions' report_file = 'instrastat_transactions'
@@ -802,11 +784,9 @@ class IntrastatProductDeclaration(models.Model):
""" """
return {} return {}
@api.multi
def done(self): def done(self):
self.write({'state': 'done'}) self.write({'state': 'done'})
@api.multi
def back2draft(self): def back2draft(self):
self.write({'state': 'draft'}) self.write({'state': 'draft'})
@@ -819,20 +799,11 @@ class IntrastatProductComputationLine(models.Model):
'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(related='parent_id.company_id')
'res.company', related='parent_id.company_id',
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', string="Company currency")
string="Company currency", readonly=True) type = fields.Selection(related='parent_id.type')
type = fields.Selection( reporting_level = fields.Selection(related='parent_id.reporting_level')
related='parent_id.type',
string='Type',
readonly=True)
reporting_level = fields.Selection(
related='parent_id.reporting_level',
string='Reporting Level',
readonly=True)
valid = fields.Boolean( valid = fields.Boolean(
compute='_compute_check_validity', compute='_compute_check_validity',
string='Valid') string='Valid')
@@ -840,7 +811,7 @@ class IntrastatProductComputationLine(models.Model):
'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', 'account.invoice', related='invoice_line_id.invoice_id',
string='Invoice', readonly=True) string='Invoice')
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)
@@ -849,14 +820,12 @@ 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', 'product.product', related='invoice_line_id.product_id')
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', 'intrastat.unit', related='hs_code_id.intrastat_unit_id',
string='Suppl. Unit', readonly=True, string='Suppl. Unit', help="Intrastat Supplementary Unit")
help="Intrastat Supplementary Unit")
weight = fields.Float( weight = fields.Float(
string='Weight', string='Weight',
digits=dp.get_precision('Stock Weight'), help="Net weight in Kg") digits=dp.get_precision('Stock Weight'), help="Net weight in Kg")
@@ -883,7 +852,7 @@ class IntrastatProductComputationLine(models.Model):
'intrastat.region', string='Intrastat Region') 'intrastat.region', string='Intrastat Region')
# extended declaration # extended declaration
incoterm_id = fields.Many2one( incoterm_id = fields.Many2one(
'stock.incoterms', string='Incoterm') 'account.incoterms', string='Incoterm')
transport_id = fields.Many2one( transport_id = fields.Many2one(
'intrastat.transport_mode', 'intrastat.transport_mode',
string='Transport Mode') string='Transport Mode')
@@ -891,13 +860,15 @@ class IntrastatProductComputationLine(models.Model):
'res.country', string='Country of Origin of the Product', 'res.country', string='Country of Origin of the Product',
help="Country of origin of the product i.e. product 'made in ____'") help="Country of origin of the product i.e. product 'made in ____'")
@api.multi
@api.depends('transport_id') @api.depends('transport_id')
def _compute_check_validity(self): def _compute_check_validity(self):
""" TO DO: logic based upon fields """ """ TO DO: logic based upon fields """
for this in self: for this in self:
this.valid = True this.valid = True
# TODO: product_id is a readonly related field 'invoice_line_id.product_id'
# so the onchange is non-sense. Either we convert product_id to a regular
# field or we keep it a related field and we remove this onchange
@api.onchange('product_id') @api.onchange('product_id')
def _onchange_product(self): def _onchange_product(self):
self.weight = 0.0 self.weight = 0.0
@@ -920,20 +891,11 @@ class IntrastatProductDeclarationLine(models.Model):
'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(related='parent_id.company_id')
'res.company', related='parent_id.company_id',
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', string="Company currency")
string="Company currency", readonly=True) type = fields.Selection(related='parent_id.type')
type = fields.Selection( reporting_level = fields.Selection(related='parent_id.reporting_level')
related='parent_id.type',
string='Type',
readonly=True)
reporting_level = fields.Selection(
related='parent_id.reporting_level',
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)
@@ -946,8 +908,7 @@ class IntrastatProductDeclarationLine(models.Model):
string='Intrastat Code') string='Intrastat Code')
intrastat_unit_id = fields.Many2one( intrastat_unit_id = fields.Many2one(
'intrastat.unit', related='hs_code_id.intrastat_unit_id', 'intrastat.unit', related='hs_code_id.intrastat_unit_id',
string='Suppl. Unit', readonly=True, string='Suppl. Unit', help="Intrastat Supplementary Unit")
help="Intrastat Supplementary Unit")
weight = fields.Integer( weight = fields.Integer(
string='Weight', help="Net weight in Kg") string='Weight', help="Net weight in Kg")
suppl_unit_qty = fields.Integer( suppl_unit_qty = fields.Integer(
@@ -965,7 +926,7 @@ class IntrastatProductDeclarationLine(models.Model):
'intrastat.region', string='Intrastat Region') 'intrastat.region', string='Intrastat Region')
# extended declaration # extended declaration
incoterm_id = fields.Many2one( incoterm_id = fields.Many2one(
'stock.incoterms', string='Incoterm') 'account.incoterms', string='Incoterm')
transport_id = fields.Many2one( transport_id = fields.Many2one(
'intrastat.transport_mode', 'intrastat.transport_mode',
string='Transport Mode') string='Transport Mode')

View File

@@ -20,5 +20,4 @@ class IntrastatRegion(models.Model):
description = fields.Char(string='Description') description = fields.Char(string='Description')
company_id = fields.Many2one( company_id = fields.Many2one(
comodel_name='res.company', string='Company', comodel_name='res.company', string='Company',
default=lambda self: self.env['res.company']._company_default_get( default=lambda self: self.env['res.company']._company_default_get())
'intrastat.region'))

View File

@@ -1,4 +1,4 @@
# Copyright 2011-2017 Akretion (http://www.akretion.com) # Copyright 2011-2017 Akretion France (http://www.akretion.com)
# Copyright 2009-2018 Noviat (http://www.noviat.com) # Copyright 2009-2018 Noviat (http://www.noviat.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com> # @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com> # @author Luc de Meyer <info@noviat.com>
@@ -10,7 +10,6 @@ class IntrastatTransaction(models.Model):
_name = 'intrastat.transaction' _name = 'intrastat.transaction'
_description = "Intrastat Transaction" _description = "Intrastat Transaction"
_order = 'code' _order = 'code'
_rec_name = 'display_name'
_sql_constraints = [( _sql_constraints = [(
'intrastat_transaction_code_unique', 'intrastat_transaction_code_unique',
'UNIQUE(code, company_id)', 'UNIQUE(code, company_id)',
@@ -18,21 +17,17 @@ class IntrastatTransaction(models.Model):
code = fields.Char(string='Code', required=True) code = fields.Char(string='Code', required=True)
description = fields.Text(string='Description') description = fields.Text(string='Description')
display_name = fields.Char(
compute='_compute_display_name_field', string="Display Name",
readonly=True, store=True)
company_id = fields.Many2one( company_id = fields.Many2one(
comodel_name='res.company', string='Company', comodel_name='res.company', string='Company',
default=lambda self: self.env['res.company']._company_default_get( default=lambda self: self.env['res.company']._company_default_get())
'intrastat.transaction'))
@api.multi
@api.depends('code', 'description') @api.depends('code', 'description')
def _compute_display_name_field(self): def name_get(self):
res = []
for this in self: for this in self:
display_name = this.code name = this.code
if this.description: if this.description:
display_name += ' ' + this.description name += ' ' + this.description
this.display_name = len(display_name) > 55 \ name = len(name) > 55 and name[:55] + '...' or name
and display_name[:55] + '...' \ res.append((this.id, this.name))
or display_name return res

View File

@@ -9,22 +9,20 @@ from odoo import api, fields, models
class IntrastatTransportMode(models.Model): class IntrastatTransportMode(models.Model):
_name = 'intrastat.transport_mode' _name = 'intrastat.transport_mode'
_description = "Intrastat Transport Mode" _description = "Intrastat Transport Mode"
_rec_name = 'display_name'
_order = 'code' _order = 'code'
_sql_constraints = [( _sql_constraints = [(
'intrastat_transport_code_unique', 'intrastat_transport_code_unique',
'UNIQUE(code)', 'UNIQUE(code)',
'Code must be unique.')] 'Code must be unique.')]
display_name = fields.Char(
string='Display Name', compute='_compute_display_name', store=True,
readonly=True)
code = fields.Char(string='Code', required=True) code = fields.Char(string='Code', required=True)
name = fields.Char(string='Name', required=True, translate=True) name = fields.Char(string='Name', required=True, translate=True)
description = fields.Char(string='Description', translate=True) description = fields.Char(string='Description', translate=True)
@api.multi
@api.depends('name', 'code') @api.depends('name', 'code')
def _compute_display_name(self): def name_get(self):
for this in self: res = []
this.display_name = '%s. %s' % (this.code, this.name) for mode in self:
name = '%s. %s' % (mode.code, mode.name)
res.append((mode.id, name))
return res

View File

@@ -13,7 +13,7 @@ class IntrastatUnit(models.Model):
name = fields.Char(string='Name', required=True) name = fields.Char(string='Name', required=True)
description = fields.Char(string='Description', required=True) description = fields.Char(string='Description', required=True)
uom_id = fields.Many2one( uom_id = fields.Many2one(
comodel_name='product.uom', string='Regular UoM', comodel_name='uom.uom', string='Regular UoM',
help="Select the regular Unit of Measure of Odoo that corresponds " help="Select the regular Unit of Measure of Odoo that corresponds "
"to this Intrastat Supplementary Unit.") "to this Intrastat Supplementary Unit.")
active = fields.Boolean(default=True) active = fields.Boolean(default=True)

View File

@@ -10,7 +10,7 @@ class ResCompany(models.Model):
_inherit = 'res.company' _inherit = 'res.company'
intrastat_incoterm_id = fields.Many2one( intrastat_incoterm_id = fields.Many2one(
comodel_name='stock.incoterms', comodel_name='account.incoterms',
string='Default Incoterm for Intrastat', string='Default Incoterm for Intrastat',
help="International Commercial Terms are a series of " help="International Commercial Terms are a series of "
"predefined commercial terms used in international " "predefined commercial terms used in international "
@@ -59,7 +59,6 @@ class ResCompany(models.Model):
('standard', 'Standard'), ('standard', 'Standard'),
('extended', 'Extended')] ('extended', 'Extended')]
@api.multi
@api.depends('intrastat_arrivals', 'intrastat_dispatches') @api.depends('intrastat_arrivals', 'intrastat_dispatches')
def _compute_intrastat(self): def _compute_intrastat(self):
for this in self: for this in self:

View File

@@ -9,27 +9,25 @@ class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings' _inherit = 'res.config.settings'
intrastat_incoterm_id = fields.Many2one( intrastat_incoterm_id = fields.Many2one(
related='company_id.intrastat_incoterm_id') related='company_id.intrastat_incoterm_id', readonly=False)
intrastat_arrivals = fields.Selection( intrastat_arrivals = fields.Selection(
related='company_id.intrastat_arrivals') related='company_id.intrastat_arrivals', readonly=False)
intrastat_dispatches = fields.Selection( intrastat_dispatches = fields.Selection(
related='company_id.intrastat_dispatches') related='company_id.intrastat_dispatches', readonly=False)
intrastat = fields.Char(related='company_id.intrastat', readonly=True) intrastat = fields.Char(related='company_id.intrastat')
intrastat_transport_id = fields.Many2one( intrastat_transport_id = fields.Many2one(
related='company_id.intrastat_transport_id') related='company_id.intrastat_transport_id', readonly=False)
intrastat_region_id = fields.Many2one( intrastat_region_id = fields.Many2one(
related='company_id.intrastat_region_id') related='company_id.intrastat_region_id', readonly=False)
intrastat_transaction_out_invoice = fields.Many2one( intrastat_transaction_out_invoice = fields.Many2one(
related='company_id.intrastat_transaction_out_invoice') related='company_id.intrastat_transaction_out_invoice', readonly=False)
intrastat_transaction_out_refund = fields.Many2one( intrastat_transaction_out_refund = fields.Many2one(
related='company_id.intrastat_transaction_out_refund') related='company_id.intrastat_transaction_out_refund', readonly=False)
intrastat_transaction_in_invoice = fields.Many2one( intrastat_transaction_in_invoice = fields.Many2one(
related='company_id.intrastat_transaction_in_invoice') related='company_id.intrastat_transaction_in_invoice', readonly=False)
intrastat_transaction_in_refund = fields.Many2one( intrastat_transaction_in_refund = fields.Many2one(
related='company_id.intrastat_transaction_in_refund') related='company_id.intrastat_transaction_in_refund', readonly=False)
intrastat_accessory_costs = fields.Boolean( intrastat_accessory_costs = fields.Boolean(
related='company_id.intrastat_accessory_costs') related='company_id.intrastat_accessory_costs', readonly=False)
country_id = fields.Many2one( country_id = fields.Many2one(related='company_id.country_id')
related='company_id.country_id', readonly=True) country_code = fields.Char(related='company_id.country_id.code')
country_code = fields.Char(
related='company_id.country_id.code', readonly=True)

View File

@@ -1,7 +1,8 @@
# Copyright 2010-2017 Akretion (http://www.akretion.com) # Copyright 2010-2019 Akretion France (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com> # @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models from odoo import fields, models
class SaleOrder(models.Model): class SaleOrder(models.Model):
@@ -12,9 +13,8 @@ class SaleOrder(models.Model):
help="This information is used in Intrastat reports") help="This information is used in Intrastat reports")
intrastat = fields.Selection( intrastat = fields.Selection(
string='Intrastat Declaration', string='Intrastat Declaration',
related='company_id.intrastat_dispatches', readonly=True) related='company_id.intrastat_dispatches')
@api.multi
def _prepare_invoice(self): def _prepare_invoice(self):
'''Copy destination country to invoice''' '''Copy destination country to invoice'''
vals = super(SaleOrder, self)._prepare_invoice() vals = super(SaleOrder, self)._prepare_invoice()

View File

@@ -2,7 +2,7 @@
# @author Alexis de Lattre <alexis.delattre@akretion.com> # @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com> # @author Luc de Meyer <info@noviat.com>
from odoo import api, fields, models from odoo import fields, models
class StockWarehouse(models.Model): class StockWarehouse(models.Model):
@@ -15,14 +15,11 @@ class StockWarehouse(models.Model):
class StockLocation(models.Model): class StockLocation(models.Model):
_inherit = 'stock.location' _inherit = 'stock.location'
@api.multi
def get_intrastat_region(self): def get_intrastat_region(self):
self.ensure_one() self.ensure_one()
locations = self.search( locations = self.search([('id', 'parent_of', self.id)])
[('parent_left', '<=', self.parent_left),
('parent_right', '>=', self.parent_right)])
warehouses = self.env['stock.warehouse'].search([ warehouses = self.env['stock.warehouse'].search([
('lot_stock_id', 'in', [x.id for x in locations]), ('lot_stock_id', 'in', locations.ids),
('region_id', '!=', False)]) ('region_id', '!=', False)])
if warehouses: if warehouses:
return warehouses[0].region_id return warehouses[0].region_id

View File

@@ -0,0 +1,2 @@
* Alexis de Lattre, Akretion <alexis.delattre@akretion.com>
* Luc De Meyer, Noviat <info@noviat.com>

View File

@@ -0,0 +1,11 @@
This module contains common objects and fields for the Intrastat Product reporting.
It should be used in combination with country-specific Intrastat Product reporting modules
such as:
- *l10n_fr_intrastat_product*:
the module for the *Déclaration d'Echange de Biens* (DEB) for France
- *l10n_be_intrastat_product*:
the module for the Intrastat Product Declaration for Belgium
These country-specific modules can be found in the OCA localization for those countries.

View File

@@ -0,0 +1 @@
This module is NOT compatible with the *account_intrastat* module from Odoo Enterprise.

View File

@@ -0,0 +1,34 @@
This module is used in combination with the country-specific
localization module(s).
Coding guidelines for localization module:
------------------------------------------
We recommend to start by copying an existing module, e.g. l10n_be_intrastat_product
and adapt the code for the specific needs of your country.
* Declaration Object
Create a new class as follows:
.. code-block:: python
class L10nCcIntrastatProductDeclaration(models.Model):
_name = 'l10n.cc.intrastat.product.declaration'
_description = "Intrastat Product Declaration for YourCountry"
_inherit = ['intrastat.product.declaration', 'mail.thread']
whereby cc = your country code
* Computation & Declaration Lines
Create also new objects inheriting from the Computation and Declaration Line Objects
so that you can add methods or customise the methods from the base modules (make a PR when
the customization or new method is required for multiple countries).
Adapt also the parent_id fields of the newly created objects
(cf. l10n_be_intrastat_product as example).
* XML Files: Menu, Action, Views
Cf. l10n_be_istrastat_product as example, replace "be" by your Country Code.

View File

@@ -120,7 +120,7 @@
<field name="name">intrastat.product.declaration.graph</field> <field name="name">intrastat.product.declaration.graph</field>
<field name="model">intrastat.product.declaration</field> <field name="model">intrastat.product.declaration</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<graph string="Intrastat Product" type="bar"> <graph string="Intrastat Product" type="bar" stacked="False">
<field name="year_month" type="row"/> <field name="year_month" type="row"/>
<field name="type" type="row"/> <field name="type" type="row"/>
<field name="total_amount" type="measure"/> <field name="total_amount" type="measure"/>
@@ -128,6 +128,19 @@
</field> </field>
</record> </record>
<record id="intrastat_product_declaration_view_pivot" model="ir.ui.view">
<field name="name">intrastat.product.declaration.pivot</field>
<field name="model">intrastat.product.declaration</field>
<field name="arch" type="xml">
<pivot string="Intrastat Product">
<field name="year_month" type="row"/>
<field name="type" type="col"/>
<field name="total_amount" type="measure"/>
</pivot>
</field>
</record>
<!-- No menuitem nor action since these are provided by the localization modules --> <!-- No menuitem nor action since these are provided by the localization modules -->
<record id="intrastat_product_computation_line_view_form" model="ir.ui.view"> <record id="intrastat_product_computation_line_view_form" model="ir.ui.view">
@@ -150,9 +163,8 @@
<field name="company_currency_id" invisible="1"/> <field name="company_currency_id" invisible="1"/>
<field name="transaction_id"/> <field name="transaction_id"/>
<label for="weight"/> <label for="weight"/>
<div> <div name="weight">
<field name="weight" class="oe_inline"/> <field name="weight" class="oe_inline"/> Kg
<label string=" Kg" class="oe_inline"/>
</div> </div>
<field name="suppl_unit_qty"/> <field name="suppl_unit_qty"/>
<field name="intrastat_unit_id"/> <field name="intrastat_unit_id"/>
@@ -216,9 +228,8 @@
<field name="company_currency_id" invisible="1"/> <field name="company_currency_id" invisible="1"/>
<field name="transaction_id"/> <field name="transaction_id"/>
<label for="weight"/> <label for="weight"/>
<div> <div name="weight">
<field name="weight" class="oe_inline"/> <field name="weight" class="oe_inline"/> Kg
<label string=" Kg" class="oe_inline"/>
</div> </div>
<field name="suppl_unit_qty"/> <field name="suppl_unit_qty"/>
<field name="intrastat_unit_id"/> <field name="intrastat_unit_id"/>

View File

@@ -15,11 +15,17 @@
<field name="model">intrastat.unit</field> <field name="model">intrastat.unit</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Intrastat Supplementary Unit"> <form string="Intrastat Supplementary Unit">
<group> <div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object"
class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button"
options='{"terminology": "archive"}'/>
</button>
</div>
<group name="main">
<field name="name"/> <field name="name"/>
<field name="uom_id" required="1"/> <field name="uom_id" required="1"/>
<field name="description"/> <field name="description"/>
<field name="active"/>
</group> </group>
</form> </form>
</field> </field>
@@ -43,11 +49,12 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<search string="Search Intrastat Supplementary Units"> <search string="Search Intrastat Supplementary Units">
<field name="name" <field name="name"
filter_domain="['|', ('name', 'ilike', self), ('description', 'ilike', self)]"/> filter_domain="['|', ('name', 'ilike', self), ('description', 'ilike', self)]"/>
<group string="Group By" name="groupby"> <filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
<filter name="uom_groupby" string="Regular UoM" <group string="Group By" name="groupby">
context="{'group_by': 'uom_id'}"/> <filter name="uom_groupby" string="Regular UoM"
</group> context="{'group_by': 'uom_id'}"/>
</group>
</search> </search>
</field> </field>
</record> </record>

View File

@@ -21,7 +21,7 @@
<div class="col-xs-12 col-md-12 o_setting_box"> <div class="col-xs-12 col-md-12 o_setting_box">
<div class="o_setting_left_pane"/> <div class="o_setting_left_pane"/>
<div class="o_setting_right_pane"> <div class="o_setting_right_pane" id="intrastat-product-main-params">
<div class="row"> <div class="row">
<label for="intrastat_arrivals" class="col-md-5 o_light_label"/> <label for="intrastat_arrivals" class="col-md-5 o_light_label"/>
<field name="intrastat_arrivals"/> <field name="intrastat_arrivals"/>
@@ -34,7 +34,7 @@
<label for="intrastat_transport_id" class="col-md-5 o_light_label"/> <label for="intrastat_transport_id" class="col-md-5 o_light_label"/>
<field name="intrastat_transport_id"/> <field name="intrastat_transport_id"/>
</div> </div>
<div class="row"> <div class="row" attrs="{'invisible': [('country_code', 'in', ['FR'])]}">
<label for="intrastat_incoterm_id" class="col-md-5 o_light_label"/> <label for="intrastat_incoterm_id" class="col-md-5 o_light_label"/>
<field name="intrastat_incoterm_id"/> <field name="intrastat_incoterm_id"/>
</div> </div>
@@ -50,7 +50,7 @@
<label for="intrastat_transaction_in_invoice" class="col-md-5 o_light_label"/> <label for="intrastat_transaction_in_invoice" class="col-md-5 o_light_label"/>
<field name="intrastat_transaction_in_invoice"/> <field name="intrastat_transaction_in_invoice"/>
</div> </div>
<div class="row"> <div class="row" attrs="{'invisible': [('country_code', 'in', ['FR'])]}">
<label for="intrastat_transaction_in_refund" class="col-md-5 o_light_label"/> <label for="intrastat_transaction_in_refund" class="col-md-5 o_light_label"/>
<field name="intrastat_transaction_in_refund"/> <field name="intrastat_transaction_in_refund"/>
</div> </div>