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][FIX] product_abc_classification_sale_stock: fix deprecated methods and tests #1807

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

kobros-tech
Copy link

@kobros-tech kobros-tech commented Dec 9, 2024

@OCA-git-bot
Copy link
Contributor

Hi @rousseldenis, @lmignon, @lmarion-source,
some modules you are maintaining are being modified, check this out!

@kobros-tech kobros-tech force-pushed the 16.0-fix-product_abc_classification_sale_stock branch from 8b7f11e to 0b0f277 Compare December 9, 2024 21:05
@kobros-tech kobros-tech changed the title [16.0][FIX] product_abc_classification_sale_stock: fix deprecated modules and tests [16.0][FIX] product_abc_classification_sale_stock: fix deprecated methods and tests Dec 9, 2024
FROM
abc_classification_profile_product_rel abc_rel
abc_classification_profile_product_rel
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be changed.... These changes fixes an issue. see #1723

@@ -9,7 +9,7 @@
"version": "16.0.1.0.2",
"license": "AGPL-3",
"website": "https://github.com/OCA/product-attribute",
"maintainers": ["rousseldenis", "lmignon", "lmarion-source"],
"maintainers": ["rousseldenis", "lmignon", "lmarion-source", "kobros-tech"],
Copy link
Contributor

Choose a reason for hiding this comment

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

You could add your name into the contributors but not into the authors since your changes are related to some little issue, not to a large change, improvement, new functionality.

Comment on lines 278 to 281
self.assertEqual(len(levels.sale_stock_level_history_ids), 1)
logs = self.env["abc.sale_stock.level.history"].search(
[("product_level_id", "in", levels.ids)]
)
self.assertEqual(len(logs), 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be changed. The sale_stock_level_history_ids should have been invalidated by the call to _compute_abc_classification This is the purpose of the initial assert. That means that the invalidation done into the _log_history method is not complete and we should add

self.env["product.template"].invalidate_cache(
            ["abc_classification_product_level_ids"]
        )
self.env["product.product"].invalidate_cache(
            ["abc_classification_product_level_ids"]
        )

Copy link
Author

@kobros-tech kobros-tech Dec 10, 2024

Choose a reason for hiding this comment

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

@lmignon
I tried changes, because module testing failed in the last test, the reason why I tested version 16.0 is that refrsh() method is deprecated in version 16.0 but I didn't see the warning in the log for version 17.0.

I preferred to use one of the recommended three methods that I saw in the log of version 16.0.

Even this method:
self.env["product.template"].invalidate_cache(
["abc_classification_product_level_ids"]
)
is deprecated in version 16.0 and raising errors in version 17.0 without giving warnings in the log, so shall we override deprecated methods and see how can it work with the new not deprecated ones?

Also the database column is changed by the pre-commit command, this one if I return to the original name can the levels be computed automatically?

For now, let me remove my name from maintainers and return the old column name in the DB, but will need your help for the remaining ones as I inquired above.

Copy link
Author

Choose a reason for hiding this comment

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

To be clear the history records were always equal to 0, and assertions should be 1==1, and 2==2.

The original 16.0 version had two issues:
1 deprecated methods for migration to 17.0
2 the last test for logging history

Copy link
Author

Choose a reason for hiding this comment

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

Screenshot from 2024-12-10 12-46-01

@@ -255,15 +255,15 @@ def test_01(self):
# test computed classification and check that inactive products are
# not taken into account
self.product1.active = False
self.product1.refresh()
self.product1.invalidate_model()
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this should be self.product1.flush_recordset()

Copy link
Author

Choose a reason for hiding this comment

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

Screenshot from 2024-12-10 12-46-16

@kobros-tech kobros-tech force-pushed the 16.0-fix-product_abc_classification_sale_stock branch 2 times, most recently from 7425538 to a71d0bb Compare December 10, 2024 10:28
@kobros-tech
Copy link
Author

@lmignon

I just wonder how can a test on my local machine requires these values:
self._assertLevelIs(self.product1, "a")
self._assertLevelIs(self.product3, "a")
self._assertLevelIs(self.product5, "a")
self._assertLevelIs(self.product6, "b")
self._assertLevelIs(self.product2, "b")
self._assertLevelIs(self.product4, "c")
self._assertLevelIs(self.product_new, "c")

instead on testing the module in OCA, Odoo the values should be:

self._assertLevelIs(self.product1, "a")
self._assertLevelIs(self.product3, "a")
self._assertLevelIs(self.product5, "b")
self._assertLevelIs(self.product6, "b")
self._assertLevelIs(self.product2, "c")
self._assertLevelIs(self.product4, "c")
self._assertLevelIs(self.product_new, "c")

I don't know should I test on a new DB or what?

@kobros-tech
Copy link
Author

@lmignon

I just wonder how can a test on my local machine requires these values: self._assertLevelIs(self.product1, "a") self._assertLevelIs(self.product3, "a") self._assertLevelIs(self.product5, "a") self._assertLevelIs(self.product6, "b") self._assertLevelIs(self.product2, "b") self._assertLevelIs(self.product4, "c") self._assertLevelIs(self.product_new, "c")

instead on testing the module in OCA, Odoo the values should be:

self._assertLevelIs(self.product1, "a") self._assertLevelIs(self.product3, "a") self._assertLevelIs(self.product5, "b") self._assertLevelIs(self.product6, "b") self._assertLevelIs(self.product2, "c") self._assertLevelIs(self.product4, "c") self._assertLevelIs(self.product_new, "c")

I don't know should I test on a new DB or what?

As I guessed, new clean testing DB is following OCA tests and Odoo tests.

@kobros-tech kobros-tech force-pushed the 16.0-fix-product_abc_classification_sale_stock branch from a71d0bb to 665aaa1 Compare December 10, 2024 11:16
self.env["abc.classification.product.level"].invalidate_cache(
["sale_stock_level_history_ids"]
)
self.env.invalidate_all()
Copy link
Contributor

Choose a reason for hiding this comment

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

you invalidate too much fields....

Suggested change
self.env.invalidate_all()
self.env["abc.classification.product.level"].invalidate_model(
["sale_stock_level_history_ids"]
)
self.env["product.template"].invalidate_model(
["abc_classification_product_level_ids"]
)
self.env["product.product"].invalidate_model(
["abc_classification_product_level_ids"]
)

@@ -315,6 +315,7 @@ def _compute_abc_classification(self):
sale_stock_data.total_so_lines = total
sale_stock_data.product_level = product_abc_classification
previous_data = sale_stock_data

Copy link
Contributor

Choose a reason for hiding this comment

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

This change is useless. Can you remove this blank line plz?

@kobros-tech kobros-tech requested a review from lmignon December 10, 2024 15:51
@kobros-tech kobros-tech force-pushed the 16.0-fix-product_abc_classification_sale_stock branch from 665aaa1 to 91029a2 Compare December 10, 2024 16:52
Copy link
Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

@kobros-tech
Copy link
Author

see https://github.com/OCA/product-attribute/pull/1807/files#r1878288674

@lmignon
I already tried that you asked me to change even before you ask and also after.

What the module that you asks me to add instead of invalidate all, it causes that your tests fail.

Only invalidata all method makes tests succeed, not any other one even the one you have mentioned.

That is why I ask for your help as in version 17.0 challenges are more, we shall discuss once we finish this one.

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

Successfully merging this pull request may close these issues.

3 participants