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 #1512

Merged
merged 50 commits into from
Mar 11, 2024

Conversation

legalsylvain
Copy link
Contributor

@legalsylvain legalsylvain commented Feb 9, 2024

This PR try to finish the migration of base_product_mass_addition.
Previsous work done by @aiendry-aktivsoftware in #1393 that has no activity since July 2023.

@ivantodorovich : Do you have a time to take a look on how to reimplement : #1065 ?

Thanks !

@legalsylvain legalsylvain changed the title 16.0 mig base product mass addition [16.0] MIG base_product_mass_addition Feb 9, 2024
@legalsylvain legalsylvain marked this pull request as ready for review February 12, 2024 15:21
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

I take this code doesn't work anymore because of the removal of towrite, right?
I see this has been refactored in odoo/odoo@384fda2

I believe we can keep the same feature, with roughly the same idea, with the necessary changes to adapt for that refactor (using get_dirty_fields and clear_dirty_field instead of directly accessing towrite).

⚠️ I haven't tested this, but I imagine something like this

Suggested change
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)
quick_fnames = ("qty_to_process", "quick_uom_id")
if (
self
and fnames
and any(quick_fname in fnames for quick_fname in quick_fnames)
):
if all(field.name in LOG_ACCESS_COLUMNS for field in self.env.cache.get_dirty_fields()):
for fname in LOG_ACCESS_COLUMNS:
self.env.cache.clear_dirty_field(self._fields[fname])
return super().modified(fnames, create=create, before=before)

The previous implementation did this at a record-level: it conditionally cleared the write cache record by record.

The new suggested implementation would do it at the model level: clearing the cache conditionally if only the log access fields are being updated. It's not as smart as the previous one, but it might work in our specific use case (we won't be updating other product fields anyway)

⚠️ again, not tested

In any case, we could re-implement the exact same behavior if we need to, but we'll have to manipulate the self.env.cache._dirty and self.env.cache._data directly IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @ivantodorovich. Thanks a lot for your time. (analysis and code proposal)
I tested your implementation (see last fixup commit).

Any idea ?

   File "/__w/product-attribute/product-attribute/base_product_mass_addition/tests/test_product_mass_addition.py", line 55, in test_quick_should_not_write_on_product
    self.assertEqual(self.product.write_uid, user_demo)
AssertionError: res.users(1,) != res.users(6,)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I would put a breakpoint there:

            if all(
                field.name in LOG_ACCESS_COLUMNS
                for field in self.env.cache.get_dirty_fields()
            )

And then check why the condition is not matched.

It could be that there's an extra dirty fields in there, during tests. In which case we might need to add some explicit flushes in tests.


Alternatively, it may be due to the simplification of the new implementation:

It's not as smart as the previous one, but it might work in our specific use case (we won't be updating other product fields anyway)

Maybe there are other dirty products in the cache. In which case the solution might be also to flush during tests, or improve the code to restore the previous record-by-record dirty check -- but to do that we'd have to mess with the cache internals as there's no public api for this AFAICS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And then check why the condition is not matched.

i put a breakpoint, and the call of clear_dirty_field is done.
So, self.env.cache.get_dirty_fields() is [write_uid, write_date] at the beginning of the call of modified and when super is executed, it is []. That looks correct. However via test, it doesn't work.

Copy link
Contributor

Choose a reason for hiding this comment

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

However via test, it doesn't work.

What is the output of self.env.cache.get_dirty_fields() during tests, on that breakpoint? still [write_uid, write_date]? 🤔


Alternatively, try adding a flush after this line: https://github.com/grap/product-attribute/blob/8fd402d307148407b9bee52d754ff4c8daf77197/base_product_mass_addition/tests/test_product_mass_addition.py#L52

Perhaps the issue is there, in the unit tests. As we might be dropping the cache modified by the previous line

Copy link

@FranzPoize FranzPoize Feb 22, 2024

Choose a reason for hiding this comment

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

Hi as said in the original PR (#1393 (comment)) the tests does not work because it is not possible to change the value of all log_access field.

I wrote a PR to your branch @legalsylvain to fix the test grap#2

@legalsylvain
Copy link
Contributor Author

/ocabot rebase

@OCA-git-bot
Copy link
Contributor

Sorry @legalsylvain you are not allowed to rebase.

To do so you must either have push permissions on the repository, or be a declared maintainer of all modified addons.

If you wish to adopt an addon and become it's maintainer, open a pull request to add your GitHub login to the maintainers key of its manifest.

@legalsylvain legalsylvain force-pushed the 16.0-mig-base_product_mass_addition branch from e32dfb5 to 36c70d9 Compare February 28, 2024 11:46
angel and others added 13 commits February 28, 2024 12:47
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: product-attribute-15.0/product-attribute-15.0-base_product_mass_addition
Translate-URL: https://translation.odoo-community.org/projects/product-attribute-15-0/product-attribute-15-0-base_product_mass_addition/
Currently translated at 100.0% (10 of 10 strings)

Translation: product-attribute-15.0/product-attribute-15.0-base_product_mass_addition
Translate-URL: https://translation.odoo-community.org/projects/product-attribute-15-0/product-attribute-15-0-base_product_mass_addition/es/
Currently translated at 100.0% (10 of 10 strings)

Translation: product-attribute-15.0/product-attribute-15.0-base_product_mass_addition
Translate-URL: https://translation.odoo-community.org/projects/product-attribute-15-0/product-attribute-15-0-base_product_mass_addition/it/
[REF] Remove call to flush that are obsolete, in tests.
… the same way, to remove the errror : '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.

'
@legalsylvain legalsylvain force-pushed the 16.0-mig-base_product_mass_addition branch from 36c70d9 to c1a9bb4 Compare February 28, 2024 11:49
@legalsylvain
Copy link
Contributor Author

@bealdav Could you review this one ? As you need it for sale_quick ? Thanks !

Copy link
Member

@bealdav bealdav left a comment

Choose a reason for hiding this comment

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

LGTM

@bealdav
Copy link
Member

bealdav commented Mar 8, 2024

Thanks a lot @legalsylvain for your decisive implication on this topic

@legalsylvain
Copy link
Contributor Author

Thanks a lot @legalsylvain for your decisive implication on this topic

you're welcome !

Note : I have updated readme, and I have adopted the module in the last commits.

I think this PR could be merged, CC : @OCA/product-maintainers

@legalsylvain
Copy link
Contributor Author

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-1512-by-legalsylvain-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit b8fe68c into OCA:16.0 Mar 11, 2024
7 of 9 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 0b861f6. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.