forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[11.0][NEW] product_secondary_unit: New module for setting a secondar…
…y unit for a product (OCA#377)
- Loading branch information
1 parent
715ed44
commit ba7a66f
Showing
15 changed files
with
378 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://github.com/OCA/product-attribute/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 <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_secondary_unit%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Carlos Dauden <carlos.dauden@tecnativa.com> | ||
* Sergio Teruel <sergio.teruel@tecnativa.com> | ||
|
||
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 <https://github.com/OCA/product-attribute/tree/11.0/product_secondary_unit>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Carlos Dauden <carlos.dauden@tecnativa.com> | ||
* Sergio Teruel <sergio.teruel@tecnativa.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This module extends the functionality of product module to allow define | ||
other units with their conversion factor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from . import test_product_second_unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2018 Tecnativa - Sergio Teruel | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
|
||
<record id="product_template_form_view" model="ir.ui.view"> | ||
<field name="name">Product template Secondary Unit</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="product.product_template_form_view"/> | ||
<field name="groups_id" eval="[(4, ref('product.group_uom'))]"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='uom_id']" position="after"> | ||
<field name="sale_secondary_uom_id" | ||
domain="[('product_tmpl_id', '=', id)]" | ||
options="{'no_create': True}"/> | ||
</xpath> | ||
<xpath expr="//page[@name='general_information']" position="inside"> | ||
<group string="secondary unit of measure"> | ||
<field name="secondary_uom_ids" nolabel="1"> | ||
<tree string="secondary Unit" editable="top"> | ||
<field name="code"/> | ||
<field name="name"/> | ||
<field name="uom_id"/> | ||
<field name="factor"/> | ||
</tree> | ||
</field> | ||
</group> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |