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

[18.0][MIG] product_uom_updatable: Migration to 18.0 #1790

Open
wants to merge 13 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
95 changes: 95 additions & 0 deletions product_uom_updatable/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
=====================
Product Uom Updatable
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:fe7aa0456f147d9cc06288c74d7f179d26dd7fcb22908c2a35a70c086c1b62ea
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/18.0/product_uom_updatable
: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-18-0/product-attribute-18-0-product_uom_updatable
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Allow to change the product UoM if the new UoM is in the same category
and has the same factor.

**Table of contents**

.. contents::
:local:

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_uom_updatable%0Aversion:%2018.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
-------

* ACSONE SA/NV
* Camptocamp

Contributors
------------

- Anna Janiszewska <[email protected]>

- [Trobz] (https://trobz.com/):

- Dung Tran <[email protected]>
- Khoi (Kien Kim) <[email protected]>

- Hughes Damry <[email protected]>

Other credits
-------------

The development of this module has been financially supported by:

- Camptocamp

The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.

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/18.0/product_uom_updatable>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_uom_updatable/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions product_uom_updatable/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Acsone SA/NV
# Copyright 2020 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Product Uom Updatable",
"summary": """
allows products uom to be modified after be used in a stock picking if
the product uom is of the same category""",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV, Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"depends": ["stock"],
}
33 changes: 33 additions & 0 deletions product_uom_updatable/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_uom_updatable
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-04-27 11:19+0000\n"
"Last-Translator: Sebastiano Picchi <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.14.1\n"

#. module: product_uom_updatable
#: model:ir.model,name:product_uom_updatable.model_product_template
msgid "Product"
msgstr "Prodotto"

#. module: product_uom_updatable
#. odoo-python
#: code:addons/product_uom_updatable/models/product_template.py:0
#, python-format
msgid ""
"You cannot change the unit of measure of a product to a new unit that "
"doesn't have the same category and factor"
msgstr ""
"Non puoi cambiare l'unità di misura di un prodotto ad una nuova unità che "
"non ha la stessa categoria e fattore"
28 changes: 28 additions & 0 deletions product_uom_updatable/i18n/product_uom_updatable.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_uom_updatable
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \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: product_uom_updatable
#: model:ir.model,name:product_uom_updatable.model_product_template
msgid "Product"
msgstr ""

#. module: product_uom_updatable
#. odoo-python
#: code:addons/product_uom_updatable/models/product_template.py:0
#, python-format
msgid ""
"You cannot change the unit of measure of a product to a new unit that "
"doesn't have the same category and factor"
msgstr ""
1 change: 1 addition & 0 deletions product_uom_updatable/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_template
59 changes: 59 additions & 0 deletions product_uom_updatable/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2020 Acsone SA/NV
# Copyright 2020 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from itertools import groupby

from odoo import models
from odoo.exceptions import UserError
from odoo.tools import SQL


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

def write(self, vals):
uom_id = vals.pop("uom_id", False)
uom_po_id = vals.pop("uom_po_id", False)
if uom_id:
self._update_uom(uom_id, "uom_id")
if uom_po_id:
self._update_uom(uom_po_id, "uom_po_id")
res = super().write(vals)
return res

def _update_uom(self, uom_id, field_name):
uom_obj = self.env["uom.uom"]
new_uom = uom_obj.browse(uom_id)
sorted_items = sorted(self, key=lambda r: r[field_name])

for key, products_group in groupby(sorted_items, key=lambda r: r[field_name]):
product_ids = [p.id for p in products_group]

if (
key.category_id == new_uom.category_id
and key.factor_inv == new_uom.factor_inv
):
# pylint: disable=sql-injection
self.env.cr.execute(
SQL(
"""
UPDATE product_template
SET %(field)s = %(new_uom)s
WHERE id IN %(product_ids)s
""",
field=SQL.identifier(field_name),
new_uom=new_uom.id,
product_ids=tuple(product_ids),
)
)
products = self.env["product.template"].browse(product_ids)
products.invalidate_recordset(fnames=[field_name])
else:
raise UserError(
self.env._(
"You cannot change the unit of measure of a product "
"to a new unit that doesn't have the same category "
"and factor"
)
)
3 changes: 3 additions & 0 deletions product_uom_updatable/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
7 changes: 7 additions & 0 deletions product_uom_updatable/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Anna Janiszewska \<<[email protected]>\>

- [Trobz] (https://trobz.com/):
- Dung Tran \<<[email protected]>\>
- Khoi (Kien Kim) \<<[email protected]>\>

- Hughes Damry \<<[email protected]>\>
5 changes: 5 additions & 0 deletions product_uom_updatable/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The development of this module has been financially supported by:

- Camptocamp

The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.
2 changes: 2 additions & 0 deletions product_uom_updatable/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow to change the product UoM if the new UoM is in the same category
and has the same factor.
Binary file added product_uom_updatable/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading