12345678910111213141516171819202122232425262728293031323334 |
- # -*- encoding: utf-8 -*-
- from openerp import models, fields, api, _
- from openerp.exceptions import Warning
- from openerp.tools import float_compare
- class stock_move(models.Model):
- _inherit = "stock.move"
- @api.multi
- def action_done_button(self):
- for move in self:
- if move.product_id.type == 'product' and move.location_id.usage == 'internal':
- uom_record = move.product_id.uom_id
- qty_available = self.get_location_qty(move.product_id.id, move.location_id.id)
- compare_qty = float_compare(qty_available, move.product_uom_qty, precision_rounding=uom_record.rounding)
- if compare_qty == -1:
- warn_msg = _('Estas intentando transferir %.2f %s de %s pero el almacén de origen posee %.2f %s disponible!') % \
- (move.product_uom_qty, uom_record.name,
- move.product_id.name,
- max(0,qty_available), uom_record.name)
- raise Warning(_("No hay stock suficiente: "),_(warn_msg))
- return super(stock_move, self).action_done()
- @api.multi
- def get_location_qty(self, product_id, location_id):
- suma = 0
- quant_ids = self.env['stock.quant'].search([('product_id','=', product_id),('location_id','=',location_id)])
- if quant_ids:
- for quant_id in quant_ids:
- suma = suma + quant_id.qty
- return suma
|