فهرست منبع

Interes atlhetic

sebas 4 سال پیش
کامیت
0c86861c4b

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from . import  model 

BIN
__init__.pyc


+ 13 - 0
__openerp__.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+{'name': 'Calculo de Interes',
+ 'version': '1.0',
+ 'author': 'Adrielso Kunert',
+ 'category': 'Accounting & Finance',
+ 'depends': ['sale'],
+ 'data': [  'data/product_data.xml',
+            'view/account_payment_term_view.xml',
+            'view/account_invoice.xml'],
+ 'installable': True,
+ 'auto_install': False,
+ }
+# 'view/account_interest_line.xml'

+ 12 - 0
data/product_data.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data noupdate="1">
+    <record id="product_product_sale_order_interest" model="product.product">
+      <field name="default_code">INTEREST</field>
+      <field name="list_price">0.0</field>
+      <field name="standard_price">0.0</field>
+      <field name="type">service</field>
+      <field name="name">INTEREST</field>
+    </record>
+  </data>
+</openerp>

+ 6 - 0
model/__init__.py

@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+
+from . import account_interest_line
+from . import account_payment_term_line
+from . import account_move_line
+from . import account_invoice

BIN
model/__init__.pyc


+ 154 - 0
model/account_interest_line.py

@@ -0,0 +1,154 @@
+# -*- coding: utf-8 -*-
+from openerp import models, fields, api
+from openerp.exceptions import ValidationError, Warning
+from datetime import datetime
+
+# mapping invoice type to journal type
+TYPE2JOURNAL = {
+    'out_invoice': 'sale',
+    'in_invoice': 'purchase',
+    'out_refund': 'sale_refund',
+    'in_refund': 'purchase_refund',
+}
+
+class account_interest_line(models.Model):
+    _name = "account.interest.line"
+    # _inherit = "account.interest.line"
+
+    origin = fields.Char(string='Source Document', help="Reference of the document that produced this invoice.")
+    invoice_id = fields.Many2one('account.invoice', string='Invoice Reference', ondelete='cascade', index=True, required=True)
+    invoice_line_id = fields.Many2one('account.invoice.line', string='Invoice line Reference', ondelete='cascade', index=True, required=True)
+    date  = fields.Date()
+    name_product = fields.Text(string='Description', required=True)
+    price_subtotal = fields.Float(string='Amount')
+    quantity = fields.Float(string='Quantity')
+    state = fields.Boolean()
+    partner_id = fields.Many2one('res.partner', string='Partner')
+    interes_invoice = fields.Many2one('account.invoice', string='Invoice Reference', ondelete='cascade', index=True, required=True)
+    move_line_id = fields.Many2one('account.move.line', string='Seguimiento de Pago ', ondelete='cascade', index=True, required=True)
+
+    @api.model
+    def _default_journal(self):
+        inv_type = self._context.get('type', 'out_invoice')
+        inv_types = inv_type if isinstance(inv_type, list) else [inv_type]
+        company_id = self._context.get('company_id', self.env.user.company_id.id)
+        domain = [
+            ('type', 'in', filter(None, map(TYPE2JOURNAL.get, inv_types))),
+            ('company_id', '=', company_id),
+        ]
+        return self.env['account.journal'].search(domain, limit=1)
+
+    journal_id = fields.Many2one('account.journal', string='Journal',
+        required=True, readonly=True, states={'draft': [('readonly', False)]},
+        default=_default_journal,
+        domain="[('type', 'in', {'out_invoice': ['sale'], 'out_refund': ['sale_refund'], 'in_refund': ['purchase_refund'], 'in_invoice': ['purchase']}.get(type, [])), ('company_id', '=', company_id)]")
+
+class invoice_interes(models.Model):
+    _inherit = "account.invoice"
+
+    interes_ids = fields.One2many('account.interest.line', inverse_name="invoice_id", string="id Interes")
+
+    @api.onchange('interes_ids')
+    def onchange_update(self):
+        for interest in self.interes_ids:
+            if interest.state == False:
+                interest_datos = self.env['account.interest.line'].search([('id','in', interest.ids)])
+                print(interest_datos.price_subtotal)
+                interest_datos.write({'state' : False})
+
+    def actualizarInteres(self, cr , uid, dato, context=None):
+        # print("*****Eliminado linea de Interes***********************************")
+        estado=None
+        # Obtener los datos de Interest Line (Linea de interes)
+        interes_model = self.pool.get('account.interest.line').search(cr, uid,[('interes_invoice', 'in', dato),
+                                                                               ('state', '=', False)],context=context)
+        interes_datos = self.pool.get('account.interest.line').browse(cr, uid, interes_model, context=context)
+        for interes in interes_datos:
+            # print(interes.name_product)
+            # Obtener los datos de invoice line (Iten de facturacion)
+            line_model = self.pool.get('account.invoice.line').search(cr, uid, [('id', '=', interes.invoice_line_id.ids)], context=context)
+            line_datos = self.pool.get('account.invoice.line').browse(cr, uid, line_model, context=context)
+            for line in line_datos:
+                # Obtener los datos de invoice para su actualizacion
+                invoice_model = self.pool.get('account.invoice').search(cr, uid, [('id', 'in', dato)],context=context)
+                invoice_dato  = self.pool.get('account.invoice').browse(cr, uid, invoice_model, context=context)
+                # Actualizar Invoice(facturacion)
+                invoice_dato.write({'residual' : (invoice_dato.residual - line.price_subtotal),
+                                    'amount_total' : (invoice_dato.amount_total - line.price_subtotal),
+                                    'amount_untaxed' : (invoice_dato.amount_untaxed - line.price_subtotal)})
+                # Actualar cuanta a pagr del cliente
+                # partner_model = self.pool.get('res.partner').search(cr, uid,[('id', '=', invoice_dato.partner_id.ids)], context=context)
+                # parthner_datos = self.pool.get('res.partner').browse(cr, uid, partner_model,context=context)
+                # parthner_datos.write({'payment_amount_due' :invoice_dato.residual})
+                # Otnere los linea de condicion de pago
+                payment_line_model = self.pool.get('account.payment.term.line').search(cr, uid, [('payment_id', 'in', invoice_dato.payment_term.ids)
+                                                                                                ], order='id', context=context)
+                payment_line_dato = self.pool.get('account.payment.term.line').browse(cr, uid, payment_line_model, context=context)
+                # print(payment_line_dato)
+                # Obtener Datos de Move Line
+                move_line_model = self.pool.get('account.move.line').search(cr, uid, [('reconcile_ref', '=', None), ('ref', '=', invoice_dato.reference),
+                                                                                      ('credit', '=', 0)], order='id', context=context)
+                # Obtener los registrode la lineas
+                move_line_modelp = self.pool.get('account.move.line').search(cr, uid, [('ref', '=', invoice_dato.reference), ('credit', '=', 0)], order='id', context=context)
+                # Retorna la cantidad de Registro de la Consulta
+                move_count = self.pool.get('account.move.line').search_count(cr, uid, [('reconcile_ref', '=', None), ('ref', '=', invoice_dato.reference),
+                                                                                        ('credit', '=', 0)], context=context)
+                # Selecionar todos los dactos de Move Line para su activacion
+                model_move_line1 = self.pool.get('account.move.line').search(cr, uid,[('ref', '=', invoice_dato.reference)], context=context)
+                datos_move_line2 = self.pool.get('account.move.line').browse(cr, uid, model_move_line1, context=context)
+                move_line_dato = self.pool.get('account.move.line').browse(cr, uid, move_line_model, context=context)
+                move_line_datosp = self.pool.get('account.move.line').browse(cr, uid, move_line_modelp, context=context)
+                # print(move_line_dato)
+                monto_cuota = invoice_dato.residual
+                # Obterner el registro de diario de ventas
+                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)
+                #Activar Modificacion
+                datos_journal.write({'entry_posted' : True})
+                # datos_move_line2.write({'debit' :  (moveline2.debit + ammount_interes)})
+                for move_line in move_line_datosp:
+                    # obterner move
+                    move_model = self.pool.get('account.move').search(cr, uid, [('id', 'in', move_line.move_id.ids)],context=context)
+                    move_dato = self.pool.get('account.move').browse(cr, uid, move_model, context=context)
+                    for move in move_dato:
+                        estado = move.state
+                        # Obtener pagos
+                        # print('voucher')
+                        # voucher_model = self.pool.get('account.voucher').search(cr, uid, [('move_id', 'in', move.id)],context=context)
+                        # voucher_dato = self.pool.get('account.voucher').browse(cr, uid, voucher_model,context=context)
+                        # for voucher in voucher_dato:
+                        # obtener ls linea de pagos
+                        line_voucher_model = self.pool.get('account.voucher.line').search(cr, uid, [('move_line_id', 'in', move_line.ids),
+                                                                                                    ('amount', '>', 0), ('reconcile', '=', False)],context=context)
+                        line_voucher_dato = self.pool.get('account.voucher.line').browse(cr, uid, line_voucher_model,context=context)
+                        for voucher_line in line_voucher_dato:
+                            monto_cuota =(monto_cuota - (voucher_line.amount_original - voucher_line.amount))
+                move_dato.write({'state' : 'draft'})
+                c=0
+                montototal=0
+                for line_move in move_line_dato:
+                    c +=1
+                    if c <= (move_count-1):
+                        move_line = self.pool.get('account.move.line').search(cr, uid, [('id', '=', line_move.ids)], context=context)
+                        move_line_browse = self.pool.get('account.move.line').browse(cr, uid, move_line, context=context)
+                        monto_cuota1= (monto_cuota*0.33)
+                        montototal +=monto_cuota1
+                        move_line_browse.write({'debit' : monto_cuota1})
+                    else:
+                        if c == move_count:
+                            move_line = self.pool.get('account.move.line').search(cr, uid, [('id', '=', line_move.ids)], context=context)
+                            move_line_browse = self.pool.get('account.move.line').browse(cr, uid, move_line, context=context)
+                            monto_cuota1= (monto_cuota - montototal)
+                            move_line_browse.write({'debit' : monto_cuota1})
+                if  estado == None:
+                    estado='draft'
+                move_dato.write({'state' : estado})
+                #Desativar Modificacion
+                datos_journal.write({'entry_posted' : False})
+                # Activar Move line
+                datos_move_line2.write({'state' : 'valid'})
+                # Eliminar Invoice Line ------------------------------------------------------
+                self.pool.get('account.invoice.line').unlink(cr, uid,line.ids,context=context)
+            # Eliminar linea de account.interest.line  cuando su estado esta en fase ----------
+            self.pool.get('account.interest.line').unlink(cr, uid, interes.ids, context=context)
+        print("*****************************************************************")

BIN
model/account_interest_line.pyc


+ 97 - 0
model/account_invoice.py

@@ -0,0 +1,97 @@
+# -*- 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'})

BIN
model/account_invoice.pyc


+ 10 - 0
model/account_move_line.py

@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+
+
+from openerp import models, fields, api, exceptions, _
+
+class account_move_line(models.Model):
+    _name = "account.move.line"
+    _inherit = "account.move.line"
+
+    month_interest_calculate = fields.Integer(digits=(2))

BIN
model/account_move_line.pyc


+ 17 - 0
model/account_payment_term_line.py

@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+
+
+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
+
+
+class AccountPaymentTermLine(models.Model):
+    _inherit = 'account.payment.term.line'
+
+    interest_rate = fields.Float(string='Tasa de Interés',
+                                 digits =dp.get_precision('Payment Term'),
+                                 help="El interes mensual de cliente con atraso."
+                                      "Valor de 0 a 100.\n"
+                                      "El interes se calcula como: \n"
+                                      "(Saldo Pendiente*(tasa de interes/100))")

BIN
model/account_payment_term_line.pyc


BIN
static/description/icon.png


+ 35 - 0
view/account_interest_line.xml

@@ -0,0 +1,35 @@
+<!-- <?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+    <record model="ir.ui.view" id="view_interest_line_form">
+      <field name="name">view.account.interest.line.form</field>
+      <field name="model">account.invoice</field>
+      <field name="priority">30</field>
+      <field name="arch" type="xml">
+        <form string="Interest Line">
+         <header class="oe_highlight">
+           <button name="search_interest" string="Buscar" type="object" class="oe_link"  groups="base.group_user"/>
+           <button name="search_interest" string="Buscar" class="oe_highlight" type="object"/>
+         </header>
+         <notebook>
+             <page string="Intereses">
+               <button name="actualizarInteres" type="object"  string="Actualizar" class="oe_link" groups="base.group_user"/>
+               <field name="interes_ids" nolabel='1' >
+                 <tree string="Intereses" editable='button' delete='false' create='false'  domain="[('state','=',False)]">
+                   <field name="name_product" string="Decripcion" readonly="1"/>
+                   <field name="price_subtotal" string="Monto Interes" readonly="1"/>
+                   <field name="date" string="Fecha de Creacion" readonly="1"/>
+                   <field name="state" string="Estado"/>
+                 </tree>
+               </field>
+             </page>
+         </notebook>
+         <footer>
+          <button name="button_deleted_interest" string="Guardar" class="oe_link" type="object"/>or
+          <button string="Cancel" class="oe_link" special="cancel"/>
+         </footer>
+       </form>
+      </field>
+    </record>
+  </data>
+</openerp> -->

+ 48 - 0
view/account_invoice.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <record id="interest_account_invoice_form" model="ir.ui.view">
+      <field name="name">account.invoice.form</field>
+      <field name="model">account.invoice</field>
+      <field name="inherit_id" ref="account.invoice_form"/>
+      <field name="arch" type="xml">
+        <xpath expr="//field[@name='date_invoice']" position="before">
+            <label for="date_invoice" string="Recalcular intereses" />
+          <div>
+            <field name="date_invoice" class="oe_inline" options="{'no_create': True}"/>
+            <button name="update_interest"  states="open"
+                    string="Actualizar Interes" class="oe_link"
+                    type="object" help="Recalcular intereses"/>
+          </div>
+            <!-- <label for="date_invoice" string="Eliminar intereses"/>
+          <div>
+          <field name="date_invoice" class="oe_inline" options="{'no_create': True}"/>
+            <button name="delet_interest" type="object"  string="Eliminar Interes" states="open"
+                    class="oe_link" attrs="{'invisible': ['|', ('state','!=','open'), ('sent','=',True)]}" groups="base.group_user"/>
+          </div> -->
+        </xpath>
+      </field>
+    </record>
+    <record id="invoice_interest" model="ir.ui.view">
+      <field name="name">account.invoice_interest</field>
+      <field name="model">account.invoice</field>
+      <field name="inherit_id" ref="account.invoice_form"/>
+      <field name="arch" type="xml">
+        <notebook>
+            <page string="Intereses">
+              <button name="actualizarInteres" type="object"  string="Actualizar Linea de Interes"
+                      class="oe_link" groups="base.group_user" attrs="{'invisible': ['|', ('state','!=','open'), ('sent','=',True)]}"/>
+              <field name="interes_ids" nolabel='1'  attrs="{'invisible': ['|', ('state','!=','open'), ('sent','=',True)]}">
+                <tree string="Intereses" editable='bottom' delete='false' create='false'  >
+                  <field name="name_product" string="Decripcion" readonly="1"/>
+                  <field name="price_subtotal" string="Monto Interes" readonly="1"/>
+                  <field name="date" string="Fecha de Creacion" readonly="1"/>
+                  <field name="state" string="Estado"/>
+                </tree>
+              </field>
+            </page>
+        </notebook>
+      </field>
+    </record>
+  </data>
+</openerp>

+ 26 - 0
view/account_payment_term_view.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data noupdate="0">
+
+    <record id="view_payment_term_line_tree" model="ir.ui.view">
+      <field name="name">account.payment.term.line.tree</field>
+      <field name="model">account.payment.term.line</field>
+      <field name="inherit_id" ref="account.view_payment_term_line_tree"/>
+      <field name="arch" type="xml">
+        <field name="days2" position="after">
+          <field name="interest_rate"/>
+        </field>
+      </field>
+    </record>
+    <record id="view_payment_term_line_form" model="ir.ui.view">
+      <field name="name">account.payment.term.line.form</field>
+      <field name="model">account.payment.term.line</field>
+      <field name="inherit_id" ref="account.view_payment_term_line_form"/>
+      <field name="arch" type="xml">
+        <xpath expr="/form/group/group[1]" position="inside">
+          <field name="interest_rate"/>
+        </xpath>
+      </field>
+    </record>
+  </data>
+</openerp>