From d149b4d4f6ef84db5c82d7d39e63c273e86dff2b Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Tue, 4 Aug 2015 14:52:40 +0200 Subject: [PATCH] rename packaging_extended to packaging_uom --- packaging_uom/README.rst | 63 ++++++++++++++ packaging_uom/__init__.py | 3 + packaging_uom/__openerp__.py | 36 ++++++++ packaging_uom/models/__init__.py | 3 + packaging_uom/models/product_packaging.py | 47 +++++++++++ packaging_uom/tests/__init__.py | 3 + packaging_uom/tests/test_packaging.py | 82 +++++++++++++++++++ .../views/product_packaging_views.xml | 45 ++++++++++ 8 files changed, 282 insertions(+) create mode 100644 packaging_uom/README.rst create mode 100755 packaging_uom/__init__.py create mode 100755 packaging_uom/__openerp__.py create mode 100755 packaging_uom/models/__init__.py create mode 100644 packaging_uom/models/product_packaging.py create mode 100644 packaging_uom/tests/__init__.py create mode 100644 packaging_uom/tests/test_packaging.py create mode 100644 packaging_uom/views/product_packaging_views.xml diff --git a/packaging_uom/README.rst b/packaging_uom/README.rst new file mode 100644 index 000000000..b9991eb7c --- /dev/null +++ b/packaging_uom/README.rst @@ -0,0 +1,63 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Packaging Extended +=========== + +This module was written to use unit of measure instead of quantity by package +in the definition of packaging. +The goal is to ease the use of packaging in sale and purchase. + +Installation +============ + +To install this module, you need to: + +* Click on install button + +Configuration +============= + +To configure this module, you need to: + +* on product packaging define the unit of measure to use. + +Usage +===== + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +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 +======= + +Contributors +------------ + +* Laetitia Gangloff +* Laurent Mignon + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://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. \ No newline at end of file diff --git a/packaging_uom/__init__.py b/packaging_uom/__init__.py new file mode 100755 index 000000000..cde864bae --- /dev/null +++ b/packaging_uom/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/packaging_uom/__openerp__.py b/packaging_uom/__openerp__.py new file mode 100755 index 000000000..04c546571 --- /dev/null +++ b/packaging_uom/__openerp__.py @@ -0,0 +1,36 @@ +# -*- 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 Extended", + "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 new file mode 100755 index 000000000..87ac1c911 --- /dev/null +++ b/packaging_uom/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import product_packaging diff --git a/packaging_uom/models/product_packaging.py b/packaging_uom/models/product_packaging.py new file mode 100644 index 000000000..7eb394459 --- /dev/null +++ b/packaging_uom/models/product_packaging.py @@ -0,0 +1,47 @@ +# -*- 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 + + +class ProductPackaging(models.Model): + _inherit = 'product.packaging' + + 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( + related='product_tmpl_id.uom_id.category_id', + 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') + def _compute_qty(self): + """ + 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) + else: + self.qty = 0 diff --git a/packaging_uom/tests/__init__.py b/packaging_uom/tests/__init__.py new file mode 100644 index 000000000..c8a922e42 --- /dev/null +++ b/packaging_uom/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import test_packaging diff --git a/packaging_uom/tests/test_packaging.py b/packaging_uom/tests/test_packaging.py new file mode 100644 index 000000000..105dd32d7 --- /dev/null +++ b/packaging_uom/tests/test_packaging.py @@ -0,0 +1,82 @@ +# -*- 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/views/product_packaging_views.xml b/packaging_uom/views/product_packaging_views.xml new file mode 100644 index 000000000..ba53d764e --- /dev/null +++ b/packaging_uom/views/product_packaging_views.xml @@ -0,0 +1,45 @@ + + + + + + product.template.common.form (packaging_uom) + product.template + + + + + {'default_product_tmpl_id': id, + 'tree_view_ref':'product.product_packaging_tree_view_product', + 'form_view_ref': 'product.product_packaging_form_view_without_product'} + + + + + + product.packaging.form.view.without.product (packaging_uom) + product.packaging + + + + + + + + + + + + product.packaging.form.view (packaging_uom) + product.packaging + + + + + + + + + + +