Following solution working with us.
1. Added a new custom selection(internal, under sale) field in store.warehouse
2. Added a custom calculated field to sale.order.line
3. Showed new calculated field on sales order lines form view
It will give the idea to salesperson how much stock we have on hand in warehouse of type internal.
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
internal_available = fields.Float(compute="_compute_internal_available", string='Internal OnHand')
@api.depends('product_uom_qty', 'product_id')
def _compute_internal_available(self):
for rec in self.filtered(lambda sol: sol.order_id.state not in ['cancel']):
qty = 0
warehouses = self.env['stock.warehouse'].sudo().search([('warehouse_type', '=', 'internal')])
for wh in warehouses:
qty += rec.product_id.with_context(warehouse=wh.id).qty_available
rec.internal_available = qty