sale.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #-*- coding:utf-8 -*-
  2. from openerp import models, api, _
  3. from openerp.exceptions import Warning
  4. from datetime import datetime, date
  5. class sale_order(models.Model):
  6. _inherit = "sale.order"
  7. @api.one
  8. def action_wait(self):
  9. self.check_limit()
  10. return super(sale_order, self).action_wait()
  11. @api.one
  12. def check_limit(self):
  13. # if self.order_policy == 'prepaid':
  14. if self.contado == True:
  15. return True
  16. # We sum from all the sale orders that are aproved, the sale order
  17. # lines that are not yet invoiced
  18. domain = [('order_id.partner_id', '=', self.partner_id.id),
  19. ('invoiced', '=', False),
  20. ('order_id.state', 'not in', ['draft', 'cancel', 'sent'])]
  21. order_lines = self.env['sale.order.line'].search(domain)
  22. none_invoiced_amount = sum([x.price_subtotal for x in order_lines])
  23. # We sum from all the invoices that are in draft the total amount
  24. domain = [
  25. ('partner_id', '=', self.partner_id.id), ('state', '=', 'draft')]
  26. draft_invoices = self.env['account.invoice'].search(domain)
  27. draft_invoices_amount = sum([x.amount_total for x in draft_invoices])
  28. available_credit = self.partner_id.credit_limit - \
  29. self.partner_id.credit - \
  30. none_invoiced_amount - draft_invoices_amount
  31. if self.amount_total > available_credit:
  32. msg = _('No se puede confirmar el Pedido ya que el cliente no tiene credito suficiente.\
  33. Cambia el límite de cliente en su ficha e intente de nuevo"')
  34. raise Warning(msg)
  35. return False
  36. return True
  37. # class sale_order(models.Model):
  38. # _inherit = "sale.order"
  39. #
  40. # @api.one
  41. # def action_wait(self):
  42. # self.check_limit()
  43. # # self.check_morosidad()
  44. # return super(sale_order, self).action_wait()
  45. #
  46. # @api.one
  47. # def check_limit(self):
  48. #
  49. # if self.contado == True:
  50. # return True
  51. #
  52. # available_credit = self.partner_id.credit_limit - self.partner_id.credit
  53. #
  54. # if self.amount_total > available_credit:
  55. # if not self.user_has_groups('partner_credito_limite.credit_config'):
  56. # msg = 'No se puede confirmar el Pedido ya que el cliente no tiene crédito suficiente.\
  57. # Pruebe marcar la opción "Contado"'
  58. # raise Warning(_(msg))
  59. # return False
  60. # return True
  61. #
  62. #