123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #-*- coding:utf-8 -*-
- from openerp import models, api, _
- from openerp.exceptions import Warning
- from datetime import datetime, date
- class sale_order(models.Model):
- _inherit = "sale.order"
- @api.one
- def action_wait(self):
- self.check_limit()
- self.check_morosidad()
- return super(sale_order, self).action_wait()
- @api.one
- def check_limit(self):
- if self.contado == True:
- return True
- available_credit = self.partner_id.credit_limit - self.partner_id.credit
- if self.amount_total > available_credit:
- msg = 'No se puede confirmar el Pedido ya que el cliente no tiene crédito suficiente.\
- Pruebe marcar la opción "Contado"'
- raise Warning(_(msg))
- return False
- return True
- @api.one
- def check_morosidad(self):
- now = datetime.now()
- hoy = datetime.strptime(now.strftime("%Y-%m-%d"),"%Y-%m-%d")
- domain = [('id', '=', self.partner_id.id)]
- partner = self.env['res.partner'].search(domain)
- invoices = self.env['account.invoice'].search([('partner_id', '=',self.partner_id.id),('state', '=','open'),('type', '=', 'out_invoice'),('journal_id.type','=','sale')])
- for item in invoices:
- moveLine = self.env['account.move.line'].search([('move_id','=', item.move_id.id),('debit','>',0)])
- if moveLine.date_maturity < now.strftime("%Y-%m-%d"):
- vencimiento = datetime.strptime(moveLine.date_maturity,"%Y-%m-%d")
- if partner.morosidad > 0 and (hoy-vencimiento).days > partner.morosidad:
- raise Warning(_("El cliente %s tiene cuotas vencidas con más de %s días de atraso") % (partner.name, partner.morosidad))
- return False
- return True
|