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.
  • Loading branch information
legalsylvain committed Jan 12, 2024
1 parent cd346b2 commit 4227404
Show file tree
Hide file tree
Showing 29 changed files with 204 additions and 160 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:d0588271e4794672124527207be34c884c67df26865a8d46ac87304217eb1321
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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
14 changes: 3 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,16 @@
# 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"],
"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 categ.to_weight = True;
"""
)
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"
)
12 changes: 4 additions & 8 deletions pos_to_weight_by_product_uom/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
* 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:: ../static/description/uom_categ_change_toweigh.png
:alt: Change the field 'To weigh' for every category
.. image:: ../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:: ../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.
26 changes: 2 additions & 24 deletions pos_to_weight_by_product_uom/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,5 @@ 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:: ../static/description/uom_categ_toweigh.png
:alt: Categories of unities of measure
:width: 900


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

.. image:: ../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:: ../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:: ../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.
4 changes: 2 additions & 2 deletions pos_to_weight_by_product_uom/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
You're able to change this field for a specific product (in tab Sales).

.. image:: ../static/description/uom_pos_change_toweigh.png
:alt: Change the field 'to weigh' for a specific
.. image:: ../static/description/product_form.png
:alt: Change the field 'To Weigh With Scale' for a specific
:width: 300
Binary file not shown.
25 changes: 7 additions & 18 deletions pos_to_weight_by_product_uom/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,22 +367,14 @@ <h1 class="title">Pos to weight by product uom</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6f9e6ba0ce290365bff3a9348cc6ea3f4dd763e39d0174c842a23d42a465471f
!! source digest: sha256:d0588271e4794672124527207be34c884c67df26865a8d46ac87304217eb1321
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/pos/tree/16.0/pos_to_weight_by_product_uom"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_to_weight_by_product_uom"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/pos&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>At the moment, when we create a new product and choose the unity of measure <strong>kg</strong>,
we have to tick the checkbox ‘To Weigh With Scale’ in the Point of Sale part.</p>
<p>We want to speed the process of creating a new product, avoiding filling manually this parameter.</p>
<p>This module adds the field <strong>‘To weigh’</strong> in UOM categories (set to <strong>false</strong> by default).</p>
<img alt="Categories of unities of measure" src="https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_categ_toweigh.png" style="width: 900px;" />
<p><strong></strong> This field affects every unities contained in this category.</p>
<img alt="Unities of measure with field 'To weigh'" src="https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_toweigh.png" style="width: 900px;" />
<p><strong></strong> <strong>AND</strong> it is linked with the parameter <strong>to_weight</strong> in product.template used for example in the Point of Sale app.</p>
<img alt="Change the field 'to weigh' for every product" src="https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_pos_change_toweigh_checked.png" style="width: 300px;" />
<ul class="simple">
<li>You <strong>CAN’T</strong> change ‘To weigh’ for one UOM → You have to change in Category and affect all UOM of this category.</li>
</ul>
<img alt="Can't change the field 'to weigh' for one unity of measure" src="https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_change_toweigh.png" style="width: 900px;" />
<p>This module adds the field <strong>‘To Weigh With Scale’</strong> in UOM categories (set to <strong>false</strong> by default).
If checked, all products created with a related Unit will be ‘To Weigh With Scale’, by default.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -401,18 +393,15 @@ <h1 class="title">Pos to weight by product uom</h1>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<ul class="simple">
<li>active settings “Allow using different units of measure” in Settings &gt; Configuration &gt; Sales &gt; Quotations and Sales Orders &gt; Product Features</li>
<li>During the creation of a category, tick the box ‘To weigh’.</li>
</ul>
<img alt="Change the field 'To weigh' for every category" src="https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_categ_change_toweigh.png" style="width: 400px;" />
<ul class="simple">
<li>You can set every product existing with the new ‘To weigh’ parameter</li>
<li>During the creation of a category, tick the box ‘To Weigh With Scale’.</li>
</ul>
<img alt="Set 'to weigh' in each product of this category" src="https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_categ_button_toweigh.png" style="width: 900px;" />
<img alt="Change the field 'To Weigh With Scale' for every weighable category" src="https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_category_form.png" style="width: 400px;" />
<p>Note: During the installation, the UoM Category ‘Weight’ is checked.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>You’re able to change this field for a specific product (in tab Sales).</p>
<img alt="Change the field 'to weigh' for a specific" src="https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/uom_pos_change_toweigh.png" style="width: 300px;" />
<img alt="Change the field 'To Weigh With Scale' for a specific" src="https://github.com/OCA/pos/16.0/pos_to_weight_by_product_uom/static/description/product_form.png" style="width: 300px;" />
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions pos_to_weight_by_product_uom/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_module
Loading

0 comments on commit 4227404

Please sign in to comment.