diff --git a/packaging_uom/README.rst b/packaging_uom/README.rst index 8e626e7a8..ced4575d5 100644 --- a/packaging_uom/README.rst +++ b/packaging_uom/README.rst @@ -1,5 +1,6 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License: AGPL-3 + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 Packaging UOM ============= @@ -25,22 +26,26 @@ To configure this module, you need to: Usage ===== -For further information, please visit: - -* https://www.odoo.com/forum/help-1 +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/153/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 ======= +Images +------ + +* Odoo Community Association: `Icon `_. + Contributors ------------ diff --git a/packaging_uom/__init__.py b/packaging_uom/__init__.py index cde864bae..239921736 100755 --- a/packaging_uom/__init__.py +++ b/packaging_uom/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- - +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models diff --git a/packaging_uom/__manifest__.py b/packaging_uom/__manifest__.py new file mode 100755 index 000000000..61bba0786 --- /dev/null +++ b/packaging_uom/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Packaging UOM", + "version": "10.0.1.0.0", + "author": 'ACSONE SA/NV, ' + 'Odoo Community Association (OCA)', + "category": "Warehouse", + "website": "http://www.acsone.eu", + 'summary': "Use uom in package", + "depends": ["product", + ], + "data": ["views/product_packaging_views.xml", + ], + "license": "AGPL-3", + "installable": True, +} diff --git a/packaging_uom/__openerp__.py b/packaging_uom/__openerp__.py deleted file mode 100755 index 31de96b1f..000000000 --- a/packaging_uom/__openerp__.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Authors: Laetitia Gangloff -# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) -# -# 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": "Packaging UOM", - "version": "0.1", - 'author': "Acsone, Odoo Community Association (OCA)", - "category": "Other", - "website": "http://www.acsone.eu", - 'summary': "Use uom in package", - "depends": ["product", - ], - "data": ["views/product_packaging_views.xml", - ], - "license": "AGPL-3", - "installable": True, - "application": False, -} diff --git a/packaging_uom/models/__init__.py b/packaging_uom/models/__init__.py index 87ac1c911..5296fa85a 100755 --- a/packaging_uom/models/__init__.py +++ b/packaging_uom/models/__init__.py @@ -1,3 +1,5 @@ # -*- coding: utf-8 -*- +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import product_packaging diff --git a/packaging_uom/models/product_packaging.py b/packaging_uom/models/product_packaging.py index 2d4b78518..c98a2e28e 100644 --- a/packaging_uom/models/product_packaging.py +++ b/packaging_uom/models/product_packaging.py @@ -1,26 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Authors: Laetitia Gangloff -# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) -# -# 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 api, fields, models +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models class ProductPackaging(models.Model): @@ -34,13 +15,22 @@ class ProductPackaging(models.Model): uom = self.env['product.uom'].browse(uom_id) return uom.category_id.id - uom_id = fields.Many2one('product.uom', 'Unit of Measure', required=True, - help="It must be in the same category than " - "the default unit of measure.") + uom_id = fields.Many2one( + 'product.uom', + 'Unit of Measure', + required=True, + help="It must be in the same category than " + "the default unit of measure." + ) uom_categ_domain_id = fields.Many2one( default=_default_uom_categ_domain_id, - comodel_name='product.uom.categ') - qty = fields.Float(compute="_compute_qty", store=True, readonly=True) + comodel_name='product.uom.categ' + ) + qty = fields.Float( + compute="_compute_qty", + store=True, + readonly=True + ) @api.one @api.depends('uom_id', 'product_tmpl_id.uom_id') @@ -49,7 +39,7 @@ class ProductPackaging(models.Model): Compute the quantity by package based on uom """ if self.uom_id and self.product_tmpl_id: - self.qty = self.env['product.uom']._compute_qty_obj( - self.uom_id, 1, self.product_tmpl_id.uom_id) + self.qty = self.uom_id._compute_quantity( + 1, to_unit=self.product_tmpl_id.uom_id) else: self.qty = 0 diff --git a/packaging_uom/static/description/icon.png b/packaging_uom/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/packaging_uom/static/description/icon.png differ diff --git a/packaging_uom/tests/__init__.py b/packaging_uom/tests/__init__.py index c8a922e42..a7d7d468e 100644 --- a/packaging_uom/tests/__init__.py +++ b/packaging_uom/tests/__init__.py @@ -1,3 +1,5 @@ # -*- coding: utf-8 -*- +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import test_packaging +from . import test_product_packaging diff --git a/packaging_uom/tests/test_packaging.py b/packaging_uom/tests/test_packaging.py deleted file mode 100644 index 105dd32d7..000000000 --- a/packaging_uom/tests/test_packaging.py +++ /dev/null @@ -1,82 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Authors: Laetitia Gangloff -# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) -# -# 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 . -# -############################################################################## - -import openerp.tests.common as common - - -class TestPackaging(common.TransactionCase): - - def setUp(self): - super(TestPackaging, self).setUp() - - def test_compute_quantity_by_package(self): - """ Create a packagings with uom product_uom_dozen on - * product_product_35 (uom is product_uom_dozen) - * product_product_34 (uom is product_uom_unit) - Result should be : - * product_product_35 -> qty by package : 1 - * product_product_34 -> qty by package : 12 - Create product_uom_24 - Update product_product_35 to set this new uom - Result should be : - * product_product_35 -> qty by package : 0.5 - Update product_package_34 to set this new uom - Result should be : - * product_product_34 -> qty by package : 24 - Create product_uom 6 - Update product_product_35 to set this new uom - Result should be : - * product_product_35 -> qty by package : 2 - Update product_package_34 to set this new uom - Result should be : - * product_product_34 -> qty by package : 6 - """ - packaging_obj = self.env['product.packaging'] - product_packaging_35 = packaging_obj.create( - {'product_tmpl_id': self.env.ref('product.product_product_35' - ).product_tmpl_id.id, - 'uom_id': self.env.ref('product.product_uom_dozen').id}) - self.assertAlmostEqual(product_packaging_35.qty, 1) - product_packaging_34 = packaging_obj.create( - {'product_tmpl_id': self.env.ref('product.product_product_34' - ).product_tmpl_id.id, - 'uom_id': self.env.ref('product.product_uom_dozen').id}) - self.assertAlmostEqual(product_packaging_34.qty, 12) - product_uom_24 = self.env['product.uom'].create( - {'category_id': self.env.ref('product.product_uom_categ_unit').id, - 'name': 'Double Dozens', - 'factor_inv': 24, - 'uom_type': 'bigger' - }) - self.env.ref('product.product_product_35').uom_id = product_uom_24 - self.assertAlmostEqual(product_packaging_35.qty, 0.5) - product_packaging_34.uom_id = product_uom_24 - self.assertAlmostEqual(product_packaging_34.qty, 24) - product_uom_6 = self.env['product.uom'].create( - {'category_id': self.env.ref('product.product_uom_categ_unit').id, - 'name': 'Demi Dozens', - 'factor_inv': 6, - 'uom_type': 'bigger' - }) - self.env.ref('product.product_product_35').uom_id = product_uom_6 - self.assertAlmostEqual(product_packaging_35.qty, 2) - product_packaging_34.uom_id = product_uom_6 - self.assertAlmostEqual(product_packaging_34.qty, 6) diff --git a/packaging_uom/tests/test_product_packaging.py b/packaging_uom/tests/test_product_packaging.py new file mode 100644 index 000000000..00b7d628b --- /dev/null +++ b/packaging_uom/tests/test_product_packaging.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import odoo.tests.common as common + + +class TestProductPackaging(common.TransactionCase): + + def setUp(self): + super(TestProductPackaging, self).setUp() + self.uom_unit = self.env.ref('product.product_uom_unit') + self.uom_dozen = self.env.ref('product.product_uom_dozen') + self.product_tmpl_dozen = self.env[ + 'product.template'].new( + {'uom_id': self.uom_dozen}) + self.product_tmpl_unit = self.env[ + 'product.template'].new( + {'uom_id': self.uom_unit}) + + def test_compute_quantity_by_package(self): + """ Create a packagings with uom product_uom_dozen on + * product_tmpl_dozen (uom is product_uom_dozen) + * product_tmpl_unit (uom is product_uom_unit) + Result should be : + * product_tmpl_dozen -> qty by package : 1 + * product_tmpl_unit -> qty by package : 12 + Create product_uom_24 + Update product_tmpl_dozen to set this new uom + Result should be : + * product_tmpl_dozen -> qty by package : 0.5 + Update product_package_unit to set this new uom + Result should be : + * product_packaging_unit -> qty by package : 24 + Create product_uom 6 + Update product_tmpl_dozen to set this new uom + Result should be : + * product_packaging_dozen -> qty by package : 2 + Update product_packaging_unit to set this new uom + Result should be : + * product_packaging_unit -> qty by package : 6 + """ + + packaging_obj = self.env['product.packaging'] + product_packaging_dozen = packaging_obj.new( + {'product_tmpl_id': self.product_tmpl_dozen, + 'uom_id': self.uom_dozen}) + self.assertAlmostEqual(product_packaging_dozen.qty, 1) + product_packaging_unit = packaging_obj.new( + {'product_tmpl_id': self.product_tmpl_unit, + 'uom_id': self.uom_dozen}) + self.assertAlmostEqual(product_packaging_unit.qty, 12) + product_uom_24 = self.env['product.uom'].create( + {'category_id': self.env.ref('product.product_uom_categ_unit').id, + 'name': 'Double Dozens', + 'factor_inv': 24, + 'uom_type': 'bigger' + }) + self.product_tmpl_dozen.uom_id = product_uom_24 + self.assertAlmostEqual(product_packaging_dozen.qty, 0.5) + product_packaging_unit.uom_id = product_uom_24 + self.assertAlmostEqual(product_packaging_unit.qty, 24) + product_uom_6 = self.env['product.uom'].create( + {'category_id': self.env.ref('product.product_uom_categ_unit').id, + 'name': 'Demi Dozens', + 'factor_inv': 6, + 'uom_type': 'bigger' + }) + self.product_tmpl_dozen.uom_id = product_uom_6 + self.assertAlmostEqual(product_packaging_dozen.qty, 2) + product_packaging_unit.uom_id = product_uom_6 + self.assertAlmostEqual(product_packaging_unit.qty, 6) diff --git a/packaging_uom/views/product_packaging_views.xml b/packaging_uom/views/product_packaging_views.xml index b94af7963..1f3b1dd9c 100644 --- a/packaging_uom/views/product_packaging_views.xml +++ b/packaging_uom/views/product_packaging_views.xml @@ -1,45 +1,32 @@ - - + + + + product.template.common.form (packaging_uom) + product.template + + + + + + + + + + + - - product.template.common.form (packaging_uom) - product.template - - - - - {'get_uom_categ_from_uom': uom_id, - 'tree_view_ref':'product.product_packaging_tree_view_product', - 'form_view_ref': 'product.product_packaging_form_view_without_product'} - + + product.packaging.form.view (packaging_uom) + product.packaging + + + + + - - - - product.packaging.form.view.without.product (packaging_uom) - product.packaging - - - - - - - - - - - - product.packaging.form.view (packaging_uom) - product.packaging - - - - - - - - - - - + + +