Skip to content

Commit

Permalink
[MIG] pos_to_weight_by_product_uom: Migration to 16.0
Browse files Browse the repository at this point in the history
- REM : remove various useless code (demo group, development status, etc...)
- IMP : Handle create and write use cases.
- ADD : Tests.
- IMP : hook, to initialize 'Weight' UoM Category, and check 'to_weight' on all related product templates
- REF : Rename 'to_weigh' field into 'to_weight' field, to match odoo nomenclature.
- UPD : readme and screenshots
  • Loading branch information
legalsylvain committed Jan 12, 2024
1 parent cd346b2 commit 42d8196
Show file tree
Hide file tree
Showing 31 changed files with 233 additions and 220 deletions.
44 changes: 9 additions & 35 deletions pos_to_weight_by_product_uom/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Pos to weight by product uom
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6f9e6ba0ce290365bff3a9348cc6ea3f4dd763e39d0174c842a23d42a465471f
!! source digest: sha256:7d8aba595011f0cb3cf50dd45e713201a5dbd8df303cffcde4efd31cdd7792fd
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -34,30 +34,8 @@ we have to tick the checkbox 'To Weigh With Scale' in the Point of Sale part.
We want to speed the process of creating a new product, avoiding filling manually this parameter.


This module adds the field **'To weigh'** in UOM categories (set to **false** by default).

.. image:: https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_categ_toweigh.png
:alt: Categories of unities of measure
:width: 900


**** This field affects every unities contained in this category.

.. image:: https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_toweigh.png
:alt: Unities of measure with field 'To weigh'
:width: 900

**** **AND** it is linked with the parameter **to_weight** in product.template used for example in the Point of Sale app.

.. image:: https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_pos_change_toweigh_checked.png
:alt: Change the field 'to weigh' for every product
:width: 300

* You **CAN'T** change 'To weigh' for one UOM → You have to change in Category and affect all UOM of this category.

.. image:: https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_change_toweigh.png
:alt: Can't change the field 'to weigh' for one unity of measure
:width: 900
This module adds the field **'To Weigh With Scale'** in UOM categories (set to **false** by default).
If checked, all products created with a related Unit will be 'To Weigh With Scale', by default.

**Table of contents**

Expand All @@ -70,25 +48,21 @@ Configuration
* active settings "Allow using different units of measure" in Settings > Configuration > Sales > Quotations and Sales Orders > Product Features


* During the creation of a category, tick the box 'To weigh'.
* During the creation of a category, tick the box 'To Weigh With Scale'.

.. image:: https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_categ_change_toweigh.png
:alt: Change the field 'To weigh' for every category
.. image:: https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_category_form.png
:alt: Change the field 'To Weigh With Scale' for every weighable category
:width: 400

* You can set every product existing with the new 'To weigh' parameter

.. image:: https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_categ_button_toweigh.png
:alt: Set 'to weigh' in each product of this category
:width: 900
Note: During the installation, the UoM Category 'Weight' is checked.

Usage
=====

You're able to change this field for a specific product (in tab Sales).

.. image:: https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_pos_change_toweigh.png
:alt: Change the field 'to weigh' for a specific
.. image:: https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/product_form.png
:alt: Change the field 'To Weigh With Scale' for a specific
:width: 300

Bug Tracker
Expand Down
3 changes: 1 addition & 2 deletions pos_to_weight_by_product_uom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
from .hooks import post_init_hook
15 changes: 4 additions & 11 deletions pos_to_weight_by_product_uom/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Pos to weight by product uom",
"summary": "Make 'To Weight' default value" " depending on product UoM settings",
"version": "12.0.1.0.1",
"summary": "Make 'To Weight' default value depending on product UoM settings",
"version": "16.0.1.0.0",
"website": "https://github.com/OCA/pos",
"author": "GRAP, Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"development_status": "Beta",
"license": "AGPL-3",
"installable": True,
"depends": [
"point_of_sale",
],
"depends": ["point_of_sale"],
"post_init_hook": "post_init_hook",
"data": [
"views/view_uom_uom.xml",
"views/view_uom_category.xml",
],
"demo": [
"demo/res_groups.xml",
"demo/uom_category.xml",
"demo/uom_uom.xml",
],
}
10 changes: 0 additions & 10 deletions pos_to_weight_by_product_uom/demo/res_groups.xml

