Skip to content

Commit

Permalink
[ADD] product_uom_measure_type module
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Sep 16, 2021
1 parent 6f9bb7e commit 405bb49
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 19 deletions.
4 changes: 4 additions & 0 deletions product_uom_measure_type/README.rst
@@ -0,0 +1,4 @@
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 changes: 2 additions & 0 deletions product_uom_measure_type/__init__.py
@@ -0,0 +1,2 @@
from . import models
from .hooks import pre_init_hook
21 changes: 21 additions & 0 deletions product_uom_measure_type/__manifest__.py
@@ -0,0 +1,21 @@
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Product - UoM Measure Type",
"version": "12.0.1.0.1",
"category": "Product",
"author": "GRAP, Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"website": "http://www.grap.coop",
"license": "AGPL-3",
"depends": [
"product",
],
"data": [
"views/view_product_template.xml",
],
"pre_init_hook": "pre_init_hook",
"installable": True,
}
21 changes: 21 additions & 0 deletions product_uom_measure_type/hooks.py
@@ -0,0 +1,21 @@
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


def pre_init_hook(cr):
"""Quick populate new product.template field 'uom_measure_type'
to avoid slowness if this is done by the ORM, in the case of
installation of this module on a large database.
"""

cr.execute("""
ALTER TABLE product_template
ADD column uom_measure_type character varying;
""")
cr.execute("""
UPDATE product_template
SET uom_measure_type = uom_uom.measure_type
FROM uom_uom
WHERE uom_uom.id = product_template.uom_id
""")
1 change: 1 addition & 0 deletions product_uom_measure_type/models/__init__.py
@@ -0,0 +1 @@
from . import product_template
13 changes: 13 additions & 0 deletions product_uom_measure_type/models/product_template.py
@@ -0,0 +1,13 @@
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

uom_measure_type = fields.Selection(
string="UoM Measure Type",
related="uom_id.measure_type", store=True, readonly=True)
1 change: 1 addition & 0 deletions product_uom_measure_type/readme/CONTRIBUTORS.rst
@@ -0,0 +1 @@
* Sylvain LE GAL (https://www.twitter.com/legalsylvain)
3 changes: 3 additions & 0 deletions product_uom_measure_type/readme/DESCRIPTION.rst
@@ -0,0 +1,3 @@
This module add a simple related field ``uom_measure_type`` that is related to the field
``measure_type`` of the uom category of the main uom of the product.
It is a technical module that doesn't add any feature by itself.
2 changes: 2 additions & 0 deletions product_uom_measure_type/readme/ROADMAP.rst
@@ -0,0 +1,2 @@
* For V14+, the field ``measure_type`` has been removed from odoo product module.
so when porting this module, we should add again this removed field on ``uom.category`` model.
19 changes: 19 additions & 0 deletions product_uom_measure_type/views/view_product_template.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>

<record id="view_product_template_form" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="uom_po_id" position="after">
<field name="uom_measure_type" invisible="1"/>
</field>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions product_uom_po_domain/__manifest__.py
Expand Up @@ -7,6 +7,7 @@
"version": "12.0.1.0.1",
"category": "Product",
"author": "GRAP, Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"website": "http://www.grap.coop",
"license": "AGPL-3",
"depends": [
Expand Down
6 changes: 0 additions & 6 deletions product_uom_po_domain/i18n/fr.po
Expand Up @@ -30,9 +30,3 @@ msgstr ""
#: model:ir.model.fields,field_description:product_uom_po_domain.field_product_template__uom_po_id
msgid "Purchase Unit of Measure"
msgstr ""

#. module: product_uom_po_domain
#: model:ir.model.fields,field_description:product_uom_po_domain.field_product_product__uom_measure_type
#: model:ir.model.fields,field_description:product_uom_po_domain.field_product_template__uom_measure_type
msgid "Type of Measure"
msgstr ""
7 changes: 0 additions & 7 deletions product_uom_po_domain/i18n/product_uom_po_domain.pot
Expand Up @@ -41,10 +41,3 @@ msgstr ""
#: model:ir.model.fields,field_description:product_uom_po_domain.field_product_template__uom_po_id
msgid "Purchase Unit of Measure"
msgstr ""

#. module: product_uom_po_domain
#: model:ir.model.fields,field_description:product_uom_po_domain.field_product_product__uom_measure_type
#: model:ir.model.fields,field_description:product_uom_po_domain.field_product_template__uom_measure_type
msgid "Type of Measure"
msgstr ""

3 changes: 0 additions & 3 deletions product_uom_po_domain/models/product_template.py
Expand Up @@ -11,9 +11,6 @@ class ProductTemplate(models.Model):
uom_category_id = fields.Many2one(
comodel_name="uom.category", related="uom_id.category_id")

uom_measure_type = fields.Selection(
related="uom_id.category_id.measure_type")

# Overload field to add a domain
uom_po_id = fields.Many2one(
domain="[('category_id', '=', uom_category_id)]"
Expand Down
2 changes: 0 additions & 2 deletions product_uom_po_domain/readme/DEVELOP.rst
@@ -1,5 +1,3 @@
Technically, this module add two new related fields on ``product.template`` model,

* ``uom_category_id``, related to ``uom_id.category_id``
* ``uom_measure_type`` related to ``uom_id.category_id.measure_type``. This second field
is a technical field that can be used for other modules.
1 change: 0 additions & 1 deletion product_uom_po_domain/views/view_product_template.xml
Expand Up @@ -12,7 +12,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="arch" type="xml">
<field name="uom_po_id" position="after">
<field name="uom_category_id" invisible="1"/>
<field name="uom_measure_type" invisible="1"/>
</field>
</field>
</record>
Expand Down

0 comments on commit 405bb49

Please sign in to comment.