1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- from openerp import models, api, _
- from openerp.exceptions import Warning
- from datetime import datetime, date
- class account_invoice(models.Model):
- _inherit = "account.invoice"
- def invoice_validate(self):
-
- self.check_morosidad()
- return super(account_invoice, self).invoice_validate()
- @api.one
- def check_limit(self):
- if self.order_policy == 'prepaid':
- return True
-
-
- domain = [('order_id.partner_id', '=', self.partner_id.id),
- ('invoiced', '=', False),
- ('order_id.state', 'not in', ['draft', 'cancel', 'sent'])]
- order_lines = self.env['sale.order.line'].search(domain)
- none_invoiced_amount = sum([x.price_subtotal for x in order_lines])
-
- domain = [
- ('partner_id', '=', self.partner_id.id), ('state', '=', 'draft')]
- draft_invoices = self.env['account.invoice'].search(domain)
- draft_invoices_amount = sum([x.amount_total for x in draft_invoices])
- available_credit = self.partner_id.credit_limit - \
- self.partner_id.credit - \
- none_invoiced_amount - draft_invoices_amount
- if self.amount_total > available_credit:
- msg = 'No se puede confirmar el Pedido ya que el cliente no tiene credito suficiente.\
- Puede pasar la politica de facturación del pedido a "Pago antes de envío" en la \
- pestaña "Otra información"'
- raise Warning(_(msg))
- return False
- return True
- @api.multi
- 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 (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
- @api.multi
- def save_payments_invoice(self,values):
- bank_payments_type_id = values['bankPayments']['bank_payments_type_id']
- payment_type = self.env['res.bank.payments.type'].search([('id', '=', bank_payments_type_id)])
- domain = [('id', '=', self.partner_id.id)]
- partner = self.env['res.partner'].search(domain)
-
- if payment_type.code == 'CH' and values['amountPayments'] > partner.check_limit:
-
- return {
- 'process': False,
- 'removeModal': False,
- 'message' : "El monto a pagar excede el límite de crédito concedido en cheques"
- }
- return super(account_invoice, self).save_payments_invoice()
|