diff --git a/intrastat_base/models/__init__.py b/intrastat_base/models/__init__.py index 18530f9..a571f6a 100644 --- a/intrastat_base/models/__init__.py +++ b/intrastat_base/models/__init__.py @@ -1,24 +1,4 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Report intrastat base module for Odoo -# Copyright (C) 2011-2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# 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 . -# -############################################################################## +# -*- coding: utf-8 -*- from . import res_country from . import product_template diff --git a/intrastat_base/models/account_tax.py b/intrastat_base/models/account_tax.py index 197e51d..e11db59 100644 --- a/intrastat_base/models/account_tax.py +++ b/intrastat_base/models/account_tax.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo diff --git a/intrastat_base/models/intrastat_common.py b/intrastat_base/models/intrastat_common.py index e8b9dda..1aa210e 100644 --- a/intrastat_base/models/intrastat_common.py +++ b/intrastat_base/models/intrastat_common.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo diff --git a/intrastat_base/models/product_template.py b/intrastat_base/models/product_template.py index 5373cb3..69fe7ce 100644 --- a/intrastat_base/models/product_template.py +++ b/intrastat_base/models/product_template.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo diff --git a/intrastat_base/models/res_company.py b/intrastat_base/models/res_company.py index 2206c76..1175d76 100644 --- a/intrastat_base/models/res_company.py +++ b/intrastat_base/models/res_company.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo diff --git a/intrastat_base/models/res_country.py b/intrastat_base/models/res_country.py index 7a34e77..8703f10 100644 --- a/intrastat_base/models/res_country.py +++ b/intrastat_base/models/res_country.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo diff --git a/intrastat_product/models/account_invoice.py b/intrastat_product/models/account_invoice.py index 74f713a..b488466 100644 --- a/intrastat_product/models/account_invoice.py +++ b/intrastat_product/models/account_invoice.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat Product module for Odoo diff --git a/intrastat_product/models/hs_code.py b/intrastat_product/models/hs_code.py index 6e23770..a4ae30b 100644 --- a/intrastat_product/models/hs_code.py +++ b/intrastat_product/models/hs_code.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat Product module for Odoo diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py index e6aa4e5..aa1790e 100644 --- a/intrastat_product/models/intrastat_product_declaration.py +++ b/intrastat_product/models/intrastat_product_declaration.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat Product module for Odoo @@ -240,7 +240,17 @@ class IntrastatProductDeclaration(models.Model): return country def _get_intrastat_transaction(self, inv_line): - return inv_line.invoice_id.intrastat_transaction_id + invoice = inv_line.invoice_id + if invoice.intrastat_transaction_id: + return invoice.intrastat_transaction_id + else: + company = invoice.company_id + if invoice.type == 'out_invoice': + return company.intrastat_transaction_out_invoice + elif invoice.type == 'out_refund': + return company.intrastat_transaction_out_refund + elif invoice.type == 'in_invoice': + return company.intrastat_transaction_in_invoice def _get_weight_and_supplunits(self, inv_line): line_qty = inv_line.quantity @@ -333,13 +343,10 @@ class IntrastatProductDeclaration(models.Model): def _get_amount(self, inv_line): invoice = inv_line.invoice_id - amount = inv_line.price_subtotal - if invoice.currency_id.name != 'EUR': - amount = self.env['res.currency'].with_context( - date=invoice.date_invoice).compute( - invoice.currency_id, - self.company_id.currency_id, - amount) + amount = invoice.currency_id.with_context( + date=invoice.date_invoice).compute( + inv_line.price_subtotal, + self.company_id.currency_id) return amount def _get_region(self, inv_line): @@ -366,17 +373,14 @@ class IntrastatProductDeclaration(models.Model): 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)]) - print "so_lines=", so_lines 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 - print "region=", region return region - def _get_transport(self, inv_line): transport = inv_line.invoice_id.intrastat_transport_id \ or self.company_id.intrastat_transport_id @@ -399,6 +403,9 @@ class IntrastatProductDeclaration(models.Model): self._company_warning(msg) return incoterm + def _get_product_origin_country(self, inv_line): + return inv_line.product_id.origin_country_id + def _update_computation_line_vals(self, inv_line, line_vals): """ placeholder for localization modules """ pass @@ -425,8 +432,22 @@ class IntrastatProductDeclaration(models.Model): if invoice.type in ['in_invoice', 'out_refund']: continue + lines_current_invoice = [] + total_inv_accessory_costs_cc = 0.0 # in company currency + total_inv_product_cc = 0.0 # in company currency for inv_line in invoice.invoice_line: + if ( + inv_line.product_id and + inv_line.product_id.is_accessory_cost): + acost = invoice.currency_id.with_context( + date=invoice.date_invoice).compute( + inv_line.price_subtotal, + self.company_id.currency_id) + total_inv_accessory_costs_cc += acost + + continue + intrastat = inv_line.hs_code_id if not intrastat: continue @@ -444,6 +465,10 @@ class IntrastatProductDeclaration(models.Model): inv_line) amount_company_currency = self._get_amount(inv_line) + total_inv_product_cc += amount_company_currency + + product_origin_country = self._get_product_origin_country( + inv_line) line_vals = { 'parent_id': self.id, @@ -454,7 +479,10 @@ class IntrastatProductDeclaration(models.Model): 'weight': weight, 'suppl_unit_qty': suppl_unit_qty, 'amount_company_currency': amount_company_currency, + 'amount_accessory_cost_company_currency': 0.0, 'transaction_id': intrastat_transaction.id, + 'product_origin_country_id': + product_origin_country.id or False, } # extended declaration @@ -468,7 +496,17 @@ class IntrastatProductDeclaration(models.Model): self._update_computation_line_vals(inv_line, line_vals) - lines.append((line_vals)) + lines_current_invoice.append((line_vals)) + + # Affect accessory costs pro-rata of the value + if total_inv_accessory_costs_cc and total_inv_product_cc: + for ac_line_vals in lines_current_invoice: + ac_line_vals['amount_accessory_cost_company_currency'] = ( + total_inv_accessory_costs_cc * + ac_line_vals['amount_company_currency'] / + total_inv_product_cc) + + lines += lines_current_invoice return lines @@ -645,6 +683,12 @@ class IntrastatProductComputationLine(models.Model): help="Amount in company currency to write in the declaration. " "Amount in company currency = amount in invoice currency " "converted to company currency with the rate of the invoice date.") + amount_accessory_cost_company_currency = fields.Float( + string='Accessory Costs', + digits=dp.get_precision('Account'), + help="Amount in company currency of the accessory costs related to " + "this invoice line (by default, these accessory costs are computed " + "at the pro-rata of the amount of each invoice line.") transaction_id = fields.Many2one( 'intrastat.transaction', string='Intrastat Transaction') @@ -753,6 +797,7 @@ class IntrastatProductDeclarationLine(models.Model): 'parent_id': computation_line.parent_id.id, 'product_origin_country_id': computation_line.product_origin_country_id.id, + 'amount_company_currency': 0.0, } for field in fields_to_sum: vals[field] = 0.0 @@ -762,7 +807,6 @@ class IntrastatProductDeclarationLine(models.Model): fields_to_sum = [ 'weight', 'suppl_unit_qty', - 'amount_company_currency', ] return fields_to_sum @@ -774,4 +818,12 @@ class IntrastatProductDeclarationLine(models.Model): for computation_line in computation_lines: for field in fields_to_sum: vals[field] += computation_line[field] + vals['amount_company_currency'] += ( + computation_line['amount_company_currency'] + + computation_line['amount_accessory_cost_company_currency']) + # round, otherwise odoo with truncate (6.7 -> 6... instead of 7 !) + for field in fields_to_sum: + vals[field] = int(round(vals[field])) + vals['amount_company_currency'] = int(round( + vals['amount_company_currency'])) return vals diff --git a/intrastat_product/models/intrastat_region.py b/intrastat_product/models/intrastat_region.py index 3d1333e..9dddfdf 100644 --- a/intrastat_product/models/intrastat_region.py +++ b/intrastat_product/models/intrastat_region.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Odoo, Open Source Management Solution diff --git a/intrastat_product/models/intrastat_transaction.py b/intrastat_product/models/intrastat_transaction.py index 3734fa6..31c86f8 100644 --- a/intrastat_product/models/intrastat_transaction.py +++ b/intrastat_product/models/intrastat_transaction.py @@ -34,7 +34,8 @@ class IntrastatTransaction(models.Model): code = fields.Char(string='Code', required=True) description = fields.Text(string='Description') display_name = fields.Char( - compute='_compute_display_name', string="Display Name", readonly=True) + compute='_compute_display_name', string="Display Name", readonly=True, + store=True) company_id = fields.Many2one( 'res.company', string='Company', default=lambda self: self.env['res.company']._company_default_get( diff --git a/intrastat_product/models/res_company.py b/intrastat_product/models/res_company.py index de568ef..2bc5b04 100644 --- a/intrastat_product/models/res_company.py +++ b/intrastat_product/models/res_company.py @@ -49,6 +49,15 @@ class ResCompany(models.Model): intrastat_region_id = fields.Many2one( 'intrastat.region', string='Default Intrastat Region') + intrastat_transaction_out_invoice = fields.Many2one( + 'intrastat.transaction', + string='Default Intrastat Transaction For Customer Invoice') + intrastat_transaction_out_refund = fields.Many2one( + 'intrastat.transaction', + string='Default Intrastat Transaction for Customer Refunds') + intrastat_transaction_in_invoice = fields.Many2one( + 'intrastat.transaction', + string='Default Intrastat Transaction For Supplier Invoices') @api.model def _intrastat_arrivals(self): diff --git a/intrastat_product/views/intrastat_product_declaration.xml b/intrastat_product/views/intrastat_product_declaration.xml index c43cb22..d7b9d49 100644 --- a/intrastat_product/views/intrastat_product_declaration.xml +++ b/intrastat_product/views/intrastat_product_declaration.xml @@ -63,6 +63,7 @@ + @@ -76,7 +77,12 @@ - + + diff --git a/intrastat_product/views/res_company.xml b/intrastat_product/views/res_company.xml index b3ef640..48ad34b 100644 --- a/intrastat_product/views/res_company.xml +++ b/intrastat_product/views/res_company.xml @@ -11,7 +11,10 @@ - + + + + diff --git a/product_harmonized_system/__init__.py b/product_harmonized_system/__init__.py index 21ff7c2..cde864b 100644 --- a/product_harmonized_system/__init__.py +++ b/product_harmonized_system/__init__.py @@ -1,3 +1,3 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- from . import models diff --git a/product_harmonized_system/__openerp__.py b/product_harmonized_system/__openerp__.py index 069e1c5..f84de33 100644 --- a/product_harmonized_system/__openerp__.py +++ b/product_harmonized_system/__openerp__.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Copyright (C) 2011-2015 Akretion (http://www.akretion.com) diff --git a/product_harmonized_system/models/__init__.py b/product_harmonized_system/models/__init__.py index 9750aa8..2d9638e 100644 --- a/product_harmonized_system/models/__init__.py +++ b/product_harmonized_system/models/__init__.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- from . import hs_code from . import product_category diff --git a/product_harmonized_system/models/hs_code.py b/product_harmonized_system/models/hs_code.py index 8ebc3cd..8a75896 100644 --- a/product_harmonized_system/models/hs_code.py +++ b/product_harmonized_system/models/hs_code.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Copyright (C) 2011-2015 Akretion (http://www.akretion.com) diff --git a/product_harmonized_system/models/product_category.py b/product_harmonized_system/models/product_category.py index 85e904a..9d99bed 100644 --- a/product_harmonized_system/models/product_category.py +++ b/product_harmonized_system/models/product_category.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Copyright (C) 2011-2015 Akretion (http://www.akretion.com) diff --git a/product_harmonized_system/models/product_template.py b/product_harmonized_system/models/product_template.py index 497f344..6dfaa0e 100644 --- a/product_harmonized_system/models/product_template.py +++ b/product_harmonized_system/models/product_template.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Copyright (C) 2011-2015 Akretion (http://www.akretion.com)