Skip to content

Commit

Permalink
[MIG]base_product_mass_addition: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
angel authored and legalsylvain committed Feb 28, 2024
1 parent 45ed8cb commit 878474e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion base_product_mass_addition/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Base Product Mass Addition",
"version": "14.0.1.2.0",
"version": "15.0.1.0.0",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"license": "AGPL-3",
Expand Down
18 changes: 13 additions & 5 deletions base_product_mass_addition/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,23 @@ def modified(self, fnames, create=False, before=False):
# We achieve it by reverting the changes made by ``write`` [^1], before [^2]
# reaching any explicit flush [^3] or inverse computation [^4].
#
# [^1]: https://github.com/odoo/odoo/blob/f74434c6f/odoo/models.py#L3652-L3663
# [^2]: https://github.com/odoo/odoo/blob/f74434c6f/odoo/models.py#L3686
# [^3]: https://github.com/odoo/odoo/blob/f74434c6f/odoo/models.py#L3689
# [^4]: https://github.com/odoo/odoo/blob/f74434c6f/odoo/models.py#L3703
# [^1]:
# https://github.com/odoo/odoo/blob/3991737a53e75398fcf70b1924525783b54d256b/odoo/models.py#L3778-L3787 # noqa: B950
# [^2]:
# https://github.com/odoo/odoo/blob/3991737a53e75398fcf70b1924525783b54d256b/odoo/models.py#L3882 # noqa: B950
# [^3]:
# https://github.com/odoo/odoo/blob/3991737a53e75398fcf70b1924525783b54d256b/odoo/models.py#L3885 # noqa: B950
# [^4]:
# https://github.com/odoo/odoo/blob/f74434c6f4303650e886d99fb950c763f2d4cc6e/odoo/models.py#L3703 # noqa: B950
#
# Basically, if all we're modifying are quick magic fields, and we don't have
# any other column to flush besides the LOG_ACCESS_COLUMNS, clear it.
quick_fnames = ("qty_to_process", "quick_uom_id")
if self and fnames and all(fname in quick_fnames for fname in fnames):
if (
self
and fnames
and any(quick_fname in fnames for quick_fname in quick_fnames)
):
for record in self.filtered("id"):
towrite = self.env.all.towrite[self._name]
vals = towrite[record.id]
Expand Down
4 changes: 4 additions & 0 deletions base_product_mass_addition/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ Akretion
* `Camptocamp <https://www.camptocamp.com>`_

* Iván Todorovich <[email protected]>

* `Sygel <https://www.sygel.es>`_:

* Ángel García de la Chica Herrera <[email protected]>
32 changes: 29 additions & 3 deletions base_product_mass_addition/tests/test_product_mass_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from odoo_test_helper import FakeModelLoader

from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


class TestProductMassAddition(SavepointCase):
class TestProductMassAddition(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -55,7 +55,33 @@ def test_quick_should_not_write_on_product(self):
self.product.qty_to_process = 1.0
self.env["base"].flush()
self.assertEqual(self.product.write_uid, user_demo)
# Case 2: Updating other fields should still work
# Case 2: Updating quick_uom_id shouldn't write on products
self.product.quick_uom_id = self.env.ref("uom.product_uom_categ_unit").uom_ids[
1
]
self.env["base"].flush()
self.assertEqual(self.product.write_uid, user_demo)

def test_quick_should_write_on_product(self):
"""Updating fields that are not magic fields should update
product metadata"""
# Change the product write_uid for testing
user_demo = self.env.ref("base.user_demo")
self.product.write_uid = user_demo
self.env["base"].flush()
self.assertEqual(self.product.write_uid, user_demo)
# Case 1: Updating name field should write on product's metadata
self.product.name = "Testing"
self.env["base"].flush()
self.assertEqual(self.product.write_uid, self.env.user)
# Change the product write_uid for testing
user_demo = self.env.ref("base.user_demo")
self.product.write_uid = user_demo
self.env["base"].flush()
self.assertEqual(self.product.write_uid, user_demo)
# Case 2: Updating qty_to_process and name before flush should
# write on product's metadata
self.product.qty_to_process = 2.0
self.product.name = "Testing 2"
self.env["base"].flush()
self.assertEqual(self.product.write_uid, self.env.user)
2 changes: 1 addition & 1 deletion base_product_mass_addition/views/product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="model">product.product</field>
<field eval="20" name="priority" />
<field name="arch" type="xml">
<tree string="Products" create="0" editable="top">
<tree create="0" editable="top">
<field name="lst_price" readonly="1" />
<field name="categ_id" readonly="1" />
<field name="display_name" readonly="1" />
Expand Down

0 comments on commit 878474e

Please sign in to comment.