[16.0][FIX] sale_order_lot_selection: Fixed, that lot_id only gets propagat…#3934
[16.0][FIX] sale_order_lot_selection: Fixed, that lot_id only gets propagat…#3934
Conversation
|
Hi @bodedra, |
|
Hey @Kev-Roche, I have discovered some issues with this module after this pull request #3057 was integrated. My scenario is:
Since the sale order line propagates the lot_id, no matter if it is filled or not, we try to set restrict_lot_id = False on stock moves which have a restrict_lot_id and are may already done. This is the moment, where the validation in stock_restrict_lot kicks in. I am not exactly sure if my fix is what we want and if it is complete. I think in general we should question:
@bodedra Maybe also interesting for you. |
| res = super().write(vals) | ||
| allow_to_change_lot = self.env.company.allow_to_change_lot_on_confirmed_so | ||
| if "lot_id" in vals and ( | ||
| if vals.get("lot_id") in vals and ( |
There was a problem hiding this comment.
@baguenth Your fix is not correct.
In vals.get("lot_id") you'll get an... id. But you want to compare it with a dict.
There was a problem hiding this comment.
Even though this will fix the issue, I am wondering if we need a more sophisticated check like:
def write(self, vals):
# Capture original lot ids to detect actual changes per record
original_lots = {rec.id: rec.lot_id.id for rec in self}
res = super().write(vals)
if "lot_id" not in vals:
return res
allow_to_change_lot = self.env.company.allow_to_change_lot_on_confirmed_so
for line in self:
old_lot = original_lots.get(line.id)
new_lot = line.lot_id.id
# Only act if there is an actual change
if new_lot == old_lot:
continue
if allow_to_change_lot or line.order_id.state not in ["sale", "done"]:
# Propagate the new lot restriction to related stock moves
line.move_ids.write({"restrict_lot_id": new_lot})
else:
# Disallow changing the lot on confirmed SO if company setting forbids it
raise UserError(_("You can't change the lot on confirmed sale order."))
return resWith this we only do something, if the lot has actually changed for a sale order line.
|
@baguenth Could you add a test to avoid regression ? Thanks |
|
@rousseldenis I have update the pr with a more general solution. We now check, if the lot has actually changed, before propagating it to the stock moves. This doesn't lead to a functional change and avoids unnecessary propagations of lots to related stock moves. |
|
Hey @rousseldenis and @bodedra, kindly asking for (another) review. Thanks :) |
|
Someone? :) @rousseldenis @bodedra @Kev-Roche |
|
Hey @pedrobaeza, I saw you are also active on this module. Can I may ask you for a review / merge? My PR is stuck. |
|
@rousseldenis should confirm this due to his "Requested changes". You should also squash the commits into one. |
…ed to stock moves, if lot_id is actually filled
…ally changed, before propagating it to stock moves
|
@pedrobaeza I unfortunately cannot squash the commits, since the source branch is a production branch. I would need to recreate the pull request from a new source branch. |
|
Not really. You can rebase interactively and do the fixup, but if not able to, just open another PR. |
|
Closing the PR in favor of #4029. There all commits have been squashed. |
…ed to stock moves, if lot_id is actually filled