From 4bbb1d7cdacc38206b07f051af9c0803e9e3c68d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 4 Oct 2016 00:41:33 +0200 Subject: [PATCH] [MIG] intrastat_product: Migration to 10.0 intrastat_base: Move company view params to account config page --- intrastat_product/README.rst | 34 ++---- intrastat_product/__manifest__.py | 39 +++++++ intrastat_product/__openerp__.py | 58 ---------- .../data/intrastat_transport_mode.xml | 6 +- intrastat_product/data/intrastat_unit.xml | 6 +- intrastat_product/demo/intrastat_demo.xml | 13 +-- intrastat_product/models/__init__.py | 2 +- .../models/account_config_settings.py | 31 ++++++ intrastat_product/models/account_invoice.py | 105 ++++++------------ intrastat_product/models/hs_code.py | 44 +++----- .../models/intrastat_product_declaration.py | 82 +++++--------- intrastat_product/models/intrastat_region.py | 26 +---- .../models/intrastat_transaction.py | 34 ++---- .../models/intrastat_transport_mode.py | 28 +---- intrastat_product/models/intrastat_unit.py | 37 ++---- intrastat_product/models/res_company.py | 28 +---- intrastat_product/models/sale_order.py | 47 +++----- intrastat_product/models/stock_picking.py | 46 -------- intrastat_product/models/stock_warehouse.py | 29 +---- .../security/intrastat_security.xml | 14 ++- ...ompany.xml => account_config_settings.xml} | 16 ++- intrastat_product/views/account_invoice.xml | 30 ++--- intrastat_product/views/hs_code.xml | 17 ++- .../views/intrastat_product_declaration.xml | 14 +-- intrastat_product/views/intrastat_region.xml | 6 +- .../views/intrastat_transaction.xml | 17 ++- .../views/intrastat_transport_mode.xml | 17 ++- intrastat_product/views/intrastat_unit.xml | 17 ++- intrastat_product/views/sale_order.xml | 20 ++++ intrastat_product/views/stock_picking.xml | 28 ----- intrastat_product/views/stock_warehouse.xml | 10 +- 31 files changed, 297 insertions(+), 604 deletions(-) create mode 100644 intrastat_product/__manifest__.py delete mode 100644 intrastat_product/__openerp__.py create mode 100644 intrastat_product/models/account_config_settings.py delete mode 100644 intrastat_product/models/stock_picking.py rename intrastat_product/views/{res_company.xml => account_config_settings.xml} (71%) create mode 100644 intrastat_product/views/sale_order.xml delete mode 100644 intrastat_product/views/stock_picking.xml diff --git a/intrastat_product/README.rst b/intrastat_product/README.rst index 1ad1510..8e769ea 100644 --- a/intrastat_product/README.rst +++ b/intrastat_product/README.rst @@ -2,9 +2,9 @@ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -======================== -Intrastat Product Module -======================== +================= +Intrastat Product +================= This module contains common objects and fields for the Intrastat Product reporting, such as the *H.S. codes* (if you are not familiar with H.S. codes, read `Wikipedia `) and the *country of origin* on the products. @@ -27,7 +27,6 @@ This module conflicts with the module *report_intrastat* from the official addon If you have already installed the module *report_intrastat*, you should uninstall it before installing this module. - Usage ===== @@ -58,7 +57,7 @@ and adapt the code for the specific needs of your country. Create also new objects inheriting from the Computation and Declaration Line Objects so that you can add methods or customise the methods from the base modules (make a PR when the customization or new method is required for multiple countries). - + Adapt also the parent_id fields of the newly created objects (cf. l10n_be_intrastat_product as example). @@ -69,26 +68,16 @@ and adapt the code for the specific needs of your country. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/91/8.0 - - -Known issues / Roadmap -====================== - -Work is in progress to migrate the existing l10n_fr_intrastat_product module -to this new reporting framework, cf. Alexis de Lattre, Akretion . - + :target: https://runbot.odoo-community.org/runbot/227/10.0 Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. -In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. - +Bugs are tracked on `GitHub Issues +`_. In case +of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed +and welcomed feedback. Credits ======= @@ -99,7 +88,6 @@ Contributors * Alexis de Lattre, Akretion * Luc De Meyer, Noviat - Maintainer ---------- @@ -113,4 +101,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/intrastat_product/__manifest__.py b/intrastat_product/__manifest__.py new file mode 100644 index 0000000..9e3f0a1 --- /dev/null +++ b/intrastat_product/__manifest__.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# © 2011-2017 Akretion (http://www.akretion.com) +# © 2009-2017 Noviat (http://www.noviat.com) +# @author Alexis de Lattre +# @author Luc de Meyer + +{ + 'name': 'Intrastat Product', + 'version': '10.0.1.0.0', + 'category': 'Intrastat', + 'license': 'AGPL-3', + 'summary': 'Base module for Intrastat Product', + 'author': 'Akretion, Noviat, Odoo Community Association (OCA)', + 'depends': [ + 'intrastat_base', + 'product_harmonized_system', + 'sale_stock', + 'purchase', + ], + 'conflicts': ['report_intrastat'], + 'data': [ + 'views/hs_code.xml', + 'views/intrastat_region.xml', + 'views/intrastat_unit.xml', + 'views/intrastat_transaction.xml', + 'views/intrastat_transport_mode.xml', + 'views/intrastat_product_declaration.xml', + 'views/account_config_settings.xml', + 'views/account_invoice.xml', + 'views/sale_order.xml', + 'views/stock_warehouse.xml', + 'security/intrastat_security.xml', + 'security/ir.model.access.csv', + 'data/intrastat_transport_mode.xml', + 'data/intrastat_unit.xml', + ], + 'demo': ['demo/intrastat_demo.xml'], + 'installable': True, +} diff --git a/intrastat_product/__openerp__.py b/intrastat_product/__openerp__.py deleted file mode 100644 index c559fe3..0000000 --- a/intrastat_product/__openerp__.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) -# @author Alexis de Lattre -# @author Luc de Meyer -# -# 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 . -# -############################################################################## - -{ - 'name': 'Intrastat Product', - 'version': '8.0.1.4.1', - 'category': 'Intrastat', - 'license': 'AGPL-3', - 'summary': 'Base module for Intrastat Product', - 'author': 'Akretion, Noviat, Odoo Community Association (OCA)', - 'depends': [ - 'intrastat_base', - 'product_harmonized_system', - 'stock_picking_invoice_link', - 'sale_stock', - 'purchase', - ], - 'conflicts': ['report_intrastat'], - 'data': [ - 'views/hs_code.xml', - 'views/intrastat_region.xml', - 'views/intrastat_unit.xml', - 'views/intrastat_transaction.xml', - 'views/intrastat_transport_mode.xml', - 'views/intrastat_product_declaration.xml', - 'views/res_company.xml', - 'views/account_invoice.xml', - 'views/stock_picking.xml', - 'views/stock_warehouse.xml', - 'security/intrastat_security.xml', - 'security/ir.model.access.csv', - 'data/intrastat_transport_mode.xml', - 'data/intrastat_unit.xml', - ], - 'demo': ['demo/intrastat_demo.xml'], - 'installable': True, -} diff --git a/intrastat_product/data/intrastat_transport_mode.xml b/intrastat_product/data/intrastat_transport_mode.xml index 4b4d245..aa59466 100644 --- a/intrastat_product/data/intrastat_transport_mode.xml +++ b/intrastat_product/data/intrastat_transport_mode.xml @@ -1,6 +1,5 @@ - - + 1 @@ -49,5 +48,4 @@ - - + diff --git a/intrastat_product/data/intrastat_unit.xml b/intrastat_product/data/intrastat_unit.xml index a6fbaff..9f80880 100644 --- a/intrastat_product/data/intrastat_unit.xml +++ b/intrastat_product/data/intrastat_unit.xml @@ -1,6 +1,5 @@ - - + @@ -121,5 +120,4 @@ Terajoule (gross calorific value) - - + diff --git a/intrastat_product/demo/intrastat_demo.xml b/intrastat_product/demo/intrastat_demo.xml index cf9d66d..cbb584d 100644 --- a/intrastat_product/demo/intrastat_demo.xml +++ b/intrastat_product/demo/intrastat_demo.xml @@ -1,13 +1,11 @@ - - - + @@ -24,5 +22,4 @@ - - + diff --git a/intrastat_product/models/__init__.py b/intrastat_product/models/__init__.py index 09f082d..1412035 100644 --- a/intrastat_product/models/__init__.py +++ b/intrastat_product/models/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from . import res_company +from . import account_config_settings from . import account_invoice from . import hs_code from . import intrastat_product_declaration @@ -8,5 +9,4 @@ from . import intrastat_transaction from . import intrastat_transport_mode from . import intrastat_unit from . import sale_order -from . import stock_picking from . import stock_warehouse diff --git a/intrastat_product/models/account_config_settings.py b/intrastat_product/models/account_config_settings.py new file mode 100644 index 0000000..a50f61d --- /dev/null +++ b/intrastat_product/models/account_config_settings.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + + +class AccountConfigSettings(models.TransientModel): + _inherit = 'account.config.settings' + + intrastat_incoterm_id = fields.Many2one( + related='company_id.intrastat_incoterm_id') + intrastat_arrivals = fields.Selection( + related='company_id.intrastat_arrivals') + intrastat_dispatches = fields.Selection( + related='company_id.intrastat_dispatches') + intrastat = fields.Char(related='company_id.intrastat', readonly=True) + intrastat_transport_id = fields.Many2one( + related='company_id.intrastat_transport_id') + intrastat_region_id = fields.Many2one( + related='company_id.intrastat_region_id') + intrastat_transaction_out_invoice = fields.Many2one( + related='company_id.intrastat_transaction_out_invoice') + intrastat_transaction_out_refund = fields.Many2one( + related='company_id.intrastat_transaction_out_refund') + intrastat_transaction_in_invoice = fields.Many2one( + related='company_id.intrastat_transaction_in_invoice') + intrastat_transaction_in_refund = fields.Many2one( + related='company_id.intrastat_transaction_in_refund') + intrastat_accessory_costs = fields.Boolean( + related='company_id.intrastat_accessory_costs') diff --git a/intrastat_product/models/account_invoice.py b/intrastat_product/models/account_invoice.py index 42df8f4..6830d49 100644 --- a/intrastat_product/models/account_invoice.py +++ b/intrastat_product/models/account_invoice.py @@ -1,37 +1,17 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2011-2016 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2016 Noviat (http://www.noviat.com) -# @author Alexis de Lattre -# @author Luc de Meyer -# -# 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 . -# -############################################################################## +# © 2011-2017 Akretion (http://www.akretion.com) +# © 2009-2017 Noviat (http://www.noviat.com) +# @author Alexis de Lattre +# @author Luc de Meyer -from openerp import models, fields, api +from odoo import models, fields, api class AccountInvoice(models.Model): _inherit = 'account.invoice' - incoterm_id = fields.Many2one( - 'stock.incoterms', string='Incoterm', - help="International Commercial Terms are a series of predefined " - "commercial terms used in international transactions.") + # in v10, the sale_stock module defines an incoterms_id + # Odoo v8 name: incoterm_id intrastat_transaction_id = fields.Many2one( 'intrastat.transaction', string='Intrastat Transaction Type', default=lambda self: self._default_intrastat_transaction_id(), @@ -42,33 +22,38 @@ class AccountInvoice(models.Model): ondelete='restrict') 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') + compute='_compute_intrastat_country', + store=True, + help="Destination country for dispatches. Origin country for " + "arrivals.") intrastat_country = fields.Boolean( compute='_compute_intrastat_country', store=True, string='Intrastat Country', readonly=True) + src_dest_region_id = fields.Many2one( + 'intrastat.region', string='Origin/Destination Region', + default=lambda self: self._default_src_dest_region_id(), + help="Origin region for dispatches, destination region for " + "arrivals. This field is used for the Intrastat Declaration.", + ondelete='restrict') intrastat = fields.Char( string='Intrastat Declaration', related='company_id.intrastat', readonly=True) @api.multi - @api.depends('src_dest_country_id', 'partner_id.country_id') + @api.depends('partner_shipping_id.country_id', 'partner_id.country_id') def _compute_intrastat_country(self): for inv in self: - country = inv.src_dest_country_id \ + country = inv.partner_shipping_id.country_id\ or inv.partner_id.country_id + if not country: + country = inv.company_id.country_id + inv.src_dest_country_id = country.id inv.intrastat_country = country.intrastat @api.model def _default_intrastat_transaction_id(self): - company = self.env['res.company'] - company_id = company._company_default_get('account.invoice') - company = company.browse(company_id) + rco = self.env['res.company'] + company = rco._company_default_get('account.invoice') inv_type = self._context.get('type') if inv_type == 'out_invoice': return company.intrastat_transaction_out_invoice @@ -83,24 +68,10 @@ class AccountInvoice(models.Model): @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) + rco = self.env['res.company'] + company = rco._company_default_get('account.invoice') return company.intrastat_region_id - @api.multi - def onchange_partner_id( - self, type, partner_id, date_invoice=False, - payment_term=False, partner_bank_id=False, company_id=False): - res = super(AccountInvoice, self).onchange_partner_id( - type, partner_id, date_invoice=date_invoice, - payment_term=payment_term, partner_bank_id=partner_bank_id, - company_id=company_id) - if partner_id: - partner = self.env['res.partner'].browse(partner_id) - res['value']['src_dest_country_id'] = partner.country_id.id - return res - class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line' @@ -108,22 +79,8 @@ class AccountInvoiceLine(models.Model): hs_code_id = fields.Many2one( 'hs.code', string='Intrastat Code', ondelete='restrict') - @api.multi - def product_id_change( - self, product, uom_id, qty=0, name='', type='out_invoice', - partner_id=False, fposition_id=False, price_unit=False, - currency_id=False, company_id=None): - res = super(AccountInvoiceLine, self).product_id_change( - product, uom_id, qty=qty, name=name, type=type, - partner_id=partner_id, fposition_id=fposition_id, - price_unit=price_unit, currency_id=currency_id, - company_id=company_id) - - if product: - product = self.env['product.product'].browse(product) - hs_code = product.product_tmpl_id.get_hs_code_recursively() - if hs_code: - res['value']['hs_code_id'] = hs_code.id - else: - res['value']['hs_code_id'] = False - return res + @api.onchange('product_id') + def intrastat_product_id_change(self): + if self.product_id: + hs_code = self.product_id.product_tmpl_id.get_hs_code_recursively() + self.hs_code_id = hs_code and hs_code.id or False diff --git a/intrastat_product/models/hs_code.py b/intrastat_product/models/hs_code.py index a4ae30b..f97652c 100644 --- a/intrastat_product/models/hs_code.py +++ b/intrastat_product/models/hs_code.py @@ -1,29 +1,11 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) -# @author Alexis de Lattre -# @author Luc de Meyer -# -# 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 . -# -############################################################################## +# © 2011-2017 Akretion (http://www.akretion.com) +# © 2009-2017 Noviat (http://www.noviat.com) +# @author Alexis de Lattre +# @author Luc de Meyer -from openerp import models, fields, api, _ -from openerp.exceptions import ValidationError +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError class HSCode(models.Model): @@ -36,13 +18,13 @@ class HSCode(models.Model): def _hs_code(self): if self.company_id.country_id.intrastat: if not self.local_code.isdigit(): - raise ValidationError( - _("Intrastat Codes should only contain digits. " - "This is not the case for code '%s'.") + raise ValidationError(_( + "Intrastat Codes should only contain digits. " + "This is not the case for code '%s'.") % self.local_code) if len(self.local_code) != 8: - raise ValidationError( - _("Intrastat Codes should " - "contain 8 digits. This is not the case for " - "Intrastat Code '%s' which has %d digits.") + raise ValidationError(_( + "Intrastat Codes should " + "contain 8 digits. This is not the case for " + "Intrastat Code '%s' which has %d digits.") % (self.local_code, len(self.local_code))) diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py index 6c5e099..d917e37 100644 --- a/intrastat_product/models/intrastat_product_declaration.py +++ b/intrastat_product/models/intrastat_product_declaration.py @@ -1,31 +1,12 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) -# @author Alexis de Lattre -# @author Luc de Meyer -# -# 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 . -# -############################################################################## +# © 2011-2017 Akretion (http://www.akretion.com) +# © 2009-2017 Noviat (http://www.noviat.com) +# @author Alexis de Lattre +# @author Luc de Meyer -from openerp import models, fields, api, _ -from openerp.exceptions import RedirectWarning, ValidationError -from openerp.exceptions import Warning as UserError -import openerp.addons.decimal_precision as dp +from odoo import models, fields, api, _ +from odoo.exceptions import RedirectWarning, ValidationError, UserError +import odoo.addons.decimal_precision as dp from datetime import datetime, date from dateutil.relativedelta import relativedelta import logging @@ -38,12 +19,6 @@ class IntrastatProductDeclaration(models.Model): _rec_name = 'year_month' _inherit = ['mail.thread', 'intrastat.common'] _order = 'year_month desc, type, revision' - _track = { - 'state': { - 'intrastat_product.declaration_done': - lambda self, cr, uid, obj, ctx=None: obj['state'] == 'done', - } - } @api.model def _get_type(self): @@ -262,7 +237,7 @@ class IntrastatProductDeclaration(models.Model): product = inv_line.product_id invoice = inv_line.invoice_id intrastat_unit_id = hs_code.intrastat_unit_id - source_uom = inv_line.uos_id + source_uom = inv_line.uom_id 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') @@ -294,8 +269,8 @@ class IntrastatProductDeclaration(models.Model): self._note += note return weight, suppl_unit_qty if target_uom.category_id == source_uom.category_id: - suppl_unit_qty = self.env['product.uom']._compute_qty_obj( - source_uom, line_qty, target_uom) + suppl_unit_qty = source_uom._compute_quantity( + line_qty, target_uom) else: note = "\n" + _( "Conversion from unit of measure '%s' to '%s' " @@ -311,10 +286,9 @@ class IntrastatProductDeclaration(models.Model): if source_uom == kg_uom: weight = line_qty elif source_uom.category_id == weight_uom_categ: - weight = self.env['product.uom']._compute_qty_obj( - source_uom, line_qty, kg_uom) + weight = source_uom._compute_quantity(line_qty, kg_uom) elif source_uom.category_id == pce_uom_categ: - if not product.weight_net: + if not product.weight: # re-create weight_net ? note = "\n" + _( "Missing net weight on product %s." ) % product.name_get()[0][1] @@ -324,13 +298,13 @@ class IntrastatProductDeclaration(models.Model): self._note += note return weight, suppl_unit_qty if source_uom == pce_uom: - weight = product.weight_net * line_qty + weight = product.weight * line_qty # product.weight_net else: # Here, I suppose that, on the product, the # weight is per PCE and not per uom_id - weight = product.weight_net * \ - self.env['product.uom']._compute_qty_obj( - source_uom, line_qty, pce_uom) + # product.weight_net + weight = product.weight * \ + source_uom._compute_quantity(line_qty, pce_uom) else: note = "\n" + _( "Conversion from unit of measure '%s' to 'Kg' " @@ -374,24 +348,18 @@ class IntrastatProductDeclaration(models.Model): """ region = False 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: - region = inv_line.move_line_ids[0].location_dest_id.\ - get_intrastat_region() - elif inv_type in ('in_invoice', 'in_refund'): + if 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'): + if po_lines[0].move_ids: + region = po_lines[0].move_ids[0].location_id\ + .get_intrastat_region() + elif inv_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 + so = so_lines[0].order_id region = so.warehouse_id.region_id if not region: if self.company_id.intrastat_region_id: @@ -410,7 +378,7 @@ class IntrastatProductDeclaration(models.Model): return transport def _get_incoterm(self, inv_line): - incoterm = inv_line.invoice_id.incoterm_id \ + incoterm = inv_line.invoice_id.incoterms_id \ or self.company_id.intrastat_incoterm_id if not incoterm: msg = _( @@ -499,7 +467,7 @@ class IntrastatProductDeclaration(models.Model): total_inv_accessory_costs_cc = 0.0 # in company currency total_inv_product_cc = 0.0 # in company currency total_inv_weight = 0.0 - for inv_line in invoice.invoice_line: + for inv_line in invoice.invoice_line_ids: if ( accessory_costs and @@ -530,7 +498,7 @@ class IntrastatProductDeclaration(models.Model): if any([ tax.exclude_from_intrastat_if_present - for tax in inv_line.invoice_line_tax_id]): + for tax in inv_line.invoice_line_tax_ids]): _logger.info( 'Skipping invoice line %s ' 'qty %s of invoice %s. Reason: ' diff --git a/intrastat_product/models/intrastat_region.py b/intrastat_product/models/intrastat_region.py index 9dddfdf..b385255 100644 --- a/intrastat_product/models/intrastat_region.py +++ b/intrastat_product/models/intrastat_region.py @@ -1,26 +1,8 @@ # -*- coding: 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 . -# -############################################################################## +# © 2009-2017 Noviat nv/sa (www.noviat.com). +# @author Luc de Meyer -from openerp import models, fields +from odoo import models, fields class IntrastatRegion(models.Model): @@ -39,5 +21,5 @@ class IntrastatRegion(models.Model): _sql_constraints = [ ('intrastat_region_code_unique', - 'UNIQUE(code, country_id)', + 'UNIQUE(code, country_id)', # TODO add company_id ? 'Code must be unique.')] diff --git a/intrastat_product/models/intrastat_transaction.py b/intrastat_product/models/intrastat_transaction.py index ea9002e..49fb34a 100644 --- a/intrastat_product/models/intrastat_transaction.py +++ b/intrastat_product/models/intrastat_transaction.py @@ -1,28 +1,10 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) -# @author Alexis de Lattre -# @author Luc de Meyer -# -# 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 . -# -############################################################################## +# © 2011-2017 Akretion (http://www.akretion.com) +# © 2009-2017 Noviat (http://www.noviat.com) +# @author Alexis de Lattre +# @author Luc de Meyer -from openerp import models, fields, api +from odoo import models, fields, api class IntrastatTransaction(models.Model): @@ -34,8 +16,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, - store=True) + compute='_compute_display_name_field', 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( @@ -43,7 +25,7 @@ class IntrastatTransaction(models.Model): @api.multi @api.depends('code', 'description') - def _compute_display_name(self): + def _compute_display_name_field(self): for this in self: display_name = this.code if this.description: diff --git a/intrastat_product/models/intrastat_transport_mode.py b/intrastat_product/models/intrastat_transport_mode.py index 484c84d..6d7fb09 100644 --- a/intrastat_product/models/intrastat_transport_mode.py +++ b/intrastat_product/models/intrastat_transport_mode.py @@ -1,28 +1,10 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) -# @author Alexis de Lattre -# @author Luc de Meyer -# -# 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 . -# -############################################################################## +# © 2011-2017 Akretion (http://www.akretion.com) +# © 2009-2017 Noviat (http://www.noviat.com) +# @author Alexis de Lattre +# @author Luc de Meyer -from openerp import models, fields, api +from odoo import models, fields, api class IntrastatTransportMode(models.Model): diff --git a/intrastat_product/models/intrastat_unit.py b/intrastat_product/models/intrastat_unit.py index 7122610..d02d538 100644 --- a/intrastat_product/models/intrastat_unit.py +++ b/intrastat_product/models/intrastat_unit.py @@ -1,41 +1,20 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) -# @author Alexis de Lattre -# @author Luc de Meyer -# -# 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 . -# -############################################################################## +# © 2011-2017 Akretion (http://www.akretion.com) +# © 2009-2017 Noviat (http://www.noviat.com) +# @author Alexis de Lattre +# @author Luc de Meyer -from openerp import models, fields +from odoo import models, fields class IntrastatUnit(models.Model): _name = 'intrastat.unit' _description = 'Intrastat Supplementary Units' - name = fields.Char( - string='Name', required=True) - description = fields.Char( - string='Description', required=True) + name = fields.Char(string='Name', required=True) + description = fields.Char(string='Description', required=True) uom_id = fields.Many2one( 'product.uom', string='Regular UoM', help="Select the regular Unit of Measure of Odoo that corresponds " "to this Intrastat Supplementary Unit.") - active = fields.Boolean( - string='Active', default=True) + active = fields.Boolean(string='Active', default=True) diff --git a/intrastat_product/models/res_company.py b/intrastat_product/models/res_company.py index 2995486..46618e6 100644 --- a/intrastat_product/models/res_company.py +++ b/intrastat_product/models/res_company.py @@ -1,28 +1,10 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) -# @author Alexis de Lattre -# @author Luc de Meyer -# -# 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 . -# -############################################################################## +# © 2011-2017 Akretion (http://www.akretion.com) +# © 2009-2017 Noviat (http://www.noviat.com) +# @author Alexis de Lattre +# @author Luc de Meyer -from openerp import models, fields, api +from odoo import models, fields, api class ResCompany(models.Model): diff --git a/intrastat_product/models/sale_order.py b/intrastat_product/models/sale_order.py index 0818460..ee360da 100644 --- a/intrastat_product/models/sale_order.py +++ b/intrastat_product/models/sale_order.py @@ -1,37 +1,26 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2010-2015 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 . -# -############################################################################## +# © 2010-2017 Akretion (http://www.akretion.com) +# @author Alexis de Lattre -from openerp import models, api +from odoo import models, fields, api class SaleOrder(models.Model): _inherit = "sale.order" - @api.model - def _prepare_invoice(self, order, lines): + intrastat_transport_id = fields.Many2one( + 'intrastat.transport_mode', string='Transport Mode', + help="This information is used in Intrastat reports") + intrastat = fields.Selection( + string='Intrastat Declaration', + related='company_id.intrastat_dispatches', readonly=True) + + @api.multi + def _prepare_invoice(self): '''Copy destination country to invoice''' - invoice_vals = super(SaleOrder, self)._prepare_invoice( - order, lines) - invoice_vals['src_dest_country_id'] = \ - order.partner_shipping_id.country_id.id or False - invoice_vals['incoterm_id'] = order.incoterm.id or False - return invoice_vals + vals = super(SaleOrder, self)._prepare_invoice() + if self.intrastat_transport_id: + vals['intrastat_transport_id'] = self.intrastat_transport_id.id + if self.warehouse_id.region_id: + vals['src_dest_region_id'] = self.warehouse_id.region_id.id + return vals diff --git a/intrastat_product/models/stock_picking.py b/intrastat_product/models/stock_picking.py deleted file mode 100644 index f46705f..0000000 --- a/intrastat_product/models/stock_picking.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Intrastat Product module for Odoo -# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) -# @author Alexis de Lattre -# @author Luc de Meyer -# -# 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, api - - -class StockPicking(models.Model): - _inherit = "stock.picking" - - intrastat_transport_id = fields.Many2one( - 'intrastat.transport_mode', string='Transport Mode', - help="This information is used in Intrastat reports") - intrastat = fields.Char(related='company_id.intrastat') - - @api.model - def _create_invoice_from_picking(self, picking, vals): - """ 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) diff --git a/intrastat_product/models/stock_warehouse.py b/intrastat_product/models/stock_warehouse.py index 90509b8..23bbb93 100644 --- a/intrastat_product/models/stock_warehouse.py +++ b/intrastat_product/models/stock_warehouse.py @@ -1,34 +1,15 @@ # -*- coding: 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 . -# -############################################################################## +# © 2009-2017 Noviat nv/sa (www.noviat.com). +# @author Alexis de Lattre +# @author Luc de Meyer -from openerp import models, fields, api +from odoo import models, fields, api class StockWarehouse(models.Model): _inherit = 'stock.warehouse' - region_id = fields.Many2one( - 'intrastat.region', - string='Intrastat region') + region_id = fields.Many2one('intrastat.region', string='Intrastat Region') class StockLocation(models.Model): diff --git a/intrastat_product/security/intrastat_security.xml b/intrastat_product/security/intrastat_security.xml index e483225..edae4dd 100644 --- a/intrastat_product/security/intrastat_security.xml +++ b/intrastat_product/security/intrastat_security.xml @@ -1,6 +1,5 @@ - - + Intrastat Transaction Company rule @@ -13,6 +12,11 @@ ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] - - - + + + Intrastat Product Declaration Company rule + + ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] + + + diff --git a/intrastat_product/views/res_company.xml b/intrastat_product/views/account_config_settings.xml similarity index 71% rename from intrastat_product/views/res_company.xml rename to intrastat_product/views/account_config_settings.xml index 2d61383..9c684fa 100644 --- a/intrastat_product/views/res_company.xml +++ b/intrastat_product/views/account_config_settings.xml @@ -1,13 +1,12 @@ - - + - - intrastat.company.form - res.company - + + intrastat.account.config.settings.form + account.config.settings + - + @@ -24,5 +23,4 @@ - - + diff --git a/intrastat_product/views/account_invoice.xml b/intrastat_product/views/account_invoice.xml index 26332cd..fda90a4 100644 --- a/intrastat_product/views/account_invoice.xml +++ b/intrastat_product/views/account_invoice.xml @@ -1,17 +1,12 @@ - - + intrastat.invoice.form account.invoice - - - - + - - + + @@ -31,24 +26,23 @@ account.invoice - - + - + - - + + - - + + - - + diff --git a/intrastat_product/views/hs_code.xml b/intrastat_product/views/hs_code.xml index f6e54f2..a48d6c1 100644 --- a/intrastat_product/views/hs_code.xml +++ b/intrastat_product/views/hs_code.xml @@ -1,15 +1,13 @@ - - - + - - + diff --git a/intrastat_product/views/intrastat_product_declaration.xml b/intrastat_product/views/intrastat_product_declaration.xml index 7ddc9bd..a86abcc 100644 --- a/intrastat_product/views/intrastat_product_declaration.xml +++ b/intrastat_product/views/intrastat_product_declaration.xml @@ -1,6 +1,5 @@ - - + intrastat.product.declaration.form @@ -75,14 +74,6 @@ - - - Intrastat Product Declaration Validated - intrastat.product.declaration - - Intrastat Product Declaration Validated - - intrastat.product.declaration.tree intrastat.product.declaration @@ -259,5 +250,4 @@ - - + diff --git a/intrastat_product/views/intrastat_region.xml b/intrastat_product/views/intrastat_region.xml index e4580df..648209f 100644 --- a/intrastat_product/views/intrastat_region.xml +++ b/intrastat_product/views/intrastat_region.xml @@ -1,6 +1,5 @@ - - + intrastat.region.form @@ -42,5 +41,4 @@ action="intrastat_region_action" parent="intrastat_base.menu_intrastat_config_root"/> - - + diff --git a/intrastat_product/views/intrastat_transaction.xml b/intrastat_product/views/intrastat_transaction.xml index 7f80b6b..c1c319d 100644 --- a/intrastat_product/views/intrastat_transaction.xml +++ b/intrastat_product/views/intrastat_transaction.xml @@ -1,15 +1,13 @@ - - - + @@ -64,5 +62,4 @@ parent="intrastat_base.menu_intrastat_config_root" sequence="20"/> - - + diff --git a/intrastat_product/views/intrastat_transport_mode.xml b/intrastat_product/views/intrastat_transport_mode.xml index 94d51be..6398a82 100644 --- a/intrastat_product/views/intrastat_transport_mode.xml +++ b/intrastat_product/views/intrastat_transport_mode.xml @@ -1,15 +1,13 @@ - - - + @@ -60,5 +58,4 @@ parent="intrastat_base.menu_intrastat_config_root" sequence="30"/> - - + diff --git a/intrastat_product/views/intrastat_unit.xml b/intrastat_product/views/intrastat_unit.xml index 2bfa2da..acc6a92 100644 --- a/intrastat_product/views/intrastat_unit.xml +++ b/intrastat_product/views/intrastat_unit.xml @@ -1,15 +1,13 @@ - - - + @@ -66,5 +64,4 @@ parent="intrastat_base.menu_intrastat_config_root" sequence="40"/> - - + diff --git a/intrastat_product/views/sale_order.xml b/intrastat_product/views/sale_order.xml new file mode 100644 index 0000000..4e3a5cd --- /dev/null +++ b/intrastat_product/views/sale_order.xml @@ -0,0 +1,20 @@ + + + + + + intrastat.sale.order.form + sale.order + + + + + + + + + + + diff --git a/intrastat_product/views/stock_picking.xml b/intrastat_product/views/stock_picking.xml deleted file mode 100644 index 80ce61e..0000000 --- a/intrastat_product/views/stock_picking.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - intrastat.product.picking.form - stock.picking - - - - - - - - - - - diff --git a/intrastat_product/views/stock_warehouse.xml b/intrastat_product/views/stock_warehouse.xml index 163cf0f..f9b1825 100644 --- a/intrastat_product/views/stock_warehouse.xml +++ b/intrastat_product/views/stock_warehouse.xml @@ -1,17 +1,15 @@ - - + intrastat.stock.warehouse.form stock.warehouse - + - + - - +