From 244adcaf265a48d493f1b06d484cd2ecd22bcbac Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 21 Nov 2016 16:53:50 +0100 Subject: [PATCH] 9.0 mig product harmonized system (#7) * Backport from 10.0 to 9.0: import odoo to import openerp, to , bring back if noupdate=1, rename __manifest__.py to __openerp__.py, downgrade version number to 9.0.1.0.0, and make module installable. * Re-add H.S.codes menu item under Sales-Product-Configuration. (it had been removed to remove the reference to product module, but I don't understand that decision since this module by nature depends on product module anyway) * Added module tests. * flake8 * Encoding lines at the beginning of python files --- .../{__manifest__.py => __openerp__.py} | 4 +- .../demo/product_demo.xml | 8 ++-- product_harmonized_system/models/hs_code.py | 2 +- .../models/product_category.py | 2 +- .../models/product_template.py | 2 +- .../security/product_hs_security.xml | 6 ++- product_harmonized_system/tests/__init__.py | 3 ++ product_harmonized_system/tests/test_hs.py | 44 +++++++++++++++++++ product_harmonized_system/views/hs_code.xml | 6 +-- .../views/product_category.xml | 4 +- .../views/product_template.xml | 4 +- 11 files changed, 66 insertions(+), 19 deletions(-) rename product_harmonized_system/{__manifest__.py => __openerp__.py} (93%) create mode 100644 product_harmonized_system/tests/__init__.py create mode 100644 product_harmonized_system/tests/test_hs.py diff --git a/product_harmonized_system/__manifest__.py b/product_harmonized_system/__openerp__.py similarity index 93% rename from product_harmonized_system/__manifest__.py rename to product_harmonized_system/__openerp__.py index 2d7187e..41512b8 100644 --- a/product_harmonized_system/__manifest__.py +++ b/product_harmonized_system/__openerp__.py @@ -7,7 +7,7 @@ { 'name': 'Product Harmonized System Codes', - 'version': '10.0.1.0.0', + 'version': '9.0.1.0.0', 'category': 'Reporting', 'license': 'AGPL-3', 'summary': 'Base module for Product Import/Export reports', @@ -24,5 +24,5 @@ 'demo': [ 'demo/product_demo.xml', ], - 'installable': False, + 'installable': True, } diff --git a/product_harmonized_system/demo/product_demo.xml b/product_harmonized_system/demo/product_demo.xml index dbc475f..78d637a 100644 --- a/product_harmonized_system/demo/product_demo.xml +++ b/product_harmonized_system/demo/product_demo.xml @@ -5,8 +5,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> - - + + 84715000 @@ -77,5 +77,5 @@ 3.3 - - + + diff --git a/product_harmonized_system/models/hs_code.py b/product_harmonized_system/models/hs_code.py index 580c957..3d1e9f2 100644 --- a/product_harmonized_system/models/hs_code.py +++ b/product_harmonized_system/models/hs_code.py @@ -5,7 +5,7 @@ # @author Luc de Meyer # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from openerp import models, fields, api class HSCode(models.Model): diff --git a/product_harmonized_system/models/product_category.py b/product_harmonized_system/models/product_category.py index 6f6233e..8ae3124 100644 --- a/product_harmonized_system/models/product_category.py +++ b/product_harmonized_system/models/product_category.py @@ -5,7 +5,7 @@ # @author Luc de Meyer # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from openerp import models, fields, api class ProductCategory(models.Model): diff --git a/product_harmonized_system/models/product_template.py b/product_harmonized_system/models/product_template.py index 8893f39..c607453 100644 --- a/product_harmonized_system/models/product_template.py +++ b/product_harmonized_system/models/product_template.py @@ -5,7 +5,7 @@ # @author Luc de Meyer # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from openerp import models, fields, api class ProductTemplate(models.Model): diff --git a/product_harmonized_system/security/product_hs_security.xml b/product_harmonized_system/security/product_hs_security.xml index c7da6fb..a50afa1 100644 --- a/product_harmonized_system/security/product_hs_security.xml +++ b/product_harmonized_system/security/product_hs_security.xml @@ -1,5 +1,6 @@ - + + HS Code Company rule @@ -7,4 +8,5 @@ ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] - + + diff --git a/product_harmonized_system/tests/__init__.py b/product_harmonized_system/tests/__init__.py new file mode 100644 index 0000000..7ef9cee --- /dev/null +++ b/product_harmonized_system/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import test_hs diff --git a/product_harmonized_system/tests/test_hs.py b/product_harmonized_system/tests/test_hs.py new file mode 100644 index 0000000..bb04b68 --- /dev/null +++ b/product_harmonized_system/tests/test_hs.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +from openerp.tests.common import TransactionCase + + +class TestHs(TransactionCase): + """Tests for unit of measure conversion""" + + def setUp(self): + super(TestHs, self).setUp() + self.hs_code = self.env['hs.code'] + + def test_10_all_functionality(self): + # Create HS code + code1 = self.hs_code.create({ + 'local_code': 'TEST 6789' + }) + # - Test whether code is correctly de-spaced and truncated + self.assertEquals(code1.hs_code, 'TEST67') + + # For the category 'Saleable': + category1 = self.env.ref('product.product_category_1') + # - Set HS code on it + category1.hs_code_id = code1 + + # For the demo category 'Software' (child of Saleable): + category2 = self.env.ref('product.product_category_4') + # - Test if the HS code is null + self.assertFalse(category2.hs_code_id) + # - Test if the recursive HS code is the one we set on Saleable + self.assertEquals(category2.get_hs_code_recursively(), code1) + + # For the product 'Windows 7 Professional' (category Software) + product1 = self.env.ref('product.product_product_40') + # - Test if the HS code is null + self.assertFalse(product1.hs_code_id) + # - Test if the recursive HS code is the one we set on Saleable + self.assertEquals( + product1.product_tmpl_id.get_hs_code_recursively(), + code1) + # - Set HS code on it + product1.hs_code_id = code1 + # - Set country to 'us' + product1.origin_country_id = self.env.ref('base.us') diff --git a/product_harmonized_system/views/hs_code.xml b/product_harmonized_system/views/hs_code.xml index fac22af..a342d8c 100644 --- a/product_harmonized_system/views/hs_code.xml +++ b/product_harmonized_system/views/hs_code.xml @@ -5,7 +5,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> - + @@ -64,9 +64,7 @@ - - + diff --git a/product_harmonized_system/views/product_category.xml b/product_harmonized_system/views/product_category.xml index ac75e13..e4b7c30 100644 --- a/product_harmonized_system/views/product_category.xml +++ b/product_harmonized_system/views/product_category.xml @@ -5,7 +5,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> - + @@ -21,4 +21,4 @@ - + diff --git a/product_harmonized_system/views/product_template.xml b/product_harmonized_system/views/product_template.xml index cc0ebcb..d17ed61 100644 --- a/product_harmonized_system/views/product_template.xml +++ b/product_harmonized_system/views/product_template.xml @@ -5,7 +5,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> - + @@ -20,4 +20,4 @@ - +