Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.0][NEW] product_secondary_unit: New module for set a second units for a product #377

Merged
merged 2 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions product_secondary_unit/README.rst
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.
2 changes: 2 additions & 0 deletions product_secondary_unit/__init__.py
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
21 changes: 21 additions & 0 deletions product_secondary_unit/__manifest__.py
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',
],
}
106 changes: 106 additions & 0 deletions product_secondary_unit/i18n/es.po
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"
3 changes: 3 additions & 0 deletions product_secondary_unit/models/__init__.py
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
36 changes: 36 additions & 0 deletions product_secondary_unit/models/product_second_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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)
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, "{uom_to}-{factor}".format(
uom_to=unit.uom_id.name,
factor=unit.factor))
)
return result
18 changes: 18 additions & 0 deletions product_secondary_unit/models/product_template.py
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',
)
2 changes: 2 additions & 0 deletions product_secondary_unit/readme/CONTRIBUTORS.rst
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>
2 changes: 2 additions & 0 deletions product_secondary_unit/readme/DESCRIPTION.rst
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.
5 changes: 5 additions & 0 deletions product_secondary_unit/readme/USAGE.rst
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.
2 changes: 2 additions & 0 deletions product_secondary_unit/security/ir.model.access.csv
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,0,0,0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions product_secondary_unit/tests/__init__.py
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
33 changes: 33 additions & 0 deletions product_secondary_unit/tests/test_product_second_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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, {
'name': 'unit-700',
'uom_id': cls.product_uom_unit.id,
'factor': 0.7,
})],
})
secondary_unit = cls.env['product.secondary.unit'].search([
('product_tmpl_id', '=', cls.product.id),
])
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(s)-0.7')
31 changes: 31 additions & 0 deletions product_secondary_unit/views/product_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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="name"/>
<field name="uom_id"/>
<field name="factor"/>
</tree>
</field>
</group>
</xpath>
</field>
</record>

</odoo>