diff --git a/intrastat_product/README.rst b/intrastat_product/README.rst new file mode 100644 index 0000000..455c358 --- /dev/null +++ b/intrastat_product/README.rst @@ -0,0 +1,41 @@ +Intrastat Product Module +======================== + +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. + +It should be used in combination with country-specific Intrastat Product reporting modules +such as: + +- *l10n_fr_intrastat_product*: + the module for the *Déclaration d'Echange de Biens* (DEB) for France + +These country-specific modules can be found in the OCA localization for those countries. + +Installation +============ + +WARNING: +This module conflicts with the module *report_intrastat* from the official addons. +If you have already installed the module *report_intrastat*, +you should uninstall it before installing this module. + +Credits +======= + +Contributors +------------ + +* Alexis de Lattre, Akretion + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +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. diff --git a/intrastat_product/__init__.py b/intrastat_product/__init__.py index 64a3431..063edb0 100644 --- a/intrastat_product/__init__.py +++ b/intrastat_product/__init__.py @@ -1,23 +1,7 @@ # -*- encoding: utf-8 -*- -############################################################################## -# -# Intrastat product module for OpenERP -# 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 . -# -############################################################################## +from . import res_company from . import intrastat +from . import intrastat_declaration +from . import stock +from . import account_invoice diff --git a/intrastat_product/__openerp__.py b/intrastat_product/__openerp__.py index 6224d37..7a593e8 100644 --- a/intrastat_product/__openerp__.py +++ b/intrastat_product/__openerp__.py @@ -3,7 +3,9 @@ # # Intrastat Product module for Odoo # Copyright (C) 2011-2015 Akretion (http://www.akretion.com) +# Copyright (C) 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 @@ -22,23 +24,27 @@ { 'name': 'Intrastat Product', - 'version': '1.1', - 'category': 'Localisation/Report Intrastat', + 'version': '1.3', + 'category': 'Intrastat', 'license': 'AGPL-3', 'summary': 'Base module for Intrastat Product', - 'description': """ -This module contains the common objects for the Intrastat Product. -This module is country-independant. - -This module has been written by Alexis de Lattre from Akretion - - """, - 'author': 'Akretion', - 'website': 'http://www.akretion.com', - 'depends': ['intrastat_base'], + 'author': 'Akretion, Noviat, Odoo Community Association (OCA)', + 'depends': [ + 'intrastat_base', + 'product_harmonized_system', + 'stock', + ], + 'conflicts': ['report_intrastat'], 'data': [ 'intrastat_view.xml', + 'intrastat_declaration_view.xml', + 'res_company_view.xml', + 'account_invoice_view.xml', + 'stock_view.xml', + 'security/intrastat_security.xml', 'security/ir.model.access.csv', + 'data/intrastat_transport_mode.xml', + 'data/intrastat_unit.xml', ], 'demo': ['intrastat_demo.xml'], 'installable': True, diff --git a/intrastat_product/account_invoice.py b/intrastat_product/account_invoice.py new file mode 100644 index 0000000..3179012 --- /dev/null +++ b/intrastat_product/account_invoice.py @@ -0,0 +1,88 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2012-2015 Noviat nv/sa (www.noviat.com) +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Luc de Meyer +# @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 . +# +############################################################################## + +from openerp import models, fields, api + + +class AccountInvoice(models.Model): + _inherit = 'account.invoice' + + @api.model + def _default_intrastat_transaction(self): + """ placeholder for localisation modules """ + return self.env['intrastat.transaction'].browse([]) + + intrastat_transaction_id = fields.Many2one( + 'intrastat.transaction', string='Intrastat Transaction Type', + default=_default_intrastat_transaction, ondelete='restrict', + help="Intrastat nature of transaction") + intrastat_transport_id = fields.Many2one( + 'intrastat.transport_mode', string='Intrastat Transport Mode', + ondelete='restrict') + src_dest_country_id = fields.Many2one( + 'res.country', string='Origin/Destination Country', + ondelete='restrict') + intrastat_country = fields.Boolean( + related='src_dest_country_id.intrastat', + store=True, string='Intrastat Country', readonly=True) + intrastat = fields.Char( + string='Intrastat Declaration', + related='company_id.intrastat', store=True, readonly=True) + + @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' + + 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.get_hs_code_recursively() + if hs_code: + res['value']['hs_code_id'] = hs_code.id + return res diff --git a/intrastat_product/account_invoice_view.xml b/intrastat_product/account_invoice_view.xml new file mode 100644 index 0000000..cccb557 --- /dev/null +++ b/intrastat_product/account_invoice_view.xml @@ -0,0 +1,44 @@ + + + + + + intrastat.invoice.form + account.invoice + + + + + + + + + + + + + + + + intrastat.invoice.supplier.form + account.invoice + + + + + + + + + + + + + + + + diff --git a/intrastat_product/data/intrastat_transport_mode.xml b/intrastat_product/data/intrastat_transport_mode.xml new file mode 100644 index 0000000..4b4d245 --- /dev/null +++ b/intrastat_product/data/intrastat_transport_mode.xml @@ -0,0 +1,53 @@ + + + + + + 1 + Sea + Sea Transport (including wagons, motor vehicles, trailers, semi-trailers and lighters on board of a ship) + + + 2 + Rail + Railway transport (including lorries on railway wagons) + + + 3 + Road + Road Transport + + + 4 + Air + Air Transport + + + 5 + Post + Postal consignments + + + 7 + Fixed installations + Fixed transport installations (e.g. pipelines, high-tension cables) + + + + 8 + Inland waterway + Inland waterway transport + + + 9 + Own propulsion + Own propulsion (imported or exported means of transport crossing the border under their own power, e.g. aircraft, lorries, boats, etc.) + + + + + + + + + diff --git a/intrastat_product/data/intrastat_unit.xml b/intrastat_product/data/intrastat_unit.xml new file mode 100644 index 0000000..a6fbaff --- /dev/null +++ b/intrastat_product/data/intrastat_unit.xml @@ -0,0 +1,125 @@ + + + + + + + + c/k + Carats - 1 metric carat = 2 × 10exp(–4) kg + + + ce/el + Number of cells + + + ct/l + Carrying capacity in tonnes + + + g + Gram + + + + gi F/S + Gram of fissile isotopes + + + kg H2O2 + Kilogram of hydrogen peroxide + + + kg K2O + Kilogram of potassium oxide + + + kg KOH + Kilogram of potassium hydroxide (caustic potash) + + + kg met.am. + Kilogram of methylamines + + + kg N + Kilogram of nitrogen + + + kg NaOH + Kilogram of sodium hydroxide (caustic soda) + + + kg/net eda + Kilogram drained net weight + + + kg P2O5 + Kilogram of diphosphorus pentaoxide + + + kg 90 pct sdt + Kilogram of substance 90 % dry + + + kg U + Kilogram of uranium + + + 1000 kWh + Thousand kilowatt hours + + + l + Litre + + + + 1000 l + Thousand litres + + + l alc. 100 pct + Litre pure (100 %) alcohol + + + m + Metre + + + + m2 + Square metre + + + m3 + Cubic metre + + + 1000 m3 + Thousand cubic metres + + + pa + Number of pairs + + + items + Number of items + + + + 100 items + Hundred items + + + 1000 items + Thousand items + + + TJ + Terajoule (gross calorific value) + + + + diff --git a/intrastat_product/i18n/intrastat_product.pot b/intrastat_product/i18n/intrastat_product.pot index 15505ac..6b1f00f 100644 --- a/intrastat_product/i18n/intrastat_product.pot +++ b/intrastat_product/i18n/intrastat_product.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 8.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-11-28 22:48+0000\n" -"PO-Revision-Date: 2014-11-28 22:48+0000\n" +"POT-Creation-Date: 2015-05-27 18:43+0000\n" +"PO-Revision-Date: 2015-05-27 18:43+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -15,6 +15,11 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: intrastat_product +#: field:report.intrastat.code,active:0 +msgid "Active" +msgstr "" + #. module: intrastat_product #: help:product.category,intrastat_id:0 msgid "Code from the Harmonised System. If this code is not set on the product itself, it will be read here, on the related product category." @@ -25,6 +30,21 @@ msgstr "" msgid "Code from the Harmonised System. Nomenclature is available from the World Customs Organisation, see http://www.wcoomd.org/. Some countries have made their own extensions to this nomenclature." msgstr "" +#. module: intrastat_product +#: help:report.intrastat.code,intrastat_code:0 +msgid "Code used for the Intrastat declaration. Must be part of the 'Combined Nomenclature' (CN), cf http://en.wikipedia.org/wiki/Combined_NomenclatureMust have 8 digits with sometimes a 9th digit." +msgstr "" + +#. module: intrastat_product +#: field:product.template,origin_country_id:0 +msgid "Country of Origin" +msgstr "" + +#. module: intrastat_product +#: help:product.template,origin_country_id:0 +msgid "Country of origin of the product i.e. product 'made in ____'. If you have different countries of origin depending on the supplier from which you purchased the product, leave this field empty and use the equivalent field on the 'product supplier info' form." +msgstr "" + #. module: intrastat_product #: field:report.intrastat.code,create_uid:0 msgid "Created by" @@ -40,6 +60,16 @@ msgstr "" msgid "Description" msgstr "" +#. module: intrastat_product +#: field:report.intrastat.code,display_name:0 +msgid "Display Name" +msgstr "" + +#. module: intrastat_product +#: field:report.intrastat.code,intrastat_code:0 +msgid "European Intrastat Code" +msgstr "" + #. module: intrastat_product #: help:report.intrastat.code,name:0 msgid "Full length Harmonized System code (digits only). Full list is available from the World Customs Organisation, see http://www.wcoomd.org" @@ -56,7 +86,7 @@ msgid "H.S. code" msgstr "" #. module: intrastat_product -#: code:addons/intrastat_product/intrastat.py:56 +#: code:addons/intrastat_product/intrastat.py:73 #, python-format msgid "H.S. codes should only contain digits. It is not the case of H.S. code '%s'." msgstr "" @@ -95,6 +125,12 @@ msgstr "" msgid "Last Updated on" msgstr "" +#. module: intrastat_product +#: view:report.intrastat.code:intrastat_product.product_intrastat_code_form +#: field:report.intrastat.code,product_categ_ids:0 +msgid "Product Categories" +msgstr "" + #. module: intrastat_product #: model:ir.model,name:intrastat_product.model_product_category msgid "Product Category" @@ -105,18 +141,46 @@ msgstr "" msgid "Product Template" msgstr "" +#. module: intrastat_product +#: view:report.intrastat.code:intrastat_product.product_intrastat_code_form +#: field:report.intrastat.code,product_tmpl_ids:0 +msgid "Products" +msgstr "" + #. module: intrastat_product #: view:report.intrastat.code:intrastat_product.product_intrastat_code_search msgid "Search Intrastat Codes" msgstr "" +#. module: intrastat_product +#: help:report.intrastat.code,intrastat_uom_id:0 +msgid "Select the unit of measure if one is required for this particular Intrastat Code (other than the weight in Kg). If no particular unit of measure is required, leave empty." +msgstr "" + #. module: intrastat_product #: help:report.intrastat.code,description:0 msgid "Short text description of the H.S. category" msgstr "" +#. module: intrastat_product +#: code:addons/intrastat_product/intrastat.py:82 +#, python-format +msgid "The field Intrastat Code should contain 8 or 9 digits. It is not the case of Intrastat Code '%s'." +msgstr "" + +#. module: intrastat_product +#: code:addons/intrastat_product/intrastat.py:77 +#, python-format +msgid "The field Intrastat Code should only contain digits. It is not the case of Intrastat Code '%s'." +msgstr "" + #. module: intrastat_product #: sql_constraint:report.intrastat.code:0 msgid "This H.S. code already exists in Odoo !" msgstr "" +#. module: intrastat_product +#: field:report.intrastat.code,intrastat_uom_id:0 +msgid "UoM for Intrastat Report" +msgstr "" + diff --git a/intrastat_product/intrastat.py b/intrastat_product/intrastat.py index 5242514..b87953a 100644 --- a/intrastat_product/intrastat.py +++ b/intrastat_product/intrastat.py @@ -1,10 +1,11 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# Intrastat Product module for OpenERP -# Copyright (C) 2004-2009 Tiny SPRL (http://tiny.be) -# Copyright (C) 2010-2014 Akretion (http://www.akretion.com) +# Intrastat Product module for Odoo +# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) +# Copyright (C) 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 @@ -25,108 +26,97 @@ from openerp import models, fields, api, _ from openerp.exceptions import ValidationError -class ReportIntrastatCode(models.Model): - _name = "report.intrastat.code" - _description = "H.S. Code" - _order = "name" - _rec_name = "display_name" - - @api.one - @api.depends('name', 'description') - def _compute_display_name(self): - display_name = self.name or '' - if self.description: - display_name += ' ' + self.description - self.display_name = display_name +class IntrastatUnit(models.Model): + _name = 'intrastat.unit' + _description = 'Intrastat Supplementary Units' name = fields.Char( - string='H.S. code', - help="Full length Harmonized System code (digits only). Full list is " - "available from the World Customs Organisation, see " - "http://www.wcoomd.org") + string='Name', required=True) description = fields.Char( - 'Description', help="Short text description of the H.S. category") - display_name = fields.Char( - compute='_compute_display_name', string="Display Name", readonly=True, - store=True) - intrastat_code = fields.Char( - string='European Intrastat Code', size=9, required=True, - help="Code used for the Intrastat declaration. Must be part " - "of the 'Combined Nomenclature' (CN), cf " - "http://en.wikipedia.org/wiki/Combined_Nomenclature" - "Must have 8 digits with sometimes a 9th digit.") - intrastat_uom_id = fields.Many2one( - 'product.uom', string='UoM for Intrastat Report', - help="Select the unit of measure if one is required for " - "this particular Intrastat Code (other than the weight in Kg). " - "If no particular unit of measure is required, leave empty.") - active = fields.Boolean(default=True) - product_categ_ids = fields.One2many( - 'product.category', 'intrastat_id', string='Product Categories') - product_tmpl_ids = fields.One2many( - 'product.template', 'intrastat_id', string='Products') + 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) - @api.constrains('name', 'intrastat_code') + +class HSCode(models.Model): + _inherit = "hs.code" + + intrastat_unit_id = fields.Many2one( + 'intrastat.unit', string='Intrastat Supplementary Unit') + + @api.constrains('local_code') def _hs_code(self): - if self.name and not self.name.isdigit(): - raise ValidationError( - _("H.S. codes should only contain digits. It is not the case " - "of H.S. code '%s'.") % self.name) - if self.intrastat_code and not self.intrastat_code.isdigit(): - raise ValidationError( - _("The field Intrastat Code should only contain digits. " - "It is not the case of Intrastat Code '%s'.") - % self.intrastat_code) - if self.intrastat_code and len(self.intrastat_code) not in (8, 9): - raise ValidationError( - _("The field Intrastat Code should " - "contain 8 or 9 digits. It is not the case of " - "Intrastat Code '%s'.") - % self.intrastat_code) + 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'.") + % 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.") + % (self.local_code, len(self.local_code))) + + +class IntrastatTransaction(models.Model): + _name = 'intrastat.transaction' + _description = "Intrastat Transaction" + _order = 'code' + _rec_name = 'display_name' + + @api.one + @api.depends('code', 'description') + def _compute_display_name(self): + display_name = self.code + if self.description: + display_name += ' ' + self.description + self.display_name = len(display_name) > 55 \ + and display_name[:55] + '...' \ + or display_name + + 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) + company_id = fields.Many2one( + 'res.company', string='Company', + default=lambda self: self.env['res.company']._company_default_get( + 'intrastat.transaction')) _sql_constraints = [( - 'hs_code_uniq', - 'unique(name)', - 'This H.S. code already exists in Odoo !' - )] - - @api.model - @api.returns('self', lambda value: value.id) - def create(self, vals): - if vals.get('intrastat_code'): - vals['intrastat_code'] = vals['intrastat_code'].replace(' ', '') - return super(ReportIntrastatCode, self).create(vals) - - @api.multi - def write(self, vals): - if vals.get('intrastat_code'): - vals['intrastat_code'] = vals['intrastat_code'].replace(' ', '') - return super(ReportIntrastatCode, self).write(vals) + 'intrastat_transaction_code_unique', + 'UNIQUE(code, company_id)', + 'Code must be unique.')] -class ProductTemplate(models.Model): - _inherit = "product.template" +class IntrastatTransportMode(models.Model): + _name = 'intrastat.transport_mode' + _description = "Intrastat Transport Mode" + _rec_name = 'display_name' + _order = 'code' - intrastat_id = fields.Many2one( - 'report.intrastat.code', string='Intrastat Code', - help="Code from the Harmonised System. Nomenclature is " - "available from the World Customs Organisation, see " - "http://www.wcoomd.org/. Some countries have made their own " - "extensions to this nomenclature.") - origin_country_id = fields.Many2one( - 'res.country', string='Country of Origin', - help="Country of origin of the product i.e. product " - "'made in ____'. If you have different countries of origin " - "depending on the supplier from which you purchased the product, " - "leave this field empty and use the equivalent field on the " - "'product supplier info' form.") + @api.one + @api.depends('name', 'code') + def _display_name(self): + print "display_name self=", self + print "self.code=", self.code + print "self.name=", self.name + self.display_name = '%s. %s' % (self.code, self.name) + display_name = fields.Char( + string='Display Name', compute='_display_name', store=True, + readonly=True) + code = fields.Char(string='Code', required=True) + name = fields.Char(string='Name', required=True, translate=True) + description = fields.Char(string='Description', translate=True) -class ProductCategory(models.Model): - _inherit = "product.category" - - intrastat_id = fields.Many2one( - 'report.intrastat.code', string='Intrastat Code', - help="Code from the Harmonised System. If this code is not " - "set on the product itself, it will be read here, on the " - "related product category.") + _sql_constraints = [( + 'intrastat_transport_code_unique', + 'UNIQUE(code)', + 'Code must be unique.')] diff --git a/intrastat_product/intrastat_declaration.py b/intrastat_product/intrastat_declaration.py new file mode 100644 index 0000000..9f4f731 --- /dev/null +++ b/intrastat_product/intrastat_declaration.py @@ -0,0 +1,724 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Intrastat Product module for Odoo +# Copyright (C) 2011-2015 Akretion (http://www.akretion.com) +# Copyright (C) 2011-2015 Noviat (http://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 . +# +############################################################################## + +from openerp import models, fields, api, _ +from openerp.exceptions import Warning, RedirectWarning, ValidationError +import openerp.addons.decimal_precision as dp +from datetime import datetime, date +from dateutil.relativedelta import relativedelta +import logging + +_logger = logging.getLogger(__name__) + + +class IntrastatProductDeclaration(models.Model): + _name = 'intrastat.product.declaration' + _description = "Intrastat Product Report Base Object" + _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): + res = [] + company = self.env.user.company_id + arrivals = company.intrastat_arrivals + dispatches = company.intrastat_dispatches + if arrivals != 'exempt': + res.append(('arrivals', _('Declaration for Arrivals'))) + if dispatches != 'exempt': + res.append(('dispatches', _('Declaration for Dispatches'))) + return res + + @api.model + def _get_reporting_level(self): + return [ + ('standard', _('Standard')), + ('extended', _('Extended'))] + + @api.onchange('type') + def _onchange_type(self): + if self.type == 'arrivals': + self.reporting_level = \ + self.company_id.intrastat_arrivals == 'extended' \ + and 'extended' or 'standard' + if self.type == 'dispatches': + self.reporting_level = \ + self.company_id.intrastat_dispatches == 'extended' \ + and 'extended' or 'standard' + + @api.model + def _get_company(self): + return self.env.user.company_id + + @api.model + def _get_year(self): + if datetime.now().month == 1: + return datetime.now().year - 1 + else: + return datetime.now().year + + @api.model + def _get_month(self): + if datetime.now().month == 1: + return 12 + else: + return datetime.now().month - 1 + + @api.model + def _get_action(self): + return [ + ('replace', 'Replace'), + ('append', 'Append'), + ('nihil', 'Nihil')] + + @api.model + def _get_default_action(self): + return 'replace' + + company_id = fields.Many2one( + 'res.company', string='Company', readonly=True, + default=lambda self: self.env['res.company']._company_default_get( + 'intrastat.product.declaration')) + year = fields.Integer( + string='Year', required=True, + default=_get_year) + month = fields.Selection([ + (1, '01'), + (2, '02'), + (3, '03'), + (4, '04'), + (5, '05'), + (6, '06'), + (7, '07'), + (8, '08'), + (9, '09'), + (10, '10'), + (11, '11'), + (12, '12') + ], string='Month', required=True, + default=_get_month) + year_month = fields.Char( + compute='_compute_year_month', string='Month', readonly=True, + track_visibility='always', 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.") + action = fields.Selection( + '_get_action', + string='Action', required=True, + default=_get_default_action, + states={'done': [('readonly', True)]}, + track_visibility='onchange') + revision = fields.Integer( + string='Revision', default=1, + states={'done': [('readonly', True)]}, + help="Used to keep track of changes") + computation_line_ids = fields.One2many( + 'intrastat.product.computation.line', + 'parent_id', string='Intrastat Product Computation Lines', + states={'done': [('readonly', True)]}) + declaration_line_ids = fields.One2many( + 'intrastat.product.declaration.line', + 'parent_id', string='Intrastat Product Declaration Lines', + states={'done': [('readonly', True)]}) + num_decl_lines = fields.Integer( + compute='_compute_numbers', string='Number of Declaration Lines', + store=True, track_visibility='onchange') + total_amount = fields.Float( + compute='_compute_numbers', digits=dp.get_precision('Account'), + string='Total Amount', store=True, + help="Total amount in company currency of the declaration.") + currency_id = fields.Many2one( + 'res.currency', related='company_id.currency_id', readonly=True, + string='Currency') + state = fields.Selection([ + ('draft', 'Draft'), + ('done', 'Done'), + ], string='State', readonly=True, track_visibility='onchange', + copy=False, default='draft', + help="State of the declaration. When the state is set to 'Done', " + "the parameters become read-only.") + note = fields.Text( + string='Notes', + help="You can add some comments here if you want.") + reporting_level = fields.Selection( + '_get_reporting_level', + string='Reporting Level') + valid = fields.Boolean( + compute='_check_validity', + string='Valid') + + @api.one + @api.constrains('year') + def _check_year(self): + s = str(self.year) + if len(s) != 4 or s[0] != '2': + raise ValidationError( + _("Invalid Year !")) + + _sql_constraints = [ + ('date_uniq', + 'unique(year_month, company_id, type)', + "A declaration of the same type already exists for this month !" + "\nYou should update the existing declaration " + "or change the revision number of this one."), + ] + + @api.one + @api.depends('year', 'month') + def _compute_year_month(self): + if self.year and self.month: + self.year_month = '-'.join( + [str(self.year), format(self.month, '02')]) + + @api.one + @api.depends('month') + def _check_validity(self): + """ TO DO: logic based upon computation lines """ + self.valid = True + + @api.one + @api.returns('self', lambda value: value.id) + def copy(self, default=None): + default = default or {} + default['revision'] = self.revision + 1 + return super(IntrastatProductDeclaration, self).copy(default) + + def _company_warning(self, msg): + action = self.env.ref('base.action_res_company_form') + raise RedirectWarning( + msg, action.id, + _('Go to company configuration screen')) + + def _get_partner_country(self, inv_line): + country = inv_line.invoice_id.intrastat_country_id \ + or inv_line.invoice_id.partner_id.country_id + if not country.intrastat: + country = False + elif country == self.company_id.country_id: + country = False + return country + + def _get_intrastat_transaction(self, inv_line): + if inv_line.invoice_id.intrastat_transaction_id: + tr = inv_line.invoice_id.intrastat_transaction_id.code + else: + tr = self.env.ref( + 'l10n_be_intrastat_advanced.intrastat_transaction_1') + return tr + + 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 + else: + msg = _( + "The Intrastat Region of the Company is not set, " + "please configure it first.") + self._company_warning(msg) + return region + + def _get_weight_and_supplunits(self, inv_line): + line_qty = inv_line.quantity + product = inv_line.product_id + invoice = inv_line.invoice_id + intrastat_unit_id = inv_line.intrastat_id.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 = suppl_unit_qty = 0.0 + + if not source_uom: + note = "\n" + _( + "Missing unit of measure on the line with %d " + "product(s) '%s' on invoice '%s'." + ) % (line_qty, product.name, invoice.number) + note += "\n" + _( + "Please adjust this line manually.") + self._note += note + return weight, suppl_unit_qty + + if intrastat_unit_id: + target_uom = intrastat_unit_id.uom_id + if not target_uom: + note = "\n" + _( + "Conversion from Intrastat Supplementary Unit '%s' to " + "Unit of Measure is not implemented yet." + ) % intrastat_unit_id.name + note += "\n" + _( + "Please correct the Intrastat Supplementary Unit " + "settingsand regenerate the lines or adjust the lines " + "with Intrastat Code '%s' manually" + ) % intrastat_code + self._note += note + return weight, suppl_unit_qty + if target_uom.categ_id == source_uom.category_id: + suppl_unit_qty = self.env['product.uom']._compute_qty_obj( + source_uom, line_qty, target_uom) + else: + note = "\n" + _( + "Conversion from unit of measure '%s' to '%s' " + "is not implemented yet." + ) % (source_uom.name, target_uom.name) + note += "\n" + _( + "Please correct the unit of measure settings and " + "regenerate the lines or adjust the impacted " + "lines manually") + self._note += note + return weight, suppl_unit_qty + + else: + 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) + elif source_uom.category_id == pce_uom_categ: + if not product.weight_net: + note = "\n" + _( + "Missing net weight on product '%s'." + ) % product.name + note += "\n" + _( + "Please correct the product record and regenerate " + "the lines or adjust the impacted lines manually") + self._note += note + return weight, suppl_unit_qty + if source_uom == pce_uom: + weight = product.weight_net * line_qty + 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) + else: + note = "\n" + _( + "Conversion from unit of measure '%s' to 'Kg' " + "is not implemented yet." + ) % source_uom.name + note += "\n" + _( + "Please correct the unit of measure settings and " + "regenerate the lines or adjust the impacted lines " + "manually") + self._note += note + return weight, suppl_unit_qty + + return weight, suppl_unit_qty + + 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) + return amount + + def _get_transport(self, inv_line): + transport = inv_line.invoice.transport_mode_id \ + or self.company_id.intrastat_transport_id + if not transport: + msg = _( + "The default Intrastat Transport Mode " + "of the Company is not set, " + "please configure it first.") + self._company_warning(msg) + return transport + + def _get_incoterm(self, inv_line): + incoterm = inv_line.invoice.incoterm_id \ + or self.company_id.incoterm_id + if not incoterm: + msg = _( + "The default Incoterm " + "of the Company is not set, " + "please configure it first.") + self._company_warning(msg) + return incoterm + + def _gather_invoices(self): + + decl_lines = [] + start_date = date(self.year, self.month, 1) + end_date = start_date + relativedelta(day=1, months=+1, days=-1) + + invoices = self.env['account.invoice'].search([ + ('date_invoice', '>=', start_date), + ('date_invoice', '<=', end_date), + ('state', 'in', ['open', 'paid']), + ('intrastat_country', '=', True), + ('company_id', '=', self.company_id.id)]) + + for invoice in invoices: + + if self.type == 'arrivals': + if invoice.type in ['out_invoice', 'in_refund']: + continue + else: + if invoice.type in ['in_invoice', 'out_refund']: + continue + + for inv_line in invoice.invoice_line: + + intrastat = inv_line.intrastat_id + if not intrastat: + continue + if not inv_line.quantity: + continue + + partner_country = self._get_partner_country(inv_line) + if not partner_country: + continue + + intrastat_transaction = \ + self._get_intrastat_transaction(inv_line) + + region = self._get_region(inv_line) + + weight, suppl_unit_qty = self._get_weight_and_supplunits( + inv_line) + + amount_company_currency = self._get_amount(inv_line) + + line_vals = { + 'parent_id': self.id, + 'invoice_line_id': inv_line.id, + 'partner_country_id': partner_country.id, + 'product_id': inv_line.product_id.id, + 'intrastat_code_id': intrastat.id, + 'weight': weight, + 'suppl_unit_qty': suppl_unit_qty, + 'amount_company_currency': amount_company_currency, + 'transaction_id': intrastat_transaction.id, + 'region_id': region.id, + 'extended': self._extended, + } + + # extended declaration + if self._extended: + transport = self._get_transport(inv_line) + incoterm = self._get_incoterm(inv_line) + line_vals.update({ + 'transport_id': transport.id, + 'incoterm_id': incoterm.id, + }) + + decl_lines.append((0, 0, line_vals)) + + return decl_lines + + @api.multi + def action_gather(self): + self.ensure_one() + 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 ( + self.type == 'dispatches' and + self.company_id.intrastat_dispatches == 'extended'): + self._extended = True + else: + self._extended = False + + decl_lines_init = [(6, 0, [])] + decl_lines = decl_lines_init[:] + + decl_lines += self._gather_invoices() + + if decl_lines == decl_lines_init: + self.action = 'nihil' + note = "\n" + \ + _("No records found for the selected period !") + '\n' + \ + _("The Declaration Action has been set to 'nihil'.") + self._note += note + + # To DO: add check on tax cases 46, 48, 84, 86 + + self.write({'intrastat_line_ids': decl_lines}) + + if self._note: + note_header = '\n\n>>> ' + str(date.today()) + '\n' + self.note = (self.note or '') + note_header + self._note + result_view = self.env.ref( + 'l10n_be_intrastat_advanced.intrastat_result_view') + return { + 'name': _("Generate lines from invoices: results"), + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'intrastat.result.view', + 'view_id': result_view.id, + 'target': 'new', + 'context': dict(self._context, note=self._note), + 'type': 'ir.actions.act_window', + } + + return True + + @api.model + def group_line_hashcode(self, computation_line): + hashcode = "%s-%s-%s-%s-%s" % ( + computation_line.src_dest_country_id.id or False, + computation_line.hs_code or False, + computation_line.intrastat_unit_id.id or False, + computation_line.transaction_id.id or False, + computation_line.transport_id.id or False + ) + return hashcode + + @api.multi + def generate_declaration(self): + """ generate declaration lines """ + self.ensure_one() + assert self.valid, 'Computation lines are not valid' + # Delete existing declaration lines + self.declaration_line_ids.unlink() + # Regenerate declaration lines from computation lines + dl_group = {} + for cl in self.computation_line_ids: + hashcode = self.group_line_hashcode(cl) + if hashcode in dl_group: + dl_group[hashcode].append(cl) + else: + dl_group[hashcode] = [cl] + ipdlo = self.pool['intrastat.product.declaration.line'] + for cl_lines in dl_group.values(): + vals = ipdlo._prepare_declaration_line(cl_lines) + declaration_line = ipdlo.create(vals) + cl_lines.write({'declaration_line_id': declaration_line.id}) + return True + + +class IntrastatProductComputationLine(models.Model): + _name = 'intrastat.product.computation.line' + _description = "Intrastat Product Computataion Lines" + + parent_id = fields.Many2one( + 'intrastat.product.declaration', + string='Intrastat Product Declaration', + ondelete='cascade', readonly=True) + company_id = fields.Many2one( + 'res.company', related='parent_id.company_id', + string="Company", readonly=True) + company_currency_id = fields.Many2one( + 'res.currency', related='company_id.currency_id', + string="Company currency", readonly=True) + type = fields.Selection( + related='parent_id.type', + string='Type', + readonly=True) + reporting_level = fields.Selection( + related='parent_id.reporting_level', + string='Reporting Level', + readonly=True) + valid = fields.Boolean( + compute='_check_validity', + string='Valid') + invoice_line_id = fields.Many2one( + 'account.invoice.line', string='Invoice Line', readonly=True) + invoice_id = fields.Many2one( + 'account.invoice', related='invoice_line_id.invoice_id', + string='Invoice', readonly=True) + declaration_line_id = fields.Many2one( + 'intrastat.product.declaration.line', + string='Declaration Line', readonly=True) + src_dest_country_id = fields.Many2one( + 'res.country', string='Country', + help="Country of Origin/Destination", + domain=[('intrastat', '=', True)]) + product_id = fields.Many2one( + 'product.product', related='invoice_line_id.product_id', + string='Product', readonly=True) + hs_code_id = fields.Many2one( + 'hs.code', string='Intrastat Code') + intrastat_unit_id = fields.Many2one( + 'intrastat.unit', related='hs_code_id.intrastat_unit_id', + string='Suppl. Unit', readonly=True, + help="Intrastat Supplementary Unit") + weight = fields.Float( + string='Weight (Kg)', + digits=dp.get_precision('Stock Weight')) + suppl_unit_qty = fields.Float( + string='Suppl. Unit Qty', + digits=dp.get_precision('Product Unit of Measure'), + help="Supplementary Units Quantity") + amount_company_currency = fields.Float( + string='Fiscal Value', + digits=dp.get_precision('Account'), required=True, + 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.") + transaction_id = fields.Many2one( + 'intrastat.transaction', + string='Intrastat Transaction') + # extended declaration + transport_id = fields.Many2one( + 'intrastat.transport_mode', + string='Transport Mode') + + @api.one + @api.depends('transport_id') + def _check_validity(self): + """ TO DO: logic based upon fields """ + self.valid = True + + @api.onchange('product_id') + def _onchange_product(self): + self.weight = 0.0 + self.suppl_unit_qty = 0.0 + self.intrastat_code_id = False + self.intrastat_unit_id = False + if self.product_id: + self.intrastat_code_id = self.product_id.intrastat_id + self.intrastat_unit_id =\ + self.product_id.intrastat_id.intrastat_unit_id + if not self.intrastat_unit_id: + self.weight = self.product_id.weight_net + + +class IntrastatProductDeclarationLine(models.Model): + _name = 'intrastat.product.declaration.line' + _description = "Intrastat Product Declaration Lines" + + parent_id = fields.Many2one( + 'intrastat.product.declaration', + string='Intrastat Product Declaration', + ondelete='cascade', readonly=True) + company_id = fields.Many2one( + 'res.company', related='parent_id.company_id', + string="Company", readonly=True) + company_currency_id = fields.Many2one( + 'res.currency', related='company_id.currency_id', + string="Company currency", readonly=True) + type = fields.Selection( + related='parent_id.type', + string='Type', + readonly=True) + reporting_level = fields.Selection( + related='parent_id.reporting_level', + string='Reporting Level', + readonly=True) + computation_line_ids = fields.One2many( + 'intrastat.product.computation.line', 'declaration_line_id', + string='Computation Lines', readonly=True) + src_dest_country_id = fields.Many2one( + 'res.country', string='Country', + help="Country of Origin/Destination", + domain=[('intrastat', '=', True)]) + hs_code_id = fields.Many2one( + 'hs.code', + string='Intrastat Code') + intrastat_unit_id = fields.Many2one( + 'intrastat.unit', related='hs_code_id.intrastat_unit_id', + string='Suppl. Unit', readonly=True, + help="Intrastat Supplementary Unit") + weight = fields.Integer( + string='Weight (Kg)') + suppl_unit_qty = fields.Integer( + string='Suppl. Unit Qty', + help="Supplementary Units Quantity") + amount_company_currency = fields.Integer( + string='Fiscal Value', + 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.") + transaction_id = fields.Many2one( + 'intrastat.transaction', + string='Intrastat Transaction') + # extended declaration + transport_id = fields.Many2one( + 'intrastat.transport_mode', + string='Transport Mode') + + @api.model + def _prepare_grouped_fields(computation_line, fields_to_sum): + vals = { + 'src_dest_country_id': computation_line.src_dest_country_id.id, + 'intrastat_unit_id': computation_line.intrastat_unit_id.id, + 'hs_code': computation_line.hs_code_id.local_code, + 'transaction_id': computation_line.transaction_id.id, + 'transport_id': computation_line.transport_id.id, + 'parent_id': computation_line.parent_id.id, + } + for field in fields_to_sum: + vals[field] = 0.0 + return vals + + def _fields_to_sum(): + fields_to_sum = [ + 'weight', + 'suppl_unit_qty', + 'amount_company_currency', + ] + return fields_to_sum + + @api.model + def _prepare_declaration_line(self, computation_lines): + fields_to_sum = self._fields_to_sum() + vals = self._prepare_grouped_fields( + computation_lines[0], fields_to_sum) + for computation_line in computation_lines: + for field in fields_to_sum: + vals[field] += computation_line[field] + return vals diff --git a/intrastat_product/intrastat_declaration_view.xml b/intrastat_product/intrastat_declaration_view.xml new file mode 100644 index 0000000..100eb93 --- /dev/null +++ b/intrastat_product/intrastat_declaration_view.xml @@ -0,0 +1,177 @@ + + + + + + intrastat.product.declaration.form + intrastat.product.declaration + +
+
+
+ +
+

