Skip to content

Commit

Permalink
[FIX] stock_barcodes_gs1_secondary_unit: fill secondary uom qty in de…
Browse files Browse the repository at this point in the history
…termine todo action
  • Loading branch information
sergio-teruel committed Jun 14, 2023
1 parent 6cddcdf commit fcf501c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ def determine_todo_action(self, forced_todo_line=False):
"secondary_uom_id", "filled_default"
):
self.secondary_uom_id = self.todo_line_id.line_ids[:1].secondary_uom_id
if self.option_group_id.get_option_value(
"secondary_uom_qty", "filled_default"
):
self.secondary_uom_qty = self.todo_line_id.secondary_uom_qty
return res
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<field name="arch" type="xml">
<!-- Add secondary uom info to pending moves -->
<xpath
expr="//field[@name='pending_move_ids']/tree/button[@name='fill_from_pending_line']"
expr="//field[@name='pending_move_ids']/tree/field[@name='product_uom_qty']"
position="before"
>
<field name="secondary_uom_qty" optional="show" />
Expand Down Expand Up @@ -96,7 +96,7 @@
</xpath>
<!-- Add secondary uom info to detailed operations -->
<xpath
expr="//field[@name='move_line_ids']/tree/button[@name='action_barcode_detailed_operation_unlink']"
expr="//field[@name='move_line_ids']/tree/field[@name='qty_done']"
position="before"
>
<field name="secondary_uom_qty" optional="show" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,28 @@ class WizStockBarcodesReadTodo(models.TransientModel):
secondary_uom_qty = fields.Float(
string="Secondary Qty",
digits="Product Unit of Measure",
compute="_compute_secondary_uom",
readonly=True,
)
secondary_uom_id = fields.Many2one(
comodel_name="product.secondary.unit",
string="Second unit",
compute="_compute_secondary_uom",
readonly=True,
)

def _compute_secondary_uom(self):
for line in self:
if (
self.wiz_barcode_id.option_group_id.source_pending_moves
== "move_line_ids"
):
moves = line.line_ids
qty = sum(m.secondary_uom_qty for m in moves.mapped("move_id")) - sum(
m.secondary_uom_qty for m in moves if m.qty_done
)
else:
moves = line.stock_move_ids
qty = sum(m.secondary_uom_qty for m in moves) - sum(
m.secondary_uom_qty for m in moves.move_line_ids if m.qty_done
)
line.secondary_uom_qty = qty
line.secondary_uom_id = moves.secondary_uom_id[:1]
def _prepare_fill_record_values(self, wiz_barcode, line, position):
vals = super()._prepare_fill_record_values(wiz_barcode, line, position)
vals.update(
{
"secondary_uom_qty": line.secondary_uom_qty,
"secondary_uom_id": line.secondary_uom_id.id,
}
)
return vals

def _update_fill_record_values(self, wiz_barcode, line, vals):
vals = super()._update_fill_record_values(wiz_barcode, line, vals)
vals["secondary_uom_qty"] += line.secondary_uom_qty
return vals

@api.model
def fields_to_fill_from_pending_line(self):
Expand Down

0 comments on commit fcf501c

Please sign in to comment.