diff --git a/intrastat_product/__openerp__.py b/intrastat_product/__openerp__.py index 917ca49..c559fe3 100644 --- a/intrastat_product/__openerp__.py +++ b/intrastat_product/__openerp__.py @@ -24,7 +24,7 @@ { 'name': 'Intrastat Product', - 'version': '8.0.1.4.0', + 'version': '8.0.1.4.1', 'category': 'Intrastat', 'license': 'AGPL-3', 'summary': 'Base module for Intrastat Product', diff --git a/intrastat_product/models/__init__.py b/intrastat_product/models/__init__.py index b62d055..09f082d 100644 --- a/intrastat_product/models/__init__.py +++ b/intrastat_product/models/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from . import res_company from . import account_invoice from . import hs_code from . import intrastat_product_declaration @@ -6,7 +7,6 @@ from . import intrastat_region from . import intrastat_transaction from . import intrastat_transport_mode from . import intrastat_unit -from . import res_company from . import sale_order from . import stock_picking from . import stock_warehouse diff --git a/intrastat_product/models/account_invoice.py b/intrastat_product/models/account_invoice.py index 0a26870..42df8f4 100644 --- a/intrastat_product/models/account_invoice.py +++ b/intrastat_product/models/account_invoice.py @@ -2,8 +2,8 @@ ############################################################################## # # Intrastat Product module for Odoo -# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) +# Copyright (C) 2011-2016 Akretion (http://www.akretion.com) +# Copyright (C) 2009-2016 Noviat (http://www.noviat.com) # @author Alexis de Lattre # @author Luc de Meyer # @@ -34,7 +34,7 @@ class AccountInvoice(models.Model): "commercial terms used in international transactions.") intrastat_transaction_id = fields.Many2one( 'intrastat.transaction', string='Intrastat Transaction Type', - default=lambda self: self._default_intrastat_transaction(), + default=lambda self: self._default_intrastat_transaction_id(), ondelete='restrict', help="Intrastat nature of transaction") intrastat_transport_id = fields.Many2one( @@ -43,6 +43,12 @@ class AccountInvoice(models.Model): src_dest_country_id = fields.Many2one( 'res.country', string='Origin/Destination Country', ondelete='restrict') + src_dest_region_id = fields.Many2one( + 'intrastat.region', string='Origin/Destination Region', + default=lambda self: self._default_src_dest_region_id(), + help="Origin/Destination Region." + "\nThis field is used for the Intrastat Declaration.", + ondelete='restrict') intrastat_country = fields.Boolean( compute='_compute_intrastat_country', store=True, string='Intrastat Country', readonly=True) @@ -59,9 +65,28 @@ class AccountInvoice(models.Model): inv.intrastat_country = country.intrastat @api.model - def _default_intrastat_transaction(self): - """ placeholder for localisation modules """ - return self.env['intrastat.transaction'].browse([]) + def _default_intrastat_transaction_id(self): + company = self.env['res.company'] + company_id = company._company_default_get('account.invoice') + company = company.browse(company_id) + inv_type = self._context.get('type') + if inv_type == 'out_invoice': + return company.intrastat_transaction_out_invoice + elif inv_type == 'out_refund': + return company.intrastat_transaction_out_refund + elif inv_type == 'in_invoice': + return company.intrastat_transaction_in_invoice + elif inv_type == 'in_refund': + return company.intrastat_transaction_in_refund + else: + return self.env['intrastat.transaction'] + + @api.model + def _default_src_dest_region_id(self): + company = self.env['res.company'] + company_id = company._company_default_get('account.invoice') + company = company.browse(company_id) + return company.intrastat_region_id @api.multi def onchange_partner_id( diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py index 6ac180f..6c5e099 100644 --- a/intrastat_product/models/intrastat_product_declaration.py +++ b/intrastat_product/models/intrastat_product_declaration.py @@ -254,6 +254,8 @@ class IntrastatProductDeclaration(models.Model): return company.intrastat_transaction_out_refund elif invoice.type == 'in_invoice': return company.intrastat_transaction_in_invoice + elif invoice.type == 'in_refund': + return company.intrastat_transaction_in_refund def _get_weight_and_supplunits(self, inv_line, hs_code): line_qty = inv_line.quantity @@ -261,10 +263,10 @@ class IntrastatProductDeclaration(models.Model): invoice = inv_line.invoice_id intrastat_unit_id = hs_code.intrastat_unit_id source_uom = inv_line.uos_id - weight_uom_categ = self._uom_refs['weight_uom_categ'] - kg_uom = self._uom_refs['kg_uom'] - pce_uom_categ = self._uom_refs['pce_uom_categ'] - pce_uom = self._uom_refs['pce_uom'] + weight_uom_categ = self._get_uom_refs('weight_uom_categ') + kg_uom = self._get_uom_refs('kg_uom') + pce_uom_categ = self._get_uom_refs('pce_uom_categ') + pce_uom = self._get_uom_refs('pce_uom') weight = suppl_unit_qty = 0.0 if not source_uom: @@ -371,26 +373,26 @@ class IntrastatProductDeclaration(models.Model): """ region = False - if inv_line.invoice_id.type in ('in_invoice', 'in_refund'): - if inv_line.move_line_ids: - region = inv_line.move_line_ids[0].location_dest_id.\ - get_intrastat_region() - else: - po_lines = self.env['purchase.order.line'].search( - [('invoice_lines', 'in', inv_line.id)]) - if po_lines: - po = po_lines.order_id - region = po.location_id.get_intrastat_region() - elif inv_line.invoice_id.type in ('out_invoice', 'out_refund'): - if inv_line.move_line_ids: + inv_type = inv_line.invoice_id.type + if inv_line.move_line_ids: + if inv_type in ('in_invoice', 'out_refund'): region = inv_line.move_line_ids[0].location_id.\ get_intrastat_region() else: - so_lines = self.env['sale.order.line'].search( - [('invoice_lines', 'in', inv_line.id)]) - if so_lines: - so = so_lines.order_id - region = so.warehouse_id.region_id + region = inv_line.move_line_ids[0].location_dest_id.\ + get_intrastat_region() + elif inv_type in ('in_invoice', 'in_refund'): + po_lines = self.env['purchase.order.line'].search( + [('invoice_lines', 'in', inv_line.id)]) + if po_lines: + po = po_lines.order_id + region = po.location_id.get_intrastat_region() + elif inv_line.invoice_id.type in ('out_invoice', 'out_refund'): + so_lines = self.env['sale.order.line'].search( + [('invoice_lines', 'in', inv_line.id)]) + if so_lines: + so = so_lines.order_id + region = so.warehouse_id.region_id if not region: if self.company_id.intrastat_region_id: region = self.company_id.intrastat_region_id @@ -431,7 +433,7 @@ class IntrastatProductDeclaration(models.Model): total_inv_weight): """ Affect accessory costs pro-rata of the value - (or pro-rata of the weight is the goods of the invoice + (or pro-rata of the weight if the goods of the invoice have no value) This method allows to implement a different logic @@ -455,6 +457,11 @@ class IntrastatProductDeclaration(models.Model): total_inv_weight) def _prepare_invoice_domain(self): + """ + Complete this method in the localization module + with the country-specific logic for arrivals and dispatches. + Cf. l10n_be_intrastat_product_declaration for an example + """ start_date = date(self.year, self.month, 1) end_date = start_date + relativedelta(day=1, months=+1, days=-1) domain = [ @@ -463,10 +470,6 @@ class IntrastatProductDeclaration(models.Model): ('state', 'in', ['open', 'paid']), ('intrastat_country', '=', True), ('company_id', '=', self.company_id.id)] - if self.type == 'arrivals': - domain.append(('type', 'in', ('in_invoice', 'in_refund'))) - elif self.type == 'dispatches': - domain.append(('type', 'in', ('out_invoice', 'out_refund'))) return domain def _is_product(self, invoice_line): @@ -477,11 +480,16 @@ class IntrastatProductDeclaration(models.Model): else: return False + def _gather_invoices_init(self): + """ placeholder for localization modules """ + pass + def _gather_invoices(self): lines = [] accessory_costs = self.company_id.intrastat_accessory_costs + self._gather_invoices_init() domain = self._prepare_invoice_domain() invoices = self.env['account.invoice'].search(domain) @@ -590,7 +598,8 @@ class IntrastatProductDeclaration(models.Model): self._update_computation_line_vals(inv_line, line_vals) - lines_current_invoice.append((line_vals)) + if line_vals: + lines_current_invoice.append((line_vals)) self._handle_invoice_accessory_cost( invoice, lines_current_invoice, @@ -615,18 +624,21 @@ class IntrastatProductDeclaration(models.Model): return lines + def _get_uom_refs(self, ref): + uom_refs = { + 'weight_uom_categ': self.env.ref('product.product_uom_categ_kgm'), + 'kg_uom': self.env.ref('product.product_uom_kgm'), + 'pce_uom_categ': self.env.ref('product.product_uom_categ_unit'), + 'pce_uom': self.env.ref('product.product_uom_unit') + } + return uom_refs[ref] + @api.multi def action_gather(self): self.ensure_one() self.message_post(_("Generate Lines from Invoices")) self._check_generate_lines() self._note = '' - self._uom_refs = { - 'weight_uom_categ': self.env.ref('product.product_uom_categ_kgm'), - 'kg_uom': self.env.ref('product.product_uom_kgm'), - 'pce_uom_categ': self.env.ref('product.product_uom_categ_unit'), - 'pce_uom': self.env.ref('product.product_uom_unit') - } if ( self.type == 'arrivals' and self.company_id.intrastat_arrivals == 'extended') or ( diff --git a/intrastat_product/models/stock_picking.py b/intrastat_product/models/stock_picking.py index 5080277..f46705f 100644 --- a/intrastat_product/models/stock_picking.py +++ b/intrastat_product/models/stock_picking.py @@ -35,9 +35,12 @@ class StockPicking(models.Model): @api.model def _create_invoice_from_picking(self, picking, vals): - '''Copy transport and department from picking to invoice''' + """ Copy data from picking to invoice. """ vals['intrastat_transport_id'] = picking.intrastat_transport_id.id if picking.partner_id and picking.partner_id.country_id: vals['src_dest_country_id'] = picking.partner_id.country_id.id + region = picking.location_id.get_intrastat_region() + if region: + vals['src_dest_region_id'] = region.id return super(StockPicking, self)._create_invoice_from_picking( picking, vals) diff --git a/intrastat_product/views/account_invoice.xml b/intrastat_product/views/account_invoice.xml index 709ebbb..26332cd 100644 --- a/intrastat_product/views/account_invoice.xml +++ b/intrastat_product/views/account_invoice.xml @@ -18,6 +18,7 @@ attrs="{'invisible': [('intrastat', '!=', 'extended')]}" widget="selection"/> + @@ -40,7 +41,8 @@ - + + diff --git a/intrastat_product/views/intrastat_product_declaration.xml b/intrastat_product/views/intrastat_product_declaration.xml index 6805b58..7ddc9bd 100644 --- a/intrastat_product/views/intrastat_product_declaration.xml +++ b/intrastat_product/views/intrastat_product_declaration.xml @@ -104,8 +104,8 @@ intrastat.product.declaration - - + + diff --git a/intrastat_product/views/intrastat_unit.xml b/intrastat_product/views/intrastat_unit.xml index acbb3c6..2bfa2da 100644 --- a/intrastat_product/views/intrastat_unit.xml +++ b/intrastat_product/views/intrastat_unit.xml @@ -19,7 +19,7 @@
- +