diff --git a/product_harmonized_system/README.rst b/product_harmonized_system/README.rst index 52304f1..12798c0 100644 --- a/product_harmonized_system/README.rst +++ b/product_harmonized_system/README.rst @@ -1,6 +1,9 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============================================ Harmonized System Codes (and National Codes) ============================================ @@ -12,11 +15,13 @@ You will also be able to configure the country of origin of a product, which is This module should be usefull for all companies that export physical goods abroad. This module is also used by the Intrastat modules for the European Union, cf the *intrastat_product* module. + Installation ============ This module is NOT compatible with the *report_intrastat* module from the official addons. + Usage ===== @@ -24,15 +29,32 @@ To create H.S. codes, go to the menu *Sales > Configuration > Product Categories Then you will be able to set the H.S. code on an product (under the *Information* tab) or on a product category. On the product form, you will also be able to set the *Country of Origin* of a product (for example, if the product is *made in China*, select *China* as *Country of Origin*). +.. 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 + + +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 `_. + + Credits ======= -Author -------- +Contributors +------------ * Alexis de Lattre, Akretion * Luc De Meyer, Noviat + Maintainer ---------- .. image:: http://odoo-community.org/logo.png diff --git a/product_harmonized_system/__init__.py b/product_harmonized_system/__init__.py index a64ddf0..21ff7c2 100644 --- a/product_harmonized_system/__init__.py +++ b/product_harmonized_system/__init__.py @@ -1,4 +1,3 @@ # -*- encoding: utf-8 -*- -from . import hs -from . import product +from . import models diff --git a/product_harmonized_system/__openerp__.py b/product_harmonized_system/__openerp__.py index 3575e46..069e1c5 100644 --- a/product_harmonized_system/__openerp__.py +++ b/product_harmonized_system/__openerp__.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2015 Noviat (http://www.noviat.com) +# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) # @author Alexis de Lattre # @author Luc de Meyer # @@ -23,7 +23,7 @@ { 'name': 'Product Harmonized System Codes', - 'version': '0.1', + 'version': '0.2', 'category': 'Reporting', 'license': 'AGPL-3', 'summary': 'Base module for Product Import/Export reports', @@ -31,11 +31,14 @@ 'depends': ['product'], 'conflicts': ['report_intrastat'], 'data': [ - 'product_view.xml', - 'hs_view.xml', 'security/product_hs_security.xml', 'security/ir.model.access.csv', + 'views/hs_code.xml', + 'views/product_category.xml', + 'views/product_template.xml', + ], + 'demo': [ + 'demo/product_demo.xml', ], - 'demo': ['product_demo.xml'], 'installable': True, } diff --git a/product_harmonized_system/product_demo.xml b/product_harmonized_system/demo/product_demo.xml similarity index 100% rename from product_harmonized_system/product_demo.xml rename to product_harmonized_system/demo/product_demo.xml diff --git a/product_harmonized_system/models/__init__.py b/product_harmonized_system/models/__init__.py new file mode 100644 index 0000000..9750aa8 --- /dev/null +++ b/product_harmonized_system/models/__init__.py @@ -0,0 +1,5 @@ +# -*- encoding: utf-8 -*- + +from . import hs_code +from . import product_category +from . import product_template diff --git a/product_harmonized_system/hs.py b/product_harmonized_system/models/hs_code.py similarity index 95% rename from product_harmonized_system/hs.py rename to product_harmonized_system/models/hs_code.py index bbf34c5..ee61855 100644 --- a/product_harmonized_system/hs.py +++ b/product_harmonized_system/models/hs_code.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2015 Noviat (http://www.noviat.com) +# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) # @author Alexis de Lattre # @author Luc de Meyer # @@ -30,23 +30,8 @@ class HSCode(models.Model): _order = "local_code" _rec_name = "display_name" - @api.one - @api.depends('local_code') - def _get_hs_code(self): - self.hs_code = self.local_code and self.local_code[:6] - - @api.one - @api.depends('local_code', 'description') - def _compute_display_name(self): - display_name = self.local_code - if self.description: - display_name += ' ' + self.description - self.display_name = len(display_name) > 55 \ - and display_name[:55] + '...' \ - or display_name - hs_code = fields.Char( - string='H.S. Code', compute='_get_hs_code', readonly=True, + string='H.S. Code', compute='_compute_hs_code', readonly=True, help="Harmonized System code (6 digits). Full list is " "available from the World Customs Organisation, see " "http://www.wcoomd.org") @@ -67,6 +52,21 @@ class HSCode(models.Model): default=lambda self: self.env['res.company']._company_default_get( 'hs.code')) + @api.one + @api.depends('local_code') + def _compute_hs_code(self): + self.hs_code = self.local_code and self.local_code[:6] + + @api.one + @api.depends('local_code', 'description') + def _compute_display_name(self): + display_name = self.local_code + if self.description: + display_name += ' ' + self.description + self.display_name = len(display_name) > 55 \ + and display_name[:55] + '...' \ + or display_name + _sql_constraints = [ ('local_code_company_uniq', 'unique(local_code, company_id)', 'This code already exists for this company !'), diff --git a/product_harmonized_system/models/product_category.py b/product_harmonized_system/models/product_category.py new file mode 100644 index 0000000..85e904a --- /dev/null +++ b/product_harmonized_system/models/product_category.py @@ -0,0 +1,46 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# 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 ProductCategory(models.Model): + _inherit = "product.category" + + hs_code_id = fields.Many2one( + 'hs.code', string='H.S. Code', + company_dependent=True, ondelete='restrict', + help="Harmonised System Code. If this code is not " + "set on the product itself, it will be read here, on the " + "related product category.") + + @api.multi + def get_hs_code_recursively(self): + self.ensure_one() + if self.hs_code_id: + res = self.hs_code_id + elif self.parent_id: + res = self.parent_id.get_hs_code_recursively() + else: + res = None + return res diff --git a/product_harmonized_system/product.py b/product_harmonized_system/models/product_template.py similarity index 73% rename from product_harmonized_system/product.py rename to product_harmonized_system/models/product_template.py index 2801a10..497f344 100644 --- a/product_harmonized_system/product.py +++ b/product_harmonized_system/models/product_template.py @@ -2,7 +2,7 @@ ############################################################################## # # Copyright (C) 2011-2015 Akretion (http://www.akretion.com) -# Copyright (C) 2015 Noviat (http://www.noviat.com) +# Copyright (C) 2009-2015 Noviat (http://www.noviat.com) # @author Alexis de Lattre # @author Luc de Meyer # @@ -49,25 +49,3 @@ class ProductTemplate(models.Model): else: res = None return res - - -class ProductCategory(models.Model): - _inherit = "product.category" - - hs_code_id = fields.Many2one( - 'hs.code', string='H.S. Code', - company_dependent=True, ondelete='restrict', - help="Harmonised System Code. If this code is not " - "set on the product itself, it will be read here, on the " - "related product category.") - - @api.multi - def get_hs_code_recursively(self): - self.ensure_one() - if self.hs_code_id: - res = self.hs_code_id - elif self.parent_id: - res = self.parent_id.get_hs_code_recursively() - else: - res = None - return res diff --git a/product_harmonized_system/hs_view.xml b/product_harmonized_system/views/hs_code.xml similarity index 92% rename from product_harmonized_system/hs_view.xml rename to product_harmonized_system/views/hs_code.xml index 0b9a2a7..34b22de 100644 --- a/product_harmonized_system/hs_view.xml +++ b/product_harmonized_system/views/hs_code.xml @@ -10,7 +10,7 @@ - + hs.code.search hs.code @@ -22,7 +22,7 @@ - + hs.code.tree hs.code @@ -36,7 +36,7 @@ - + hs.code.form hs.code diff --git a/product_harmonized_system/views/product_category.xml b/product_harmonized_system/views/product_category.xml new file mode 100644 index 0000000..71b7010 --- /dev/null +++ b/product_harmonized_system/views/product_category.xml @@ -0,0 +1,27 @@ + + + + + + + + + + hs_code.product.category.form + product.category + + + + + + + + + + + + diff --git a/product_harmonized_system/product_view.xml b/product_harmonized_system/views/product_template.xml similarity index 60% rename from product_harmonized_system/product_view.xml rename to product_harmonized_system/views/product_template.xml index 7c15e95..2037b69 100644 --- a/product_harmonized_system/product_view.xml +++ b/product_harmonized_system/views/product_template.xml @@ -22,19 +22,5 @@ - - - hs_code.product.category.form - product.category - - - - - - - - - -