sale_order.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding : utf-8 -*-
  2. from openerp import fields, models, api, _
  3. class sale_order_line(models.Model):
  4. _inherit = "sale.order.line"
  5. @api.one
  6. @api.depends(
  7. 'product_uom_qty',
  8. 'product_id')
  9. def _fnct_line_stock(self):
  10. available = False
  11. if self.order_id.state == 'draft':
  12. available = self.with_context(
  13. warehouse=self.order_id.warehouse_id.id
  14. ).product_id.virtual_available - self.product_uom_qty
  15. self.virtual_available = available
  16. if available >= 0.0:
  17. available = True
  18. else:
  19. available = False
  20. self.virtual_available_boolean = available
  21. virtual_available = fields.Float(
  22. compute="_fnct_line_stock", string='Saldo Stock')
  23. virtual_available_boolean = fields.Boolean(
  24. compute="_fnct_line_stock", string='Saldo Stock')
  25. def product_id_change_with_wh(
  26. self, cr, uid, ids, pricelist, product, qty=0,
  27. uom=False, qty_uos=0, uos=False, name='', partner_id=False,
  28. lang=False, update_tax=True, date_order=False, packaging=False,
  29. fiscal_position=False, flag=False, warehouse_id=False,
  30. context=None):
  31. res = super(sale_order_line, self).product_id_change_with_wh(
  32. cr, uid, ids, pricelist, product, qty,
  33. uom, qty_uos, uos, name, partner_id,
  34. lang, update_tax, date_order, packaging, fiscal_position, flag,
  35. warehouse_id=warehouse_id, context=context)
  36. disable_warning = warehouse_id and self.pool['stock.warehouse'].browse(
  37. cr, uid, warehouse_id, context).disable_sale_stock_warning or False
  38. # if not stock warning set in company and warning in res...
  39. if res.get('warning', False) and disable_warning:
  40. # clean warning
  41. warning = {}
  42. # call sale_stock module other warning
  43. res_packing = self.product_packaging_change(
  44. cr, uid, ids, pricelist, product, qty, uom, partner_id,
  45. packaging, context=context)
  46. res['value'].update(res_packing.get('value', {}))
  47. warning_msgs = res_packing.get(
  48. 'warning') and res_packing['warning']['message'] or ''
  49. if warning_msgs:
  50. warning = {
  51. 'title': _('Configuration Error!'),
  52. 'message': warning_msgs
  53. }
  54. else:
  55. # if not sale stock warning_try sale warnings
  56. product_change_res = self.product_id_change(
  57. cr, uid, ids, pricelist, product, qty=qty, uom=False,
  58. qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id,
  59. lang=lang, update_tax=update_tax, date_order=date_order,
  60. packaging=packaging, fiscal_position=fiscal_position,
  61. flag=flag, context=context)
  62. warning = product_change_res.get('warning')
  63. res.update({'warning': warning})
  64. return res
  65. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: