-
-
Notifications
You must be signed in to change notification settings - Fork 71
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] sale_loyalty_auto_refresh: Migration to 16.0 #208
[16.0][MIG] sale_loyalty_auto_refresh: Migration to 16.0 #208
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR has the |
Hi @pedrobaeza can you merge this PR please ? |
/ocabot migration sale_loyalty_auto_refresh @chienandalu do you see it correct? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work @nguyenminhchien 🙂 Just some comments:
.get_param("sale_coupon_auto_refresh.%s_triggers" % (self._table), "") | ||
.get_param("sale_loyalty_auto_refresh.%s_triggers" % (self._table), "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chore: there should be a migration script renaming this parameter
def _auto_refresh_coupons(self): | ||
orders = self.filtered(type(self)._allow_recompute_coupon_lines) | ||
if orders: | ||
orders = orders.with_context(skip_auto_refresh_coupons=True) | ||
orders.recompute_coupon_lines() | ||
orders.action_open_reward_wizard() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this change of behavior. Why not using the new _update_programs_and_rewards
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried calling it, but it didn't work as expected. anw, i made some changes to deal with the case there was more than 1 applicable promotion. please review.
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo.tests import new_test_user, tagged | ||
|
||
from odoo.addons.sale_loyalty.tests.common import TestSaleCouponCommon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to have a diff here. Aside from that, at first glance I see lot of changes:
- Copyright and licences aren't respected from the original
- Tests cases are trimmed so you're not testing the same effects as before, so avoiding regression isn't granted or hard to tell...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the Copyright part, i may remove it by mistake.
I just add 1 more unit test to check the case of having more than 1 applicable promotion.
321bcd8
to
0fb6824
Compare
Hello @chienandalu is it good for you ? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nguyenminhchien some comments / doubts:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases are completely changed and can't see a clear reason why...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the models of coupon and promotion were changed dramatically. so i trimmed the test to make it more focus on testing the applying of the promotion auto, than re-test the promotion flow, which has been done by sale_loyalty. anw, i'm going to roll it back.
self_ctx = self.with_context(skip_auto_refresh_coupons=True) | ||
for order in self_ctx: | ||
if order._allow_recompute_coupon_lines(): | ||
order._update_programs_and_rewards() | ||
order.action_apply_rewards() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no real need to change the previous structure. Yo can:
self_ctx = self.with_context(skip_auto_refresh_coupons=True) | |
for order in self_ctx: | |
if order._allow_recompute_coupon_lines(): | |
order._update_programs_and_rewards() | |
order.action_apply_rewards() | |
orders = self.with_context(skip_auto_refresh_coupons=True).filtered(type(self)._allow_recompute_coupon_lines) | |
for order in orders: | |
order._update_programs_and_rewards() | |
order.action_apply_rewards() |
# Ignore exception errors to unblock the user when creating/writing | ||
logger.warning(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to be really noisy. I you need to do it, better just log it in debug mode.
7aca846
to
f4d66d1
Compare
@chienandalu is it good for you ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non blocking comments, only code review.
@chienandalu ping :)
|
||
self_ctx = self.with_context(skip_auto_refresh_coupons=True) | ||
lines = super(SaleOrderLine, self_ctx).create(vals_list) | ||
lines.mapped("order_id")._auto_refresh_coupons() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lines.mapped("order_id")._auto_refresh_coupons() | |
lines.order_id._auto_refresh_coupons() |
"""Returns whether reward lines in order ``self`` can be recomputed | ||
automatically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Returns whether reward lines in order ``self`` can be recomputed | |
automatically. | |
""" | |
Check if reward lines in ``self`` can be recomputed automatically. |
return super().write(vals) | ||
|
||
old_data = self._read_recs_data() | ||
old_orders = self.mapped("order_id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old_orders = self.mapped("order_id") | |
old_orders = self.order_id |
self_ctx = self.with_context(skip_auto_refresh_coupons=True) | ||
res = super(SaleOrderLine, self_ctx).write(vals) | ||
new_data = self._read_recs_data() | ||
new_orders = self.mapped("order_id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new_orders = self.mapped("order_id") | |
new_orders = self.order_id |
if self._check_skip_refresh(): | ||
return super().unlink() | ||
|
||
orders = self.mapped("order_id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orders = self.mapped("order_id") | |
orders = self.order_id |
#. In every add the fields seperated by commas that you want to add to the recomputation | ||
triggers. | ||
|
||
⚠️ After configuring or removing a trigger a restart of Odoo is recommended so the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this statement. Either is required or is not. I'd remove it if not necessary because it's confusing.
I left a comment on the compute method.
) | ||
return {x for x in additional_triggers if x in self._fields} | ||
|
||
@api.depends(lambda self: list(self._get_auto_refresh_coupons_triggers())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this complexity w/ the check on new triggers is necessary?
Data:
- the field you compute is non stored -> will get recomputed at every request and you can invalidate caching if needed
- any change on the config param won't have any effect on this depends
- in fact what you are doing is to load the triggers at need (eg: create/write)
Wouldn't be better to have an empty api.depends
?
@chienandalu ping |
@SilvioC2C maybe you can help on the review / merge of this PR as it's been under review for some time. |
try: | ||
self._apply_program_reward(reward, coupon) | ||
self._update_programs_and_rewards() | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it a too broad except ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but here, i want to ignore all exception errors to unblock the user when creating/writing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anw, i updated to catch UserError, ValidationError only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, a few comments here and there
[("key", "like", "sale_coupon_auto_refresh.")] | ||
) | ||
for parameter in parameters: | ||
parameter.key = (parameter.key).replace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameter.key = (parameter.key).replace( | |
parameter.key = parameter.key.replace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious but what's different or benefit of this suggested change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better readability 😄 parenthesis are redundant in this case
order._update_programs_and_rewards() | ||
order.action_apply_rewards() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't _update_programs_and_rewards()
already called by action_apply_rewards()
internally? Do we need this double call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we do. The first call to updates applied with the current state of the order. Then, after calling _apply_program_reward()
, need to call it again.
try: | ||
self._apply_program_reward(reward, coupon) | ||
self._update_programs_and_rewards() | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please catch any possible psycopg2
exception and let them be raised, it'd be better to not ignore DB-level errors.
)._update_programs_and_rewards() | ||
|
||
|
||
class SaleOrderLine(models.Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be worth it to move SaleOrderLine
to its own file sale_order_line.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I've seen different approaches regarding that. Some people prefer to keep it in the parent object file (sale_order.py
). I am okay to keep like that. But move SaleOrderLine
to his own file it's an option as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, usually if I have something like:
from odoo import fields, models
class MyModel(models.Model):
_name = "my.model"
name = fields.Char()
line_ids = fields.One2many("my.model.line", "rec_id")
class MyModel(models.Model):
_name = "my.model"
descr = fields.Char()
rec_id = fields.Many2one("my.model")
then it can make sense to have both classes in the same file.
But in this module's case, file's ~150 LoC already, and both classes contain business logic... might as well separate them for improved readability.
Currently translated at 6.2% (1 of 16 strings) Translation: sale-promotion-14.0/sale-promotion-14.0-sale_coupon_auto_refresh Translate-URL: https://translation.odoo-community.org/projects/sale-promotion-14-0/sale-promotion-14-0-sale_coupon_auto_refresh/it/
This can allow us to work altogether with flexible triggers like the ones we could need with sale_coupon_criteria_order_based TT37479
We should not refresh the lines before the proccess of applying the coupon is finished. TT38806
Use the new `get_depends()` method as the former `depends` attribute (now in `_depends`) is no longer reliable.
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: sale-promotion-15.0/sale-promotion-15.0-sale_coupon_auto_refresh Translate-URL: https://translation.odoo-community.org/projects/sale-promotion-15-0/sale-promotion-15-0-sale_coupon_auto_refresh/
Currently translated at 100.0% (13 of 13 strings) Translation: sale-promotion-15.0/sale-promotion-15.0-sale_coupon_auto_refresh Translate-URL: https://translation.odoo-community.org/projects/sale-promotion-15-0/sale-promotion-15-0-sale_coupon_auto_refresh/es/
f4d66d1
to
e48ae33
Compare
e48ae33
to
fb20963
Compare
Hi @rousseldenis is it good for you ? |
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
@simahawk is possible to merge that one ? 4 approvals |
/ocabot merge nobump |
On my way to merge this fine PR! |
Congratulations, your PR was merged at d64c8a4. Thanks a lot for contributing to OCA. ❤️ |
Rename from
sale_coupon_auto_refresh
tosale_loyalty_auto_refresh