|
|
""" This field represents the sum of the move lines `quantity`. It allows the user to know
if there is still work to do.
We take care of rounding this value at the general decimal precision and not the rounding
of the move's UOM to make sure this value is really close to the real sum, because this
field will be used in `_action_done` in order to know if the move will need a backorder or
an extra move.
"""
if not any(self._ids):
# onchange
for move in self:
move.quantity = move._quantity_sml()
else:
# compute
move_lines_ids = set()
for move in self:
move_lines_ids |= set(move.move_line_ids.ids)
data = self.env['stock.move.line']._read_group(
[('id', 'in', list(move_lines_ids))],
['move_id', 'uom_id'], ['quantity:sum']
)
sum_qty = defaultdict(float)
for move, uom_id, qty_sum in data:
uom = move.uom_id
sum_qty[move.id] += uom_id._compute_quantity(qty_sum, uom, round=False)
for move in self:
move.quantity = sum_qty[move.id]
|
|