add region to intrastat_product

This commit is contained in:
luc-demeyer
2015-11-06 18:31:49 +01:00
committed by Alexis de Lattre
parent ce293b57db
commit 0cdfd10819
5 changed files with 90 additions and 8 deletions

View File

@@ -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

View File

@@ -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')

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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.')]

View File

@@ -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):

View File

@@ -11,6 +11,7 @@
<field name="intrastat" invisible="1"/>
<field name="intrastat_arrivals"/>
<field name="intrastat_dispatches"/>
<field name="intrastat_region_id" domain="[('country_id','=', country_id)]" invisible="1"/>
<field name="intrastat_transport_id"
attrs="{'required': [('intrastat', '=', 'extended')], 'invisible': [('intrastat', '!=', 'extended')]}"/>
<field name="intrastat_incoterm_id"