+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+
+ + + + Intrastat Product Declaration Validated + intrastat.product.declaration + + Intrastat Product Declaration Validated + + + + intrastat.product.tree + intrastat.product.declaration + + + + + + + + + + + + + + + intrastat.product.search + intrastat.product.declaration + + + + + + + + + + + + + + + + intrastat.product.graph + intrastat.product.declaration + + + + + + + + + + + Intrastat Product Declaration + intrastat.product.declaration + tree,form,graph + + + + + +
+
diff --git a/intrastat_product/intrastat_demo.xml b/intrastat_product/intrastat_demo.xml index b5ae41b..61b1c39 100644 --- a/intrastat_product/intrastat_demo.xml +++ b/intrastat_product/intrastat_demo.xml @@ -1,7 +1,7 @@ @@ -9,80 +9,13 @@ - - 84715000 - 84715000 - - Automatic data-processing machines (computers) + + - - 84717050 - 84717050 - - Storage units + + - - 85340090 - 85340090 - Printed circuits - - - - - - 5 - - - - - - 6 - - - - - - 6.5 - - - - - - 0.5 - - - - - - 0.5 - - - - - - 0.5 - - - - - - 0.7 - - - - - - 0.8 - - - - - - 2 - - - diff --git a/intrastat_product/intrastat_view.xml b/intrastat_product/intrastat_view.xml index b62c280..c61fc61 100644 --- a/intrastat_product/intrastat_view.xml +++ b/intrastat_product/intrastat_view.xml @@ -1,101 +1,203 @@ - + - - - intrastat.product.template.form - product.template - - - - - + + + + + + intrastat.hs.code.tree + hs.code + + + + - - + + - - - intrastat.product.category.form - product.category - - - - - - - - - + + + intrastat.hs.code.form + hs.code + + + + + + + - - - intrastat.product.intrastat.code.search - report.intrastat.code - - - - - - - - - - intrastat.product.intrastat.code.tree - report.intrastat.code - - + + + intrastat.unit.form + intrastat.unit + +
+ - - + - - - - - - - fr.intrastat.product.intrastat.code.form - report.intrastat.code - - - - - - - - - - - - - - - + +
-
-
+
+
- - - Intrastat Code - report.intrastat.code - tree,form - + + intrastat.unit.tree + intrastat.unit + + + + + + + + - - + + intrastat.unit.search + intrastat.unit + + + + + + + + + -
+ + + Supplementary Units + intrastat.unit + tree,form + + + + + + + intrastat.transaction_form + intrastat.transaction + +
+ + + + + +
+
+
+ + + intrastat.transaction_tree + intrastat.transaction + + + + + + + + + + + intrastat.transaction.mode.search + intrastat.transaction + + + + + + + + + + + + Transaction Types + intrastat.transaction + tree,form + + + + + + + + intrastat.transport.mode.form + intrastat.transport_mode + +
+ + + + + +
+
+
+ + + intrastat.transport.mode.tree + intrastat.transport_mode + + + + + + + + + + + intrastat.transport.mode.search + intrastat.transport_mode + + + + + + + + + Transport Modes + intrastat.transport_mode + tree,form + + + + +
diff --git a/intrastat_product/res_company.py b/intrastat_product/res_company.py new file mode 100644 index 0000000..65e0e3f --- /dev/null +++ b/intrastat_product/res_company.py @@ -0,0 +1,67 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2012-2015 Noviat nv/sa (www.noviat.com) +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Luc de Meyer +# @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 . +# +############################################################################## + +from openerp import models, fields, api + + +class ResCompany(models.Model): + _inherit = 'res.company' + + @api.model + def _intrastat_arrivals(self): + return [ + ('exempt', 'Exempt'), + ('standard', 'Standard'), + ('extended', 'Extended')] + + @api.model + def _intrastat_dispatches(self): + return [ + ('exempt', 'Exempt'), + ('standard', 'Standard'), + ('extended', 'Extended')] + + @api.one + @api.depends('intrastat_arrivals', 'intrastat_dispatches') + def _compute_intrastat(self): + if self.intrastat_arrivals == 'exempt' \ + and self.intrastat_dispatches == 'exempt': + self.intrastat = 'exempt' + elif self.intrastat_arrivals == 'extended' \ + or self.intrastat_dispatches == 'extended': + self.intrastat = 'extended' + else: + self.intrastat = 'standard' + + intrastat_arrivals = fields.Selection( + '_intrastat_arrivals', string='Arrivals', + default='extended', required=True) + intrastat_dispatches = fields.Selection( + '_intrastat_arrivals', string='Dispatches', + default='extended', required=True) + intrastat_transport_id = fields.Many2one( + 'intrastat.transport_mode', + string='Default Transport Mode', ondelete='restrict') + intrastat = fields.Char( + string='Intrastat Declaration', store=True, readonly=True, + compute='_compute_intrastat') diff --git a/intrastat_product/res_company_view.xml b/intrastat_product/res_company_view.xml new file mode 100644 index 0000000..9761cb4 --- /dev/null +++ b/intrastat_product/res_company_view.xml @@ -0,0 +1,21 @@ + + + + + + intrastat.company.form + res.company + + + + + + + + + + + + + diff --git a/intrastat_product/security/intrastat_security.xml b/intrastat_product/security/intrastat_security.xml new file mode 100644 index 0000000..cd4f161 --- /dev/null +++ b/intrastat_product/security/intrastat_security.xml @@ -0,0 +1,12 @@ + + + + + + Intrastat Transaction Company rule + + ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] + + + + diff --git a/intrastat_product/security/ir.model.access.csv b/intrastat_product/security/ir.model.access.csv index 1708adf..bd6835f 100644 --- a/intrastat_product/security/ir.model.access.csv +++ b/intrastat_product/security/ir.model.access.csv @@ -1,3 +1,10 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_report_intrastat_code_sale_manager,Full access on report.intrastat.code to sale manager,model_report_intrastat_code,base.group_sale_manager,1,1,1,1 -access_report_intrastat_code_employee,Read access on report.intrastat.code to employee,model_report_intrastat_code,base.group_user,1,0,0,0 +access_intrastat_unit_read,Read access on Intrastat Supplementary Units to everybody,model_intrastat_unit,,1,0,0,0 +access_intrastat_unit_full,Full access on Intrastat Supplementary Units to Finance manager,model_intrastat_unit,account.group_account_manager,1,1,1,1 +access_intrastat_transaction_read,Read access on Intrastat Transaction Types to everybody,model_intrastat_transaction,,1,0,0,0 +access_intrastat_transaction_full,Full access on Intrastat Transaction Types to Finance manager,model_intrastat_transaction,account.group_account_manager,1,1,1,1 +access_intrastat_transport_mode_read,Read access on Intrastat Transport Modes to everybody,model_intrastat_transport_mode,,1,0,0,0 +access_intrastat_transport_mode_full,Full access on Intrastat Transport Modes to Finance manager,model_intrastat_transport_mode,account.group_account_manager,1,1,1,1 +access_intrastat_product_declaration,Full access on Intrastat Product Declarations to Accountant,model_intrastat_product_declaration,account.group_account_user,1,1,1,1 +access_intrastat_product_computation_line,Full access on Intrastat Product Computation Lines to Accountant,model_intrastat_product_computation_line,account.group_account_user,1,1,1,1 +access_intrastat_product_declaration_line,Full access on Intrastat Product Declaration Lines to Accountant,model_intrastat_product_declaration_line,account.group_account_user,1,1,1,1 diff --git a/intrastat_product/stock.py b/intrastat_product/stock.py new file mode 100644 index 0000000..c97cf75 --- /dev/null +++ b/intrastat_product/stock.py @@ -0,0 +1,40 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# 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 . +# +############################################################################## + +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 transport and department 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 + return super(StockPicking, self)._create_invoice_from_picking( + picking, vals) diff --git a/intrastat_product/stock_view.xml b/intrastat_product/stock_view.xml new file mode 100644 index 0000000..80ce61e --- /dev/null +++ b/intrastat_product/stock_view.xml @@ -0,0 +1,28 @@ + + + + + + + + + + intrastat.product.picking.form + stock.picking + + + + + + + + + + +