Skip to content

Commit

Permalink
Add option intrastat_accessory_costs on company
Browse files Browse the repository at this point in the history
Set more fields as invisible (localisation should put them visible if they need it)
Fix handling of suppl. units when hs_code is empty on invoice line (but set on product)
Small usability enhancements
  • Loading branch information
alexis-via committed Dec 9, 2015
1 parent 7e3a9ce commit 1b4bd4c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
5 changes: 3 additions & 2 deletions intrastat_base/views/account_tax.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright (C) 2011-2014 Akretion (http://www.akretion.com/)
Copyright (C) 2011-2015 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
Expand All @@ -16,7 +16,8 @@
<field name="inherit_id" ref="account.view_tax_form"/>
<field name="arch" type="xml">
<field name="active" position="after">
<field name="exclude_from_intrastat_if_present" />
<!-- Will be set visible in the localisation modules that need it -->
<field name="exclude_from_intrastat_if_present" invisible="1"/>
</field>
</field>
</record>
Expand Down
3 changes: 2 additions & 1 deletion intrastat_base/views/product_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<group name="properties" position="after">
<group string="Intrastat Properties" name="intrastat">
<field name="is_accessory_cost"
attrs="{'invisible': [('type', '!=', 'service')]}"/>
attrs="{'invisible': [('type', '!=', 'service')]}"
invisible="1"/>
</group>
</group>
</field>
Expand Down
7 changes: 7 additions & 0 deletions intrastat_product/demo/intrastat_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@
<field name="intrastat_unit_id" ref="intrastat_unit_pce"/>
</record>

<record id="base.main_company" model="res.company">
<field name="intrastat_arrivals">extended</field>
<field name="intrastat_dispatches">extended</field>
<field name="intrastat_incoterm_id" ref="stock.incoterm_DDU"/>
<field name="intrastat_transport_id" ref="intrastat_transport_3"/>
</record>

</data>
</openerp>
32 changes: 19 additions & 13 deletions intrastat_product/models/intrastat_product_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def _get_default_action(self):
default=_get_month)
year_month = fields.Char(
compute='_compute_year_month', string='Period', readonly=True,
track_visibility='always', store=True,
track_visibility='onchange', store=True,
help="Year and month of the declaration.")
type = fields.Selection(
'_get_type', string='Type', required=True,
states={'done': [('readonly', True)]},
track_visibility='always', help="Select the declaration type.")
track_visibility='onchange', help="Select the declaration type.")
action = fields.Selection(
'_get_action',
string='Action', required=True,
Expand Down Expand Up @@ -253,11 +253,11 @@ def _get_intrastat_transaction(self, inv_line):
elif invoice.type == 'in_invoice':
return company.intrastat_transaction_in_invoice

def _get_weight_and_supplunits(self, inv_line):
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 = inv_line.hs_code_id.intrastat_unit_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']
Expand All @@ -284,7 +284,7 @@ def _get_weight_and_supplunits(self, inv_line):
) % intrastat_unit_id.name
note += "\n" + _(
"Please correct the Intrastat Supplementary Unit "
"settingsand regenerate the lines or adjust the lines "
"settings and regenerate the lines or adjust the lines "
"with Intrastat Code '%s' manually"
) % inv_line.hs_code_id.local_code
self._note += note
Expand Down Expand Up @@ -413,6 +413,7 @@ def _update_computation_line_vals(self, inv_line, line_vals):
def _gather_invoices(self):

lines = []
accessory_costs = self.company_id.intrastat_accessory_costs
start_date = date(self.year, self.month, 1)
end_date = start_date + relativedelta(day=1, months=+1, days=-1)

Expand All @@ -438,6 +439,7 @@ def _gather_invoices(self):
for inv_line in invoice.invoice_line:

if (
accessory_costs and
inv_line.product_id and
inv_line.product_id.is_accessory_cost):
acost = invoice.currency_id.with_context(
Expand All @@ -463,29 +465,29 @@ def _gather_invoices(self):
continue

if inv_line.hs_code_id:
intrastat = inv_line.hs_code_id
hs_code = inv_line.hs_code_id
elif (
inv_line.product_id and
inv_line.product_id.type in ('product', 'consu')):
intrastat = inv_line.product_id.product_tmpl_id.\
hs_code = inv_line.product_id.product_tmpl_id.\
get_hs_code_recursively()
if not intrastat:
if not hs_code:
note = "\n" + _(
'Missing H.S. code on product %s (%s). '
'This product is present in invoice %s.') % (
inv_line.product_id.name,
inv_line.product_id.default_code,
inv_line.invoice_id.number)
self._note += note

if not intrastat:
continue
else:
continue

intrastat_transaction = \
self._get_intrastat_transaction(inv_line)

weight, suppl_unit_qty = self._get_weight_and_supplunits(
inv_line)
inv_line, hs_code)

amount_company_currency = self._get_amount(inv_line)
total_inv_product_cc += amount_company_currency
Expand All @@ -498,7 +500,7 @@ def _gather_invoices(self):
'invoice_line_id': inv_line.id,
'src_dest_country_id': partner_country.id,
'product_id': inv_line.product_id.id,
'hs_code_id': intrastat.id,
'hs_code_id': hs_code.id,
'weight': weight,
'suppl_unit_qty': suppl_unit_qty,
'amount_company_currency': amount_company_currency,
Expand Down Expand Up @@ -536,6 +538,7 @@ def _gather_invoices(self):
@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 = {
Expand Down Expand Up @@ -569,7 +572,8 @@ def action_gather(self):
self.write({'computation_line_ids': [(0, 0, x) for x in lines]})

if self._note:
note_header = '\n\n>>> ' + str(date.today()) + '\n'
note_header = '\n\n>>> ' + fields.Datetime.to_string(
fields.Datetime.context_timestamp(self, datetime.now())) + '\n'
self.note = note_header + self._note + (self.note or '')
result_view = self.env.ref(
'intrastat_base.intrastat_result_view_form')
Expand Down Expand Up @@ -604,6 +608,7 @@ def generate_declaration(self):
""" generate declaration lines """
self.ensure_one()
assert self.valid, 'Computation lines are not valid'
self.message_post(_("Generate Declaration Lines"))
# Delete existing declaration lines
self.declaration_line_ids.unlink()
# Regenerate declaration lines from computation lines
Expand All @@ -626,6 +631,7 @@ def generate_declaration(self):
def generate_xml(self):
""" generate the INTRASTAT Declaration XML file """
self.ensure_one()
self.message_post(_("Generate XML Declaration File"))
self._check_generate_xml()
self._unlink_attachments()
xml_string = self._generate_xml()
Expand Down
2 changes: 2 additions & 0 deletions intrastat_product/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ResCompany(models.Model):
intrastat_transaction_in_invoice = fields.Many2one(
'intrastat.transaction',
string='Default Intrastat Transaction For Supplier Invoices')
intrastat_accessory_costs = fields.Boolean(
string='Include Accessory Costs in Fiscal Value of Product')

@api.model
def _intrastat_arrivals(self):
Expand Down
1 change: 1 addition & 0 deletions intrastat_product/views/res_company.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<field name="intrastat_transport_id"
attrs="{'required': [('intrastat', '=', 'extended')], 'invisible': [('intrastat', '!=', 'extended')]}"/>
<field name="intrastat_incoterm_id" invisible="1"/>
<field name="intrastat_accessory_costs" invisible="1"/>
</group>
</field>
</record>
Expand Down

0 comments on commit 1b4bd4c

Please sign in to comment.