This file was deleted.

11 changes: 0 additions & 11 deletions pos_to_weight_by_product_uom/demo/uom_category.xml

This file was deleted.

13 changes: 0 additions & 13 deletions pos_to_weight_by_product_uom/demo/uom_uom.xml

This file was deleted.

23 changes: 23 additions & 0 deletions pos_to_weight_by_product_uom/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def post_init_hook(cr, registry):
cr.execute(
"""
UPDATE uom_category
SET to_weight = true
WHERE id = (
SELECT res_id
FROM ir_model_data
WHERE module = 'uom'
AND name = 'product_uom_categ_kgm'
);"""
)

cr.execute(
"""
UPDATE product_template
SET to_weight = true
FROM uom_uom, uom_category
WHERE uom_uom.id = product_template.uom_id
AND uom_category.id = uom_uom.category_id
AND uom_category.to_weight = True;
"""
)
50 changes: 16 additions & 34 deletions pos_to_weight_by_product_uom/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -1,60 +1,42 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_to_weight_by_product_uom
# * pos_to_weight_by_product_uom
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-11-13 12:19+0000\n"
"PO-Revision-Date: 2017-11-13 12:19+0000\n"
"Last-Translator: <>\n"
"POT-Creation-Date: 2024-01-12 22:44+0000\n"
"PO-Revision-Date: 2024-01-12 22:44+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: pos_to_weight_by_product_uom
#: model:uom.category,name:pos_to_weight_by_product_uom.uom_category_to_weigh
msgid "Demo - New Category To Weigh"
msgstr "Demo - Nouvelle Catégorie à peser"

#. module: pos_to_weight_by_product_uom
#: model:uom.uom,name:pos_to_weight_by_product_uom.uom_uom_to_weigh
msgid "Demo - New Uom To Weigh"
msgstr "Demo - Nouvelle UdM à peser"

#. module: pos_to_weight_by_product_uom
#: model:ir.model,name:pos_to_weight_by_product_uom.model_product_product
#, fuzzy
msgid "Product"
msgstr "Modèle d'article"

#. module: pos_to_weight_by_product_uom
#: model:ir.model,name:pos_to_weight_by_product_uom.model_product_template
msgid "Product Template"
msgstr "Modèle d'article"
msgid "Product"
msgstr "Produit"

#. module: pos_to_weight_by_product_uom
#: model:ir.model,name:pos_to_weight_by_product_uom.model_uom_uom
msgid "Product Unit of Measure"
msgstr "Unité de mesure d'article"
msgstr "Unité de mesure du produit"

#. module: pos_to_weight_by_product_uom
#: model:ir.model,name:pos_to_weight_by_product_uom.model_uom_category
#, fuzzy
msgid "Product UoM Categories"
msgstr "Catégorie d'UdM d'article"
msgstr "Catégorie d'UdM"

#. module: pos_to_weight_by_product_uom
#: model_terms:ir.ui.view,arch_db:pos_to_weight_by_product_uom.view_uom_category_form
msgid "Set 'to weigh' in each product of this category"
msgstr ""
#: model:ir.model,name:pos_to_weight_by_product_uom.model_product_product
msgid "Product Variant"
msgstr "Variante de produit"

#. module: pos_to_weight_by_product_uom
#: model:ir.model.fields,field_description:pos_to_weight_by_product_uom.field_uom_category__to_weigh
#: model:ir.model.fields,field_description:pos_to_weight_by_product_uom.field_uom_uom__to_weigh
msgid "To weigh"
msgstr "À peser"
#: model:ir.model.fields,field_description:pos_to_weight_by_product_uom.field_uom_category__to_weight
#: model:ir.model.fields,field_description:pos_to_weight_by_product_uom.field_uom_uom__to_weight
msgid "To Weigh With Scale"
msgstr "À peser avec une balance"
38 changes: 12 additions & 26 deletions pos_to_weight_by_product_uom/i18n/pos_to_weight_by_product_uom.pot
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_to_weight_by_product_uom
# * pos_to_weight_by_product_uom
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"POT-Creation-Date: 2024-01-12 22:45+0000\n"
"PO-Revision-Date: 2024-01-12 22:45+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: pos_to_weight_by_product_uom
#: model:uom.category,name:pos_to_weight_by_product_uom.uom_category_to_weigh
msgid "Demo - New Category To Weigh"
msgstr ""

