forked from OCA/stock-logistics-barcode
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] stock_barcodes: Add pending move with difference between demand…
… and reserved
- Loading branch information
1 parent
336497b
commit 0cd2937
Showing
11 changed files
with
379 additions
and
202 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 Tecnativa - Sergio Teruel | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = "stock.move" | ||
|
||
barcode_backorder_action = fields.Selection( | ||
[ | ||
("pending", "Pending"), | ||
("create_backorder", "Create Backorder"), | ||
("skip_backorder", "No Backorder"), | ||
], | ||
string="Backorder action", | ||
default="pending", | ||
) | ||
|
||
def _action_done(self, cancel_backorder=False): | ||
moves_cancel_backorder = self.browse() | ||
if not cancel_backorder: | ||
moves_cancel_backorder = self.filtered( | ||
lambda sm: sm.barcode_backorder_action == "skip_backorder" | ||
) | ||
super(StockMove, moves_cancel_backorder)._action_done(cancel_backorder=True) | ||
moves_backorder = self - moves_cancel_backorder | ||
moves_backorder.barcode_backorder_action = "pending" | ||
return super(StockMove, moves_backorder)._action_done( | ||
cancel_backorder=cancel_backorder | ||
) | ||
|
||
def copy_data(self, default=None): | ||
vals_list = super().copy_data(default=default) | ||
for vals in vals_list: | ||
vals.pop("barcode_backorder_action", None) | ||
return vals_list |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# Copyright 2019 Sergio Teruel <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from odoo import models | ||
from odoo.tools.float_utils import float_compare | ||
|
||
|
||
class StockPicking(models.Model): | ||
|
@@ -33,50 +32,25 @@ def action_barcode_scan(self, option_group=False): | |
wiz = self.env["wiz.stock.barcodes.read.picking"].create( | ||
self._prepare_barcode_wiz_vals(option_group) | ||
) | ||
wiz.determine_todo_action() | ||
wiz.fill_pending_moves() | ||
wiz.determine_todo_action() | ||
action = self.env["ir.actions.actions"]._for_xml_id( | ||
"stock_barcodes.action_stock_barcodes_read_picking" | ||
) | ||
action["res_id"] = wiz.id | ||
return action | ||
|
||
def button_validate(self): | ||
if ( | ||
self.picking_type_id.barcode_option_group_id.auto_put_in_pack | ||
and not self.move_line_ids.mapped("result_package_id") | ||
): | ||
self.action_put_in_pack() | ||
create_backorder = False | ||
put_in_pack_picks = self.filtered( | ||
lambda p: p.picking_type_id.barcode_option_group_id.auto_put_in_pack | ||
and not p.move_line_ids.result_package_id | ||
) | ||
if put_in_pack_picks: | ||
put_in_pack_picks.action_put_in_pack() | ||
# Variable initialized as True to optimize break loop | ||
skip_backorder = True | ||
if self.env.context.get("stock_barcodes_validate_picking", False): | ||
# Avoid backorder when all move lines are processed (done or done_forced) | ||
prec = self.env["decimal.precision"].precision_get( | ||
"Product Unit of Measure" | ||
) | ||
for move in self.move_ids.filtered(lambda sm: sm.state != "cancel"): | ||
if ( | ||
float_compare( | ||
move.quantity_done, move.product_uom_qty, precision_digits=prec | ||
) | ||
< 0 | ||
): | ||
# In normal conditions backorder will be created | ||
create_backorder = True | ||
if not move.move_line_ids or any( | ||
sml.barcode_scan_state in ["pending"] | ||
for sml in move.move_line_ids | ||
): | ||
# If any move are not processed we can not skip backorder | ||
skip_backorder = False | ||
break | ||
if create_backorder and skip_backorder: | ||
res = super( | ||
StockPicking, | ||
self.with_context( | ||
picking_ids_not_to_backorder=self.ids, skip_backorder=True | ||
), | ||
StockPicking, self.with_context(skip_backorder=True) | ||
).button_validate() | ||
else: | ||
res = super().button_validate() | ||
|
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
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
Oops, something went wrong.