diff --git a/intrastat_product/models/__init__.py b/intrastat_product/models/__init__.py
index 9663fcd..f00785c 100644
--- a/intrastat_product/models/__init__.py
+++ b/intrastat_product/models/__init__.py
@@ -1,10 +1,10 @@
# -*- encoding: utf-8 -*-
-
-from . import res_company
-from . import hs_code
-from . import intrastat_transaction
-from . import intrastat_unit
-from . import intrastat_transport_mode
-from . import intrastat_product_declaration
-from . import stock_picking
from . import account_invoice
+from . import hs_code
+from . import intrastat_product_declaration
+from . import intrastat_region
+from . import intrastat_transaction
+from . import intrastat_transport_mode
+from . import intrastat_unit
+from . import res_company
+from . import stock_picking
diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py
index db561e2..3fe3dc4 100644
--- a/intrastat_product/models/intrastat_product_declaration.py
+++ b/intrastat_product/models/intrastat_product_declaration.py
@@ -342,6 +342,39 @@ class IntrastatProductDeclaration(models.Model):
amount)
return amount
+ def _get_region(self, inv_line):
+ """
+ Logic copied from standard addons, l10n_be_intrastat module:
+
+ If purchase, comes from purchase order, linked to a location,
+ which is linked to the warehouse.
+
+ If sales, the sale order is linked to the warehouse.
+ If sales, from a delivery order, linked to a location,
+ which is linked to the warehouse.
+
+ If none found, get the company one.
+ """
+ region = False
+ if inv_line.invoice_id.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 = self.env['stock.warehouse'].get_region_from_location(
+ po.location_id)
+ 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
+ return region
+
+
def _get_transport(self, inv_line):
transport = inv_line.invoice_id.intrastat_transport_id \
or self.company_id.intrastat_transport_id
@@ -606,6 +639,8 @@ class IntrastatProductComputationLine(models.Model):
transaction_id = fields.Many2one(
'intrastat.transaction',
string='Intrastat Transaction')
+ region_id = fields.Many2one(
+ 'intrastat.region', string='Intrastat Region')
# extended declaration
incoterm_id = fields.Many2one(
'stock.incoterms', string='Incoterm')
diff --git a/intrastat_product/models/intrastat_region.py b/intrastat_product/models/intrastat_region.py
new file mode 100644
index 0000000..3d1333e
--- /dev/null
+++ b/intrastat_product/models/intrastat_region.py
@@ -0,0 +1,43 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Odoo, Open Source Management Solution
+#
+# Copyright (c) 2009-2015 Noviat nv/sa (www.noviat.com).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from openerp import models, fields
+
+
+class IntrastatRegion(models.Model):
+ _name = 'intrastat.region'
+ _description = "Intrastat Region"
+
+ code = fields.Char(string='Code', required=True)
+ country_id = fields.Many2one(
+ 'res.country', string='Country', required=True)
+ name = fields.Char(string='Name', translate=True)
+ description = fields.Char(string='Description')
+ company_id = fields.Many2one(
+ 'res.company', string='Company',
+ default=lambda self: self.env['res.company']._company_default_get(
+ 'intrastat.region'))
+
+ _sql_constraints = [
+ ('intrastat_region_code_unique',
+ 'UNIQUE(code, country_id)',
+ 'Code must be unique.')]
diff --git a/intrastat_product/models/res_company.py b/intrastat_product/models/res_company.py
index 988048f..f3d4c9b 100644
--- a/intrastat_product/models/res_company.py
+++ b/intrastat_product/models/res_company.py
@@ -46,6 +46,9 @@ class ResCompany(models.Model):
intrastat = fields.Char(
string='Intrastat Declaration', store=True, readonly=True,
compute='_compute_intrastat')
+ intrastat_region_id = fields.Many2one(
+ 'intrastat.region',
+ string='Default Intrastat region')
@api.model
def _intrastat_arrivals(self):
diff --git a/intrastat_product/views/res_company.xml b/intrastat_product/views/res_company.xml
index 06e1ea1..263f0e0 100644
--- a/intrastat_product/views/res_company.xml
+++ b/intrastat_product/views/res_company.xml
@@ -11,6 +11,7 @@
+