-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] stock_picking_batch_validate_confirm: avoid propagating context…
… with defaults When this module was installed along with `sale_elaboration`, elaboration sale order lines could be created automatically when confirming a picking. The `sale.order.line` model also has a `move_ids` field. Thus, those lines were created associated to the `stock.move` records found from within the batch. To make it even more fun, a batch can contain moves associated to unrelated sales. Thus, the elaboration lines were getting stock moves (which is wrong because they are services) and those moves came from unrelated sale orders. This mismatch was resulting in unexpected behaviors here and there. Now, we just produce defaults based on the standard context that all wizards get by default. This is safe and doesn't pollute any sub-calls. @moduon MT-9033
- Loading branch information
Showing
3 changed files
with
32 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 24 additions & 3 deletions
27
stock_picking_batch_validate_confirm/wizards/stock_picking_batch_confirm.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
# Copyright 2024 Moduon Team S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) | ||
|
||
from odoo import fields, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class StockPickingBatchConfirm(models.TransientModel): | ||
_name = "stock.picking.batch.confirm" | ||
_description = "Wizard Batch Confirm" | ||
|
||
batch_id = fields.Many2one("stock.picking.batch", string="Batch") | ||
move_ids = fields.Many2many("stock.move", string="Moves") | ||
batch_id = fields.Many2one( | ||
"stock.picking.batch", | ||
string="Batch", | ||
required=True, | ||
default=lambda self: self._default_batch_id(), | ||
) | ||
move_ids = fields.Many2many( | ||
"stock.move", string="Moves", compute="_compute_move_ids" | ||
) | ||
|
||
@api.model | ||
def _default_batch_id(self): | ||
"""Get batch from context.""" | ||
if self.env.context.get("active_model") == "stock.picking.batch": | ||
return self.env.context.get("active_id") | ||
|
||
@api.depends("batch_id") | ||
def _compute_move_ids(self): | ||
"""Get moves from batch.""" | ||
for wizard in self: | ||
wizard.move_ids = wizard.batch_id.move_ids.move_orig_ids.filtered_domain( | ||
[("state", "not in", ("cancel", "done"))] | ||
) | ||
|
||
def button_validate(self): | ||
return self.batch_id.with_context(skip_batch_confirm=True).action_done() |