diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2015-11-24 08:38:18 +0100 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2015-11-24 11:33:26 +0100 |
| commit | db7ed45a4e5da3f303d5cfda4718e5f31a212527 (patch) | |
| tree | 665e1095ec949a704bcd42fe55f3e0d6fda22936 /addons | |
| parent | ae3efc0df73b41e8e0d7472428ca1c5168ae449e (diff) | |
[FIX] sale_stock: handles UoM correctly in check availability
A simple browse with `uom=` as parameter does not convert
virtual_available in the requested UoM. Therefore, we need to convert
manually in the standard UoM of the product.
Bonus: is_available depends on self.route_id
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/sale_stock/sale_stock.py | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 47b0aed363d..740cdaa5476 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -113,27 +113,21 @@ class SaleOrderLine(models.Model): return self._check_package() return {} - @api.onchange('product_id', 'product_uom_qty') + @api.onchange('product_id', 'product_uom_qty', 'product_uom', 'route_id') def _onchange_product_id_check_availability(self): - if not self.product_id: + if not self.product_id or not self.product_uom_qty or not self.product_uom: self.product_packaging = False return {} - precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') if self.product_id.type == 'product': - product = self.product_id.with_context( - lang=self.order_id.partner_id.lang, - partner_id=self.order_id.partner_id.id, - date_order=self.order_id.date_order, - pricelist_id=self.order_id.pricelist_id.id, - uom=self.product_uom.id, - warehouse_id=self.order_id.warehouse_id.id - ) + precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') + product_qty = self.env['product.uom']._compute_qty_obj(self.product_uom, self.product_uom_qty, self.product_id.uom_id) + if float_compare(self.product_id.virtual_available, product_qty, precision_digits=precision) == -1: is_available = self._check_routing() if not is_available: warning_mess = { 'title': _('Not enough inventory!'), 'message' : _('You plan to sell %.2f %s but you only have %.2f %s available!\nThe stock on hand is %.2f %s.') % \ - (self.product_uom_qty, self.product_uom.name or self.product_id.uom_id.name, product.virtual_available, self.product_uom.name or self.product_id.uom_id.name, product.qty_available, self.product_uom.name or self.product_id.uom_id.name) + (self.product_uom_qty, self.product_uom.name, self.product_id.virtual_available, self.product_id.uom_id.name, self.product_id.qty_available, self.product_id.uom_id.name) } return {'warning': warning_mess} return {} |
