[REF] stock: quant: add available quantity field
available_quantity is the quantity without the reservation. task-2061825
This commit is contained in:
@@ -87,9 +87,18 @@ class StockQuant(models.Model):
|
||||
default=0.0,
|
||||
help='Quantity of reserved products in this quant, in the default unit of measure of the product',
|
||||
readonly=True, required=True)
|
||||
available_quantity = fields.Float(
|
||||
'Available Quantity',
|
||||
help="On hand quantity which hasn't been reserved on a transfer, in the default unit of measure of the product",
|
||||
compute='_compute_available_quantity')
|
||||
in_date = fields.Datetime('Incoming Date', readonly=True)
|
||||
tracking = fields.Selection(related='product_id.tracking', readonly=True)
|
||||
|
||||
@api.depends('quantity', 'reserved_quantity')
|
||||
def _compute_available_quantity(self):
|
||||
for quant in self:
|
||||
quant.available_quantity = quant.quantity - quant.reserved_quantity
|
||||
|
||||
@api.depends('quantity')
|
||||
def _compute_inventory_quantity(self):
|
||||
if not self._is_inventory_mode():
|
||||
@@ -151,13 +160,20 @@ class StockQuant(models.Model):
|
||||
|
||||
@api.model
|
||||
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
|
||||
""" Override to handle the "inventory mode" and set the `inventory_quantity`
|
||||
in view list grouped.
|
||||
""" Override to set the `inventory_quantity` field if we're in "inventory mode" as well
|
||||
as to compute the sum of the `available_quantity` field.
|
||||
"""
|
||||
if 'available_quantity' in fields:
|
||||
if 'quantity' not in fields:
|
||||
fields.append('quantity')
|
||||
if 'reserved_quantity' not in fields:
|
||||
fields.append('reserved_quantity')
|
||||
result = super(StockQuant, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
|
||||
if self._is_inventory_mode():
|
||||
for record in result:
|
||||
record['inventory_quantity'] = record.get('quantity', 0)
|
||||
for group in result:
|
||||
if self._is_inventory_mode():
|
||||
group['inventory_quantity'] = group.get('quantity', 0)
|
||||
if 'available_quantity' in fields:
|
||||
group['available_quantity'] = group['quantity'] - group['reserved_quantity']
|
||||
return result
|
||||
|
||||
def write(self, vals):
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
invisible="1"/>
|
||||
<field name="inventory_quantity" string="On Hand Quantity"
|
||||
readonly="0"/>
|
||||
<field name="reserved_quantity" optional="hide"/>
|
||||
<field name="available_quantity" optional="show"/>
|
||||
<field name="product_uom_id" groups="uom.group_uom"/>
|
||||
<field name='company_id' groups="base.group_multi_company" optional="show"/>
|
||||
</tree>
|
||||
@@ -121,7 +121,7 @@
|
||||
invisible="context.get('hide_lot', False)"/>
|
||||
<field name="package_id" groups="stock.group_tracking_lot"/>
|
||||
<field name="owner_id" groups="stock.group_tracking_owner"/>
|
||||
<field name="reserved_quantity" string="Reserved"/>
|
||||
<field name="available_quantity"/>
|
||||
<field name="quantity"/>
|
||||
<field name="product_uom_id" groups="uom.group_uom"/>
|
||||
<field name='company_id' groups="base.group_multi_company"/>
|
||||
|
||||
Reference in New Issue
Block a user