Skip to content

Commit

Permalink
update intrastat_product
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-demeyer authored and alexis-via committed Mar 6, 2023
1 parent 80c0e7c commit 2320981
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 46 deletions.
2 changes: 1 addition & 1 deletion intrastat_product/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion intrastat_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from . import res_company
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 sale_order
from . import stock_picking
from . import stock_warehouse
37 changes: 31 additions & 6 deletions intrastat_product/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com>
#
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -59,9 +65,28 @@ def _compute_intrastat_country(self):
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(
Expand Down
78 changes: 45 additions & 33 deletions intrastat_product/models/intrastat_product_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,19 @@ def _get_intrastat_transaction(self, inv_line):
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
product = inv_line.product_id
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:
Expand Down Expand Up @@ -371,26 +373,26 @@ def _get_region(self, inv_line):
"""
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
Expand Down Expand Up @@ -431,7 +433,7 @@ def _handle_invoice_accessory_cost(
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
Expand All @@ -455,6 +457,11 @@ def _handle_invoice_accessory_cost(
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 = [
Expand All @@ -463,10 +470,6 @@ def _prepare_invoice_domain(self):
('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):
Expand All @@ -477,11 +480,16 @@ def _is_product(self, invoice_line):
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)

Expand Down Expand Up @@ -590,7 +598,8 @@ def _gather_invoices(self):

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,
Expand All @@ -615,18 +624,21 @@ def _gather_invoices(self):

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 (
Expand Down
5 changes: 4 additions & 1 deletion intrastat_product/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion intrastat_product/views/account_invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
attrs="{'invisible': [('intrastat', '!=', 'extended')]}"
widget="selection"/>
<field name="src_dest_country_id" string="Destination Country"/>
<field name="src_dest_region_id" string="Origin Region" invisible="1"/>
</xpath>
<xpath expr="//field[@name='invoice_line']//field[@name='account_id']" position="after">
<field name="hs_code_id"/>
Expand All @@ -40,7 +41,8 @@
<field name="intrastat_transport_id"
attrs="{'invisible': [('intrastat', '!=', 'extended')]}"
widget="selection"/>
<field name="src_dest_country_id" string="Origin Country"/>
<field name="src_dest_country_id" string="Origin/Destination Country"/>
<field name="src_dest_region_id" string="Origin/Destination Region" invisible="1"/>
</xpath>
<xpath expr="//field[@name='invoice_line']//field[@name='account_id']" position="after">
<field name="hs_code_id"/>
Expand Down
4 changes: 2 additions & 2 deletions intrastat_product/views/intrastat_product_declaration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
<field name="model">intrastat.product.declaration</field>
<field name="arch" type="xml">
<search string="Search Intrastat Product Declarations">
<filter name="arrivals" string="Arrivals" domain="[('type', 'like', 'EX19')]" />
<filter name="dispatches" string="Dispatches" domain="[('type', 'like', 'EX29')]" />
<filter name="arrivals" string="Arrivals" domain="[('type', '=', 'arrivals')]"/>
<filter name="dispatches" string="Dispatches" domain="[('type', '=', 'dispatches')]"/>
<filter name="draft" string="Draft" domain="[('state', '=', 'draft')]" />
<filter name="done" string="Done" domain="[('state', '=', 'done')]" />
<group string="Group By" name="group_by">
Expand Down
2 changes: 1 addition & 1 deletion intrastat_product/views/intrastat_unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<form string="Intrastat Supplementary Unit">
<group>
<field name="name"/>
<field name="uom_id"/>
<field name="uom_id" required="1"/>
<field name="description"/>
<field name="active"/>
</group>
Expand Down

0 comments on commit 2320981

Please sign in to comment.