sale.py 2.5 KB

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