-
-
Notifications
You must be signed in to change notification settings - Fork 332
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_*: Move todo record methods to picking read wizard
- Loading branch information
1 parent
ad7afc8
commit 72c3a30
Showing
6 changed files
with
176 additions
and
34 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,11 +1,13 @@ | ||
# Copyright 2019 Sergio Teruel <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
import logging | ||
from collections import OrderedDict, defaultdict | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
from odoo.fields import first | ||
from odoo.tools.float_utils import float_compare | ||
from odoo.tools.safe_eval import safe_eval | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
@@ -195,7 +197,7 @@ def get_moves_or_move_lines(self): | |
|
||
def fill_todo_records(self): | ||
move_lines = self.get_sorted_move_lines(self.get_moves_or_move_lines()) | ||
self.env["wiz.stock.barcodes.read.todo"].fill_records(self, [move_lines]) | ||
self.fill_records([move_lines]) | ||
|
||
@api.model | ||
def _get_fields_filled_special(self): | ||
|
@@ -784,6 +786,138 @@ def _option_required_hook(self, option_required): | |
return bool(self.location_dest_id) | ||
return super()._option_required_hook(option_required) | ||
|
||
def _group_key(self, line): | ||
group_key_for_todo_records = self.option_group_id.group_key_for_todo_records | ||
if group_key_for_todo_records: | ||
return safe_eval(group_key_for_todo_records, globals_dict={"object": line}) | ||
if self.option_group_id.source_pending_moves == "move_line_ids": | ||
return (line.location_id, line.product_id, line.lot_id, line.package_id) | ||
else: | ||
return (line.location_id, line.product_id) | ||
|
||
def _get_all_products_quantities_in_package(self, package): | ||
res = {} | ||
for quant in package._get_contained_quants(): | ||
if quant.product_id not in res: | ||
res[quant.product_id] = 0 | ||
res[quant.product_id] += quant.quantity | ||
return res | ||
|
||
def _prepare_fill_record_values(self, line, position): | ||
vals = { | ||
"wiz_barcode_id": self.id, | ||
"product_id": line.product_id.id, | ||
"product_uom_qty": line.product_uom_qty, | ||
"name": "To do action", | ||
"position_index": position, | ||
"picking_code": line.picking_code, | ||
} | ||
if line._name == "stock.move.line": | ||
package_product_dic = self._get_all_products_quantities_in_package( | ||
line.package_id | ||
) | ||
vals.update( | ||
{ | ||
"location_id": line.location_id.id, | ||
"location_dest_id": line.location_dest_id.id, | ||
"lot_id": line.lot_id.id, | ||
"package_id": line.package_id.id, | ||
"result_package_id": line.result_package_id.id, | ||
"uom_id": line.product_uom_id.id, | ||
"product_qty_reserved": line.product_qty, | ||
"line_ids": [(6, 0, line.ids)], | ||
"stock_move_ids": [(6, 0, line.move_id.ids)], | ||
"package_product_qty": package_product_dic | ||
and package_product_dic[line.product_id] | ||
or 0.0, | ||
} | ||
) | ||
else: | ||
vals.update( | ||
{ | ||
"location_id": (line.move_line_ids[:1] or line).location_id.id, | ||
"location_dest_id": ( | ||
line.move_line_ids[:1] or line | ||
).location_dest_id.id, | ||
"uom_id": line.product_uom.id, | ||
"product_qty_reserved": line.move_line_ids | ||
and sum(line.move_line_ids.mapped("product_qty")) | ||
or line.product_uom_qty, | ||
"line_ids": [(6, 0, line.move_line_ids.ids)], | ||
"stock_move_ids": [(6, 0, line.ids)], | ||
} | ||
) | ||
return vals | ||
|
||
def _update_fill_record_values(self, line, vals): | ||
vals["product_uom_qty"] += line.product_uom_qty | ||
if self.option_group_id.source_pending_moves == "move_line_ids": | ||
vals["product_qty_reserved"] += line.product_qty | ||
vals["line_ids"][0][2].append(line.id) | ||
vals["stock_move_ids"][0][2].append(line.move_id.id) | ||
else: | ||
vals["product_qty_reserved"] += ( | ||
line.move_line_ids | ||
and sum(line.move_line_ids.mapped("product_qty")) | ||
or line.product_uom_qty | ||
) | ||
vals["line_ids"][0][2].extend(line.move_line_ids.ids) | ||
vals["stock_move_ids"][0][2].extend(line.ids) | ||
return vals | ||
|
||
def fill_records(self, lines_list): | ||
""" | ||
:param lines_list: browse list | ||
:return: | ||
""" | ||
ReadTodo = self.env["wiz.stock.barcodes.read.todo"] | ||
self.todo_line_ids.unlink() | ||
self.todo_line_id = False | ||
# self.position_index = 0 | ||
todo_vals = OrderedDict() | ||
position = 0 | ||
move_qty_dic = defaultdict(float) | ||
is_stock_move_line_origin = lines_list[0]._name == "stock.move.line" | ||
for lines in lines_list: | ||
for line in lines: | ||
key = self._group_key(line) | ||
if key not in todo_vals: | ||
todo_vals[key] = self._prepare_fill_record_values(line, position) | ||
position += 1 | ||
else: | ||
todo_vals[key] = self._update_fill_record_values( | ||
line, todo_vals[key] | ||
) | ||
if is_stock_move_line_origin: | ||
move_qty_dic[line.move_id] += max( | ||
line.product_uom_qty, line.qty_done | ||
) | ||
else: | ||
move_qty_dic[line] += max(line.product_uom_qty, line.quantity_done) | ||
for move in self.get_moves(): | ||
qty = move_qty_dic[move] | ||
if ( | ||
move.barcode_backorder_action == "pending" | ||
and move.product_uom_qty > qty | ||
): | ||
vals = self._prepare_fill_record_values(move, position) | ||
vals.update( | ||
{ | ||
"product_uom_qty": move.product_uom_qty - qty, | ||
"product_qty_reserved": 0.0, | ||
"line_ids": False, | ||
"is_extra_line": True, | ||
} | ||
) | ||
todo_vals[ | ||
( | ||
move, | ||
"M", | ||
) | ||
] = vals | ||
position += 1 | ||
self.todo_line_ids = ReadTodo.create(list(todo_vals.values())) | ||
|
||
|
||
class WizCandidatePicking(models.TransientModel): | ||
""" | ||
|
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 +1,2 @@ | ||
from . import stock_barcodes_read_picking | ||
from . import stock_barcodes_read_todo |
12 changes: 12 additions & 0 deletions
12
stock_barcodes_elaboration/wizard/stock_barcodes_read_picking.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,12 @@ | ||
# Copyright 2019 Sergio Teruel <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from odoo import models | ||
|
||
|
||
class WizStockBarcodesReadPicking(models.TransientModel): | ||
_inherit = "wiz.stock.barcodes.read.picking" | ||
|
||
def _group_key(self, line): | ||
key = super()._group_key(line) | ||
key += (line.elaboration_ids,) | ||
return key |
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,6 +1,7 @@ | ||
# Copyright 2019 Sergio Teruel <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from odoo import api, fields, models | ||
from odoo.tools import float_compare | ||
|
||
|
||
class WizStockBarcodesReadPicking(models.TransientModel): | ||
|
@@ -51,3 +52,30 @@ def _update_stock_move_line(self, line, sml_vals): | |
line.secondary_uom_qty + self.secondary_uom_qty | ||
) | ||
return super()._update_stock_move_line(line, sml_vals) | ||
|
||
def _prepare_fill_record_values(self, line, position): | ||
vals = super()._prepare_fill_record_values(line, position) | ||
vals["secondary_uom_id"] = line.secondary_uom_id.id | ||
if line._name == "stock.move.line": | ||
move = line.move_id | ||
# Set secondary qty when stock.move full match with stock.move.line | ||
if not (move.move_line_ids - line) and not float_compare( | ||
move.product_uom_qty, | ||
line.product_uom_qty, | ||
precision_rounding=line.product_uom_id.rounding, | ||
): | ||
vals["secondary_uom_qty"] = move.secondary_uom_qty | ||
elif line._name == "stock.move": | ||
# Set secondary qty when stock.move all quantity is available | ||
if not float_compare( | ||
line.reserved_availability, | ||
line.product_uom_qty, | ||
precision_rounding=line.product_uom.rounding, | ||
): | ||
vals["secondary_uom_qty"] = line.secondary_uom_qty | ||
return vals | ||
|
||
def _group_key(self, line): | ||
key = super()._group_key(line) | ||
key += (line.secondary_uom_id,) | ||
return key |
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