[18.0][ADD] sale_loyalty_margin_computation: New module#264
[18.0][ADD] sale_loyalty_margin_computation: New module#264Andrii9090-tecnativa wants to merge 2 commits intoOCA:18.0from
Conversation
41a466d to
aacddac
Compare
| origin_lines[0].margin_percent = ( | ||
| origin_lines[0].margin / origin_lines[0].price_subtotal | ||
| ) | ||
| break |
There was a problem hiding this comment.
I'm not sure if this case can happen in practice, but what would occur if two loyalty programs were active at the same time, each with its own sale_margin_formula? The break would exit the loop after the first reward, so the second program's formula would never run.
I understand the break prevents applying the same formula multiple times when a multi_gift reward generates several lines (all sharing the same reward_id). But wouldn't skipping by already-processed reward_id be safer?
Something like this:
processed_reward_ids = set()
for line in self.filtered(...):
if line.reward_id.id in processed_reward_ids:
continue
processed_reward_ids.add(line.reward_id.id)
...
There was a problem hiding this comment.
Locally tested since runboat appears red.
I'm not sure if this is intentional, but I created a multi-gift promotion with 2 gifts and a formula result = origin_lines[0].margin + 10.
After applying the reward, the margin on the origin line was 22.40
Shouldn't it be 12.40? Since sale_margin_formula is defined at the reward level (not per gift line), I'd expect the formula to apply once per reward, regardless of how many gift lines it generates.
|
@cristina-hidalgo-tecnativa I tested this, and it seems to calculate correctly.
|
133c571 to
1d078c7
Compare
It seems our result of 22.40 was indeed transient — on a subsequent order with the same configuration we got the expected 12.40. That said, I also tested with two multi-gift programs applied to the same quotation, each with their own
And I obtained the following margin:
Shouldn't it be 17.40 (2.40 + 10 + 5) ? |
pedrobaeza
left a comment
There was a problem hiding this comment.
Not sure if for consistency with the rewards not having a formula, we should as well transfer the margin of the reward line to the main one.
|
@cristina-hidalgo-tecnativa Have you tested it with the changes I pushed yesterday? |
|
@pedrobaeza After yesterday's changes, when a reward has a formula configured, the margin of each reward line is now set to 0. Then, the result of the margin formula is applied to one of the origin lines. |
|
Yes, thanks, Andrii, please check what do you think of #264 (review) |
1d078c7 to
967eb48
Compare
Yes, tested this morning. Single multi-gift formula looks fixed. But the two-programs case still fails — with +10 and +5 formulas we get 22.40 instead of 17.40. |
967eb48 to
177a3c1
Compare
177a3c1 to
9accf1d
Compare





Depends:
@pedrobaeza ping
TT62183
@Tecnativa