Skip to content

Commit

Permalink
[IMP] nutritional_info_stock_lot: Compute nutritional_value_ids to ge…
Browse files Browse the repository at this point in the history
…t initial values from product

TT51200
  • Loading branch information
carlosdauden committed Oct 9, 2024
1 parent 419d145 commit f859843
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions nutritional_info_stock_lot/models/stock_production_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,30 @@ class StockProductionLot(models.Model):
nutritional_value_ids = fields.One2many(
comodel_name="nutritional.value.lot",
inverse_name="lot_id",
compute="_compute_nutritional_value_ids",
store=True,
readonly=False,
)

@api.depends("product_id")
def _compute_nutritional_value_ids(self):
for lot in self:
nutritional_list = [(5, 0, 0)]
for nutritional_line in lot.product_id.nutritional_value_ids:
nutritional_list.append(

Check warning on line 23 in nutritional_info_stock_lot/models/stock_production_lot.py

View check run for this annotation

Codecov / codecov/patch

nutritional_info_stock_lot/models/stock_production_lot.py#L23

Added line #L23 was not covered by tests
(
0,
0,
{
"type_id": nutritional_line.type_id.id,
"sequence": nutritional_line.sequence,
"product_id": nutritional_line.product_id.id,
"value": nutritional_line.value,
},
)
)
lot.nutritional_value_ids = nutritional_list

@api.constrains("nutritional_value_ids", "nutritional_value_ids.type_id")
def _check_nutritional_type_not_repeated(self):
for lot in self:
Expand Down

0 comments on commit f859843

Please sign in to comment.