#. module: pos_to_weight_by_product_uom
#: model:uom.uom,name:pos_to_weight_by_product_uom.uom_uom_to_weigh
msgid "Demo - New Uom To Weigh"
msgstr ""

#. module: pos_to_weight_by_product_uom
#: model:ir.model,name:pos_to_weight_by_product_uom.model_product_product
msgid "Product"
msgstr ""

#. module: pos_to_weight_by_product_uom
#: model:ir.model,name:pos_to_weight_by_product_uom.model_product_template
msgid "Product Template"
msgid "Product"
msgstr ""

#. module: pos_to_weight_by_product_uom
Expand All @@ -44,13 +31,12 @@ msgid "Product UoM Categories"
msgstr ""

#. module: pos_to_weight_by_product_uom
#: model_terms:ir.ui.view,arch_db:pos_to_weight_by_product_uom.view_uom_category_form
msgid "Set 'to weigh' in each product of this category"
#: model:ir.model,name:pos_to_weight_by_product_uom.model_product_product
msgid "Product Variant"
msgstr ""

#. module: pos_to_weight_by_product_uom
#: model:ir.model.fields,field_description:pos_to_weight_by_product_uom.field_uom_category__to_weigh
#: model:ir.model.fields,field_description:pos_to_weight_by_product_uom.field_uom_uom__to_weigh
msgid "To weigh"
msgstr ""

#: model:ir.model.fields,field_description:pos_to_weight_by_product_uom.field_uom_category__to_weight
#: model:ir.model.fields,field_description:pos_to_weight_by_product_uom.field_uom_uom__to_weight
msgid "To Weigh With Scale"
msgstr ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024, Grap
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

_field_renames = [
(
"uom.uom",
"uom_uom",
"to_weigh",
"to_weight",
),
(
"uom.category",
"uom_category",
"to_weigh",
"to_weight",
),
]


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_fields(env, _field_renames)
4 changes: 2 additions & 2 deletions pos_to_weight_by_product_uom/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ProductProduct(models.Model):

@api.onchange("uom_id", "uom_po_id")
def _onchange_uom(self):
res = super(ProductProduct, self)._onchange_uom()
res = super()._onchange_uom()
if self.uom_id:
self.to_weight = self.uom_id.to_weigh
self.to_weight = self.uom_id.category_id.to_weight
return res
18 changes: 16 additions & 2 deletions pos_to_weight_by_product_uom/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ class ProductTemplate(models.Model):

@api.onchange("uom_id")
def _onchange_uom_id(self):
res = super(ProductTemplate, self)._onchange_uom_id()
res = super()._onchange_uom_id()
if self.uom_id:
self.to_weight = self.uom_id.to_weigh
self.to_weight = self.uom_id.category_id.to_weight
return res

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if "uom_id" in vals and "to_weight" not in vals:
uom = self.env["uom.uom"].browse(vals["uom_id"])
vals["to_weight"] = uom.category_id.to_weight
return super().create(vals_list)

def write(self, vals):
if "uom_id" in vals and "to_weight" not in vals:
uom = self.env["uom.uom"].browse(vals["uom_id"])
vals["to_weight"] = uom.category_id.to_weight
return super().write(vals)
11 changes: 2 additions & 9 deletions pos_to_weight_by_product_uom/models/uom_category.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# Copyright 2017, Grap
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models


class UomCategory(models.Model):
_inherit = "uom.category"

to_weigh = fields.Boolean("To weigh", default=False)

@api.multi
def action_recompute_to_weigh(self):
for categ in self:
domain = [("uom_id.category_id", "=", categ.id)]
products = self.env["product.template"].search(domain)
products.write({"to_weight": categ.to_weigh})
to_weight = fields.Boolean(string="To Weigh With Scale")
4 changes: 3 additions & 1 deletion pos_to_weight_by_product_uom/models/uom_uom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
class UomUom(models.Model):
_inherit = "uom.uom"

to_weigh = fields.Boolean(related="category_id.to_weigh", readonly=True)
to_weight = fields.Boolean(
string="To Weigh With Scale", related="category_id.to_weight"
)
Loading

0 comments on commit 42d8196

Please sign in to comment.