Skip to content

Commit

Permalink
[FIX] the stock calculation from product packs if see from product te…
Browse files Browse the repository at this point in the history
…mplate view (OCA#189)

[FIX] we add prefetch_fields becase if not the stock it's no correct when this method it's call from website (OCA#191)
  • Loading branch information
nicomacr authored and docker-odoo committed Jan 17, 2025
1 parent 3bf34b7 commit 5c1f0e6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions product_pack/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ class ProductProduct(models.Model):
help='List of packs where product is used.'
)

@api.depends('stock_quant_ids', 'stock_move_ids')
def _compute_quantities(self):
def _compute_quantities_dict(
self, lot_id, owner_id, package_id,
from_date=False, to_date=False):
res = super(ProductProduct, self)._compute_quantities_dict(
lot_id, owner_id, package_id, from_date=from_date, to_date=to_date)
packs = self.filtered('pack')
no_packs = (self + packs.mapped('pack_line_ids.product_id')) - packs
super(ProductProduct, no_packs)._compute_quantities()
for product in packs:
for product in packs.with_context(prefetch_fields=False):
pack_qty_available = []
pack_virtual_available = []
for subproduct in product.pack_line_ids:
Expand All @@ -40,7 +41,7 @@ def _compute_quantities(self):
pack_virtual_available.append(math.floor(
subproduct_stock.virtual_available / sub_qty))
# TODO calcular correctamente pack virtual available para negativos
vals = {
res[product.id] = {
'qty_available': (
pack_qty_available and min(pack_qty_available) or False),
'incoming_qty': 0,
Expand All @@ -49,8 +50,7 @@ def _compute_quantities(self):
pack_virtual_available and
max(min(pack_virtual_available), 0) or False),
}
product.update(vals)
# return res
return res

@api.constrains('pack_line_ids')
def check_recursion(self):
Expand Down

0 comments on commit 5c1f0e6

Please sign in to comment.