12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- # -*- coding: utf-8 -*-
- from __future__ import division
- from datetime import datetime
- from datetime import date, timedelta
- from dateutil.relativedelta import relativedelta
- import openerp.addons.decimal_precision as dp
- from openerp import models, fields, api
- from openerp.tools.float_utils import float_round as round, float_compare
- from openerp.osv import fields, osv
- from openerp.tools.translate import _
- class account_invoice(models.Model):
- _name = 'account.invoice'
- _inherit = 'account.invoice'
- def update_interest(self,cr,uid,value,context=None):
- date_ref = datetime.today().date()
- fecha = None
- interes = None
- # account invoice
- model_invoice_ids = self.pool.get('account.invoice').search(cr, uid,[('id', '=', value)], context=context)
- datos_invoice = self.pool.get('account.invoice').browse(cr, uid, model_invoice_ids, context=context)
- for account_in in datos_invoice:
- account_residual = account_in.residual
- account_total = account_in.amount_total
- # print("Calculando interest**********************************************")
- # account paymnet term line
- model_payment_term_line = self.pool.get('account.payment.term.line').search(cr, uid,[('payment_id', 'in', account_in.payment_term.ids)], context=context)
- datos_payment_term_line = self.pool.get('account.payment.term.line').browse(cr, uid, model_payment_term_line, context=context)
- for payment_line in datos_payment_term_line:
- interes = payment_line.interest_rate
- if interes <= 0:
- raise osv.except_osv('Advertencia','No fue Definida, la Condiciones de Pago')
- return
- # prodcuto prodcuto
- model_prodcuto = self.pool.get('product.product').search(cr, uid,[('name', '=', 'INTEREST')], context=context)
- datos_producto = self.pool.get('product.product').browse(cr, uid, model_prodcuto, context=context)
- # print("Producto")
- print(model_prodcuto)
- for productos_obj in datos_producto:
- print("producto")
- print(productos_obj.name_template)
- # journal
- model_journal = self.pool.get('account.journal').search(cr, uid,[('type', '=', 'sale')], context=context)
- datos_journal = self.pool.get('account.journal').browse(cr, uid, model_journal, context=context)
- # print(datos_journal)
- # account move line
- model_move_line = self.pool.get('account.move.line').search(cr, uid,[('reconcile_ref', '=', None),
- ('partner_id', 'in', account_in.partner_id.ids),
- ('ref', '=', account_in.reference),
- ('date_maturity', '<', date_ref)], context=context)
- datos_move_line = self.pool.get('account.move.line').browse(cr, uid, model_move_line, context=context)
- # print(datos_move_line)
- for move_line in datos_move_line:
- mesciere=move_line.month_interest_calculate
- datos_invoice = self.pool.get('account.invoice').browse(cr, uid, model_invoice_ids, context=context)
- for account_in in datos_invoice:
- account_residual = account_in.residual
- account_total = account_in.amount_total
- account_subtot = account_in.amount_untaxed
- ammount_interes = ((account_in.residual * interes)/100)
- model_move_line2 = self.pool.get('account.move.line').search(cr, uid,[('reconcile_ref', '=', None),
- ('partner_id', '=', account_in.partner_id.ids),
- ('ref', '=', account_in.reference),
- ('date_maturity', '<', date_ref),
- ('id', '=', move_line.id)], context=context)
- datos_move_line2 = self.pool.get('account.move.line').browse(cr, uid, model_move_line2, context=context)
- for moveline2 in datos_move_line2:
- fechavencimeito =moveline2.date_maturity
- if ((date_ref.month) > moveline2.month_interest_calculate):
- new_id=self.pool.get('account.invoice.line').create(cr, uid, { 'origin' : account_in.reference, 'create_uid' : '1', 'uos_id' : '1', 'account_id' : '113',
- 'sequence' : '10', 'invoice_id' : account_in.id, 'price_unit' : ammount_interes,
- 'price_subtotal' : ammount_interes, 'company_id' : '1', 'write_uid' : '1',
- 'discount' : '0.00', 'product_id' : productos_obj.id,
- 'partner_id' : moveline2.partner_id['id'], 'quantity' : '1',
- 'name' : 'Incumplimiento de pago / '+str(moveline2.date_maturity) }, context=context)
- self.pool.get('account.interest.line').create(cr, uid, {'origin' : account_in.reference, 'invoice_id' : account_in.id, 'price_subtotal' :ammount_interes,
- 'invoice_line_id' : new_id, 'name_product' : 'Incumplimiento de pago / '+str(moveline2.date_maturity),
- 'date' :date_ref, 'quantity' : '1', 'state' : True, 'interes_invoice' : account_in.id,
- 'move_line_id' : moveline2.id }, context=context)
- datos_invoice.write({'residual' : (account_residual+ammount_interes),
- 'amount_total' : (account_total+ammount_interes), 'amount_untaxed' : (account_subtot+ammount_interes)})
- datos_move_line2.write({'month_interest_calculate' : (date_ref.month)})
- datos_journal.write({'entry_posted' : True})
- datos_move_line2.write({'debit' : (moveline2.debit + ammount_interes)})
- datos_journal.write({'entry_posted' : False})
- # validar move_line
- model_move_line = self.pool.get('account.move.line').search(cr, uid,[('ref', '=', account_in.reference)], context=context)
- datos_move_line2 = self.pool.get('account.move.line').browse(cr, uid, model_move_line, context=context)
- for line_move in datos_move_line2:
- datos_move_line2.write({'state' : 'valid'})
|