[IMP] website_sale_aplicoop: use virtual_available for stock check instead of qty_available
Use forecasted quantity (virtual_available) instead of on-hand quantity (qty_available) for out-of-stock and low-stock calculations, so pending incoming/outgoing moves are taken into account.
This commit is contained in:
parent
39b9f887a9
commit
26bfa028d1
1 changed files with 5 additions and 5 deletions
|
|
@ -23,14 +23,14 @@ class ProductProduct(models.Model):
|
|||
string="Is Out of Stock",
|
||||
compute="_compute_stock_ribbons",
|
||||
store=False,
|
||||
help="True if qty_available <= 0",
|
||||
help="True if virtual_available <= 0",
|
||||
)
|
||||
|
||||
is_low_stock = fields.Boolean(
|
||||
string="Is Low Stock",
|
||||
compute="_compute_stock_ribbons",
|
||||
store=False,
|
||||
help="True if 0 < qty_available <= threshold",
|
||||
help="True if 0 < virtual_available <= threshold",
|
||||
)
|
||||
|
||||
dynamic_ribbon_id = fields.Many2one(
|
||||
|
|
@ -41,13 +41,13 @@ class ProductProduct(models.Model):
|
|||
help="Auto-assigned ribbon based on stock levels",
|
||||
)
|
||||
|
||||
@api.depends("qty_available", "type", "allow_out_of_stock_order")
|
||||
@api.depends("virtual_available", "type", "allow_out_of_stock_order")
|
||||
def _compute_stock_ribbons(self):
|
||||
"""Compute stock-based ribbons dynamically.
|
||||
|
||||
A product is considered out of stock only when:
|
||||
- It is a storable product (type='consu')
|
||||
- qty_available <= 0
|
||||
- virtual_available <= 0
|
||||
- allow_out_of_stock_order is False
|
||||
|
||||
If allow_out_of_stock_order is True, the product can always be sold
|
||||
|
|
@ -76,7 +76,7 @@ class ProductProduct(models.Model):
|
|||
product.dynamic_ribbon_id = False
|
||||
continue
|
||||
|
||||
qty = product.qty_available
|
||||
qty = product.virtual_available
|
||||
|
||||
# Check if product allows selling when out of stock
|
||||
# If True, never block add-to-cart based on stock
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue