diff --git a/product_secondary_unit/README.rst b/product_secondary_unit/README.rst new file mode 100644 index 00000000000..3757c47dc45 --- /dev/null +++ b/product_secondary_unit/README.rst @@ -0,0 +1,84 @@ +====================== +Product Secondary Unit +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/11.0/product_secondary_unit + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-11-0/product-attribute-11-0-product_secondary_unit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/135/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of product module to allow define +other units with their conversion factor. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module you need to: + +#. Go to a *Product > General Information tab*. +#. Create any record in "Secondary unit of measure". +#. Set the conversion factor. + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* Carlos Dauden +* Sergio Teruel + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_secondary_unit/__init__.py b/product_secondary_unit/__init__.py new file mode 100644 index 00000000000..3275ac2adf3 --- /dev/null +++ b/product_secondary_unit/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/product_secondary_unit/__manifest__.py b/product_secondary_unit/__manifest__.py new file mode 100644 index 00000000000..7a04b95f739 --- /dev/null +++ b/product_secondary_unit/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + 'name': 'Product Secondary Unit', + 'summary': 'Set a secondary unit per product', + 'version': '11.0.1.0.0', + 'development_status': 'Beta', + 'category': 'Product', + 'website': 'https://github.com/OCA/product-attribute', + 'author': 'Tecnativa, Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'application': False, + 'installable': True, + 'depends': [ + 'product', + ], + 'data': [ + 'security/ir.model.access.csv', + 'views/product_views.xml', + ], +} diff --git a/product_secondary_unit/i18n/es.po b/product_secondary_unit/i18n/es.po new file mode 100644 index 00000000000..5c936aecebb --- /dev/null +++ b/product_secondary_unit/i18n/es.po @@ -0,0 +1,106 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_secondary_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-09-05 10:03+0000\n" +"PO-Revision-Date: 2018-09-05 12:05+0200\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.0.6\n" +"Last-Translator: \n" +"Language: es_ES\n" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_create_date +msgid "Created on" +msgstr "Creado en" + +#. module: product_secondary_unit +#: model:ir.model.fields,help:product_secondary_unit.field_product_product_secondary_uom_ids +#: model:ir.model.fields,help:product_secondary_unit.field_product_secondary_unit_uom_id +#: model:ir.model.fields,help:product_secondary_unit.field_product_template_secondary_uom_ids +msgid "Default Secondary Unit of Measure." +msgstr "Segunda unidad de medida por defecto" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_product_sale_secondary_uom_id +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_template_sale_secondary_uom_id +msgid "Default unit sale" +msgstr "Unidad de venta por defecto" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_display_name +#, fuzzy +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_id +#, fuzzy +msgid "ID" +msgstr "ID" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit___last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_write_uid +msgid "Last Updated by" +msgstr "Última actualización de" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_write_date +msgid "Last Updated on" +msgstr "Última actualización en" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_name +msgid "Name" +msgstr "Nombre" + +#. module: product_secondary_unit +#: model:ir.model,name:product_secondary_unit.model_product_template +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_product_tmpl_id +msgid "Product Template" +msgstr "Plantilla de producto" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_factor +msgid "Secondary Unit Factor" +msgstr "Factor segunda unidad" + +#. module: product_secondary_unit +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_product_secondary_uom_ids +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_secondary_unit_uom_id +#: model:ir.model.fields,field_description:product_secondary_unit.field_product_template_secondary_uom_ids +msgid "Secondary Unit of Measure" +msgstr "Segunda unidad de medida" + +#. module: product_secondary_unit +#: model:ir.model,name:product_secondary_unit.model_product_secondary_unit +msgid "product.secondary.unit" +msgstr "" + +#. module: product_secondary_unit +#: model:ir.ui.view,arch_db:product_secondary_unit.product_template_form_view +msgid "secondary Unit" +msgstr "Unidad Secundaria" + +#. module: product_secondary_unit +#: model:ir.ui.view,arch_db:product_secondary_unit.product_template_form_view +msgid "secondary unit of measure" +msgstr "Segunda unidad de medida" diff --git a/product_secondary_unit/models/__init__.py b/product_secondary_unit/models/__init__.py new file mode 100644 index 00000000000..4775c1b3fcc --- /dev/null +++ b/product_secondary_unit/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import product_second_unit +from . import product_template diff --git a/product_secondary_unit/models/product_second_unit.py b/product_secondary_unit/models/product_second_unit.py new file mode 100755 index 00000000000..914186ad826 --- /dev/null +++ b/product_secondary_unit/models/product_second_unit.py @@ -0,0 +1,47 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class ProductSecondaryUnit(models.Model): + _name = 'product.secondary.unit' + + name = fields.Char(required=True) + code = fields.Char() + product_tmpl_id = fields.Many2one( + comodel_name='product.template', + string='Product Template', + required=True, + ) + uom_id = fields.Many2one( + comodel_name='product.uom', + string='Secondary Unit of Measure', + required=True, + help="Default Secondary Unit of Measure.", + ) + factor = fields.Float( + string='Secondary Unit Factor', + default=1.0, + digits=0, + required=True, + ) + + @api.multi + def name_get(self): + result = [] + for unit in self: + result.append((unit.id, "{unit_name}-{factor}".format( + unit_name=unit.name, + factor=unit.factor)) + ) + return result + + @api.model + def name_search(self, name='', args=None, operator='ilike', limit=100): + if args is None: + args = [] + units = self.search([('code', '=', name)] + args, limit=1) + if not units: + return super(ProductSecondaryUnit, self).name_search( + name=name, args=args, operator=operator, limit=limit) + return units.name_get() diff --git a/product_secondary_unit/models/product_template.py b/product_secondary_unit/models/product_template.py new file mode 100755 index 00000000000..067316bdc60 --- /dev/null +++ b/product_secondary_unit/models/product_template.py @@ -0,0 +1,18 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + secondary_uom_ids = fields.One2many( + comodel_name='product.secondary.unit', + inverse_name='product_tmpl_id', + string='Secondary Unit of Measure', + help='Default Secondary Unit of Measure.', + ) + sale_secondary_uom_id = fields.Many2one( + comodel_name='product.secondary.unit', + string='Default unit sale', + ) diff --git a/product_secondary_unit/readme/CONTRIBUTORS.rst b/product_secondary_unit/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..b919cb776aa --- /dev/null +++ b/product_secondary_unit/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Carlos Dauden +* Sergio Teruel diff --git a/product_secondary_unit/readme/DESCRIPTION.rst b/product_secondary_unit/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..006bd6d63a2 --- /dev/null +++ b/product_secondary_unit/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the functionality of product module to allow define +other units with their conversion factor. diff --git a/product_secondary_unit/readme/USAGE.rst b/product_secondary_unit/readme/USAGE.rst new file mode 100644 index 00000000000..3f837c39383 --- /dev/null +++ b/product_secondary_unit/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module you need to: + +#. Go to a *Product > General Information tab*. +#. Create any record in "Secondary unit of measure". +#. Set the conversion factor. diff --git a/product_secondary_unit/security/ir.model.access.csv b/product_secondary_unit/security/ir.model.access.csv new file mode 100644 index 00000000000..5ca549da6e5 --- /dev/null +++ b/product_secondary_unit/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_product_secondary_unit_user,access_product_second_unit_user,model_product_secondary_unit,base.group_user,1,1,1,1 diff --git a/product_secondary_unit/static/description/icon.png b/product_secondary_unit/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_secondary_unit/static/description/icon.png differ diff --git a/product_secondary_unit/tests/__init__.py b/product_secondary_unit/tests/__init__.py new file mode 100644 index 00000000000..62bc6773d19 --- /dev/null +++ b/product_secondary_unit/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_product_second_unit diff --git a/product_secondary_unit/tests/test_product_second_unit.py b/product_secondary_unit/tests/test_product_second_unit.py new file mode 100644 index 00000000000..3b01607bba3 --- /dev/null +++ b/product_secondary_unit/tests/test_product_second_unit.py @@ -0,0 +1,52 @@ +# Copyright 2018 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import SavepointCase + + +class TestProductSecondaryUnit(SavepointCase): + at_install = False + post_install = True + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product_uom_kg = cls.env.ref('product.product_uom_kgm') + cls.product_uom_unit = cls.env.ref('product.product_uom_unit') + cls.product = cls.env['product.template'].create({ + 'name': 'test', + 'uom_id': cls.product_uom_kg.id, + 'uom_po_id': cls.product_uom_kg.id, + 'secondary_uom_ids': [ + (0, 0, { + 'code': 'A', + 'name': 'unit-700', + 'uom_id': cls.product_uom_unit.id, + 'factor': 0.7, + }), + (0, 0, { + 'code': 'B', + 'name': 'unit-900', + 'uom_id': cls.product_uom_unit.id, + 'factor': 0.9, + }), + ], + }) + secondary_unit = cls.env['product.secondary.unit'].search([ + ('product_tmpl_id', '=', cls.product.id), + ], limit=1) + cls.product.sale_secondary_uom_id = secondary_unit.id + + def test_product_secondary_unit_name(self): + self.assertEqual( + self.product.sale_secondary_uom_id.name_get()[0][1], + 'unit-700-0.7') + + def test_product_secondary_unit_search(self): + args = [('product_tmpl_id.product_variant_ids', 'in', + self.product.product_variant_ids.ids)] + name_get = self.env['product.secondary.unit'].name_search( + name='A', args=args) + self.assertEqual(len(name_get), 1) + name_get = self.env['product.secondary.unit'].name_search( + name='X', args=args) + self.assertEqual(len(name_get), 0) diff --git a/product_secondary_unit/views/product_views.xml b/product_secondary_unit/views/product_views.xml new file mode 100755 index 00000000000..2ef69a3b719 --- /dev/null +++ b/product_secondary_unit/views/product_views.xml @@ -0,0 +1,32 @@ + + + + + + Product template Secondary Unit + product.template + + + + + + + + + + + + + + + + + + + + + +