-
-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] proc_auto_create_grp_by_product: merge moves
Allow to merge moves having different date_deadline to pick everything in one operation
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from . import stock_rule | ||
from . import stock_move | ||
from . import procurement_group | ||
from . import product_product |
29 changes: 29 additions & 0 deletions
29
procurement_auto_create_group_by_product/models/stock_move.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from itertools import groupby | ||
|
||
from odoo import models | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = "stock.move" | ||
|
||
def _merge_moves(self, merge_into=False): | ||
sorted_moves_by_rule = sorted(self, key=lambda m: m.rule_id.id) | ||
res_moves = self.browse() | ||
for _rule, move_list in groupby( | ||
sorted_moves_by_rule, key=lambda m: m.rule_id.id | ||
): | ||
moves = self.browse(m.id for m in move_list) | ||
res_moves |= super(StockMove, moves)._merge_moves(merge_into=merge_into) | ||
return res_moves | ||
|
||
def _prepare_merge_moves_distinct_fields(self): | ||
result = super()._prepare_merge_moves_distinct_fields() | ||
if self.rule_id.auto_create_group_by_product: | ||
# Allow to merge moves on a pick operation having different | ||
# deadlines | ||
if "date_deadline" in result: | ||
result.remove("date_deadline") | ||
return result |