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

16.0 mig base product mass addition #1393

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a0c4247
[ADD] module base_product_mass_addition
Mar 12, 2019
2193753
[IMP] do not depend on arbitrary view
Mar 19, 2019
7e3bbde
[IMP] make implementations intercompatible
Mar 19, 2019
9e69234
IMP ui and refactor action
bealdav Mar 27, 2019
46f6146
[FIX] Remove non model-agnostic filter
Mar 28, 2019
ab8ba5b
[UPD] README.rst
OCA-git-bot Mar 28, 2019
e394391
[UPD] Update base_product_mass_addition.pot
oca-travis Mar 28, 2019
6051cc6
[ADD] icon.png
OCA-git-bot Apr 3, 2019
590cd49
[UPD] README.rst
OCA-git-bot Jul 29, 2019
071dcf5
[IMP] base_product_mass_addition: black, isort
phuctranfxvn Feb 26, 2020
73061d9
[MIG] base_product_mass_addition: Migration to 13.0
phuctranfxvn Feb 26, 2020
d58eaae
[IMP] base_product_mass_addition: black, isort, prettier
Dec 17, 2020
03cfca9
[MIG] base_product_mass_addition: Migration to 14.0
Dec 17, 2020
631d087
[IMP] optionnaly use onchange_helper
Dec 17, 2020
e6022ab
[IMP] depend on onchange_helper
Jan 14, 2021
ae4015f
[UPD] Update base_product_mass_addition.pot
oca-travis May 9, 2021
d5e8afc
[UPD] README.rst
OCA-git-bot May 9, 2021
5fde75a
[IMP] Add UoM functionality, simplify some code
kevinkhao Mar 15, 2021
0ff0fa8
[IMP] Remove purchase-specific element in function name
kevinkhao Mar 24, 2021
771dfd1
[IMP] Add access rights hack so that users that don't have write acce…
kevinkhao Apr 1, 2021
f700523
[IMP] Remove useless _sync_quick_lines() intermediary
kevinkhao Apr 15, 2021
f335e37
[IMP] use related on quick_uom_category_id
kevinkhao Apr 15, 2021
6700572
[REF] Remove permissions for users that cannot edit product.product. …
kevinkhao Apr 15, 2021
fdea025
[REF] Remove dead code
kevinkhao Apr 19, 2021
6440da6
[REV] Revert rename of _inverse_set_process_qty
kevinkhao Jun 8, 2021
918cb6d
[UPD] Update base_product_mass_addition.pot
oca-travis Jun 14, 2021
4bb8386
[UPD] README.rst
OCA-git-bot Jun 14, 2021
7f77ba8
base_product_mass_addition 14.0.1.1.0
OCA-git-bot Jun 14, 2021
54b2c93
Added translation using Weblate (French)
Kev-Roche Nov 29, 2021
fec9f63
Translated using Weblate (French)
Kev-Roche Nov 29, 2021
fd4a066
Translated using Weblate (French)
Kev-Roche Nov 30, 2021
f30c4ca
[IMP] base_product_mass_addition: avoid writing on product access fields
ivantodorovich Apr 26, 2022
63452ac
[IMP] base_product_mass_addition: Add unit tests
ivantodorovich Apr 26, 2022
c647b9b
[UPD] README.rst
OCA-git-bot Feb 20, 2023
515f93f
base_product_mass_addition 14.0.1.2.0
OCA-git-bot Feb 20, 2023
665b50c
[MIG]base_product_mass_addition: Migration to 15.0
Feb 28, 2023
d88f9ec
[UPD] Update base_product_mass_addition.pot
Apr 5, 2023
76745c2
[UPD] README.rst
OCA-git-bot Apr 5, 2023
d342143
Update translation files
weblate Apr 5, 2023
f25414c
Added translation using Weblate (Spanish)
luis-ron Apr 12, 2023
7426c45
Translated using Weblate (Spanish)
luis-ron Apr 12, 2023
9379dac
[IMP] base_product_mass_addition: pre-commit stuff
aiendry-aktivsoftware Jul 27, 2023
936f18a
[MIG] base_product_mass_addition: Migration to 16.0
aiendry-aktivsoftware Jul 27, 2023
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
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": "15.0.1.0.0",
"version": "16.0.1.0.0",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"license": "AGPL-3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-27 08:23+0000\n"
"PO-Revision-Date: 2023-07-27 08:23+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -42,7 +44,7 @@ msgstr ""

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

#. module: base_product_mass_addition
Expand Down
8 changes: 4 additions & 4 deletions base_product_mass_addition/models/product_mass_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def _prepare_quick_line(self, product):
return res

def _get_quick_line(self, product):
raise NotImplementedError
raise NotImplementedError()

def _add_quick_line(self, product, lines_key=""):
if not lines_key:
raise NotImplementedError
raise NotImplementedError()
vals = self._prepare_quick_line(product)
vals = self._complete_quick_line_vals(vals)
self.write({lines_key: [(0, 0, vals)]})
Expand All @@ -55,11 +55,11 @@ def _update_quick_line(self, product, line):
line.unlink()

def _get_quick_line_qty_vals(self, product):
raise NotImplementedError
raise NotImplementedError()

def _complete_quick_line_vals(self, vals, lines_key=""):
if not lines_key:
raise NotImplementedError
raise NotImplementedError()
init_keys = ["product_id"]
update_vals = {key: val for key, val in vals.items() if key not in init_keys}
lines = getattr(self, lines_key)
Expand Down
42 changes: 18 additions & 24 deletions base_product_mass_addition/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ProductProduct(models.Model):
domain="[('category_id', '=', quick_uom_category_id)]",
compute="_compute_quick_uom_id",
inverse="_inverse_set_process_qty",
store=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: you try to store a field that should be computed on the fly, and not be stored. I guess something is wrong with that design. could you explain that change ? Thanks !

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the issue without store=True

tests/test_product_mass_addition.py::TestProductMassAddition::test_quick_line_add
  /odoo/src/odoo/fields.py:808: UserWarning: Field product.product.quick_uom_id in dependency of product.product.quick_uom_category_id should be searchable. This is necessary to determine which records to recompute when uom.uom.category_id is modified. You should either make the field searchable, or simplify the field dependency.

It seems there is some kind of dependency race on this.

However I'm not sure there is a need to have the quick_uom_category_id field since it's not use anywhere in the module and it could be accessed via quick_uom_id.category_id

Copy link

@FranzPoize FranzPoize Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way the store=True breaks functionnality on downstream module it sometimes lead to a None valued uom_id on the product

)

def _inverse_set_process_qty(self):
Expand All @@ -38,41 +39,34 @@ def _inverse_set_process_qty(self):
else:
parent._add_quick_line(product, quick_line._name)

def modified(self, fnames, create=False, before=False):
def write(self, vals):
# OVERRIDE to supress LOG_ACCESS_COLUMNS writes if we're only writing on quick
# magic fields, as they could lead to concurrency issues.
#
# Moreover, from a functional perspective, these magic fields aren't really
# modifying the product's data so it doesn't make sense to update its metadata.
#
# We achieve it by reverting the changes made by ``write`` [^1], before [^2]
# reaching any explicit flush [^3] or inverse computation [^4].
# We achieve it by stopping the ``write`` [^1] to modify LOG_ACCESS_COLUMNS.
# By changing the log access rights ``_log_access``
#
# [^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
# https://github.com/odoo/odoo/blob/dab802a939c97603f70c504e98ecc92b0ac552f9/odoo/models.py#L3677C1-L3679C61 # 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 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]
if not vals: # pragma: no cover
continue
if all(fname in LOG_ACCESS_COLUMNS for fname in vals.keys()):
towrite.pop(record.id)
return super().modified(fnames, create=create, before=before)
if self and any(quick_fname in vals.keys() for quick_fname in quick_fnames):
cr = self.env.cr
Model = self._build_model(self.pool, cr)
Model._auto = False
Model._log_access = set(list([]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Model._log_access = set(list([]))
Model._log_access = set()

is the same, no ?

res = super(ProductProduct, self).write(vals)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
res = super(ProductProduct, self).write(vals)
res = super().write(vals)

if not self._log_access:
cr = self.env.cr
Model = self._build_model(self.pool, cr)
Model._auto = True
Model._log_access = set(LOG_ACCESS_COLUMNS)
return res

@property
def pma_parent(self):
Expand All @@ -83,7 +77,7 @@ def pma_parent(self):
return self.env[parent_model].browse(parent_id)

def _default_quick_uom_id(self):
raise NotImplementedError
raise NotImplementedError()

def _compute_quick_uom_id(self):
parent = self.pma_parent
Expand Down
1 change: 1 addition & 0 deletions base_product_mass_addition/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Akretion
* `Sygel <https://www.sygel.es>`_:

* Ángel García de la Chica Herrera <[email protected]>
* Aiendry Sarkar <[email protected]>
14 changes: 7 additions & 7 deletions base_product_mass_addition/tests/test_product_mass_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ def test_quick_should_not_write_on_product(self):
"""Using quick magic fields shouldn't write on product's metadata"""
user_demo = self.env.ref("base.user_demo")
self.product.write_uid = user_demo
self.env["base"].flush()
self.env["base"].flush_model()
self.assertEqual(self.product.write_uid, user_demo)
# Case 1: Updating qty_to_process shouldn't write on products
self.product.qty_to_process = 1.0
self.env["base"].flush()
self.env["base"].flush_model()
self.assertEqual(self.product.write_uid, user_demo)
# 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.env["base"].flush_model()
self.assertEqual(self.product.write_uid, user_demo)

def test_quick_should_write_on_product(self):
Expand All @@ -68,20 +68,20 @@ def test_quick_should_write_on_product(self):
# 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.env["base"].flush_model()
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.env["base"].flush_model()
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.env["base"].flush_model()
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.env["base"].flush_model()
self.assertEqual(self.product.write_uid, self.env.user)
Loading