Selaa lähdekoodia

[FIX] Mejora en el cambio de estado de las lineas de interés

adrielso 6 vuotta sitten
vanhempi
commit
76bd463cce

+ 39 - 10
models/account_interest.py

@@ -55,18 +55,16 @@ class AccountInterest(models.Model):
 
 
         return super(AccountInterest, self).unlink()
         return super(AccountInterest, self).unlink()
 
 
-'''
-    Invoice
-'''
+''' Invoice '''
 class accountInvoiceInterest(models.Model):
 class accountInvoiceInterest(models.Model):
     _inherit = 'account.invoice'
     _inherit = 'account.invoice'
 
 
     interest_ids = fields.One2many('account.interest', 'invoice_id', string=' Account Interest')
     interest_ids = fields.One2many('account.interest', 'invoice_id', string=' Account Interest')
     is_interest = fields.Boolean('Factura de interés', default=False, help="Indica si esta factura fue generado por un interés.")
     is_interest = fields.Boolean('Factura de interés', default=False, help="Indica si esta factura fue generado por un interés.")
+    interest_line_ids = fields.One2many('account.interest.line', 'invoice', string=' Account Interest Line')
 
 
-    '''
-        Unlink Invoice
-    '''
+
+    '''  Unlink Invoice '''
     @api.multi
     @api.multi
     def unlink(self):
     def unlink(self):
         interestLine = self.env['account.interest.line'].search([('invoice.id', '=', self.id)])
         interestLine = self.env['account.interest.line'].search([('invoice.id', '=', self.id)])
@@ -83,10 +81,36 @@ class accountInvoiceInterest(models.Model):
 
 
         return super(accountInvoiceInterest, self).unlink()
         return super(accountInvoiceInterest, self).unlink()
 
 
+    @api.multi
+    def write(self, vals):
+        invoice = super(accountInvoiceInterest, self).write(vals)
 
 
-'''
-    partner
-'''
+        linesIds = map(lambda x: x.id, self.interest_line_ids)
+        if (linesIds):
+            interestLine = self.env['account.interest.line'].search([('id', 'in', linesIds)])
+
+            if (interestLine):
+                state = []
+                if (self.state == 'open'):
+                    state = {'state': 'invoiced'}
+
+                if (self.state == 'cancel'):
+                    state = {'state': 'invoice_cancel'}
+
+                if (self.state == 'draft'):
+                    state = {'state': 'invoice_draft'}
+
+                if (self.state == 'paid'):
+                    state = {'state': 'paid'}
+
+                if (state):
+                    for line in interestLine:
+                        line.write(state)
+
+        return True
+
+
+''' Partner '''
 class ResPartnerInterest(models.Model):
 class ResPartnerInterest(models.Model):
     _inherit = 'res.partner'
     _inherit = 'res.partner'
 
 
@@ -105,7 +129,12 @@ class AccountInterestLine(models.Model):
     expired_days = fields.Integer('Expired Days ')
     expired_days = fields.Integer('Expired Days ')
     invoice = fields.Many2one('account.invoice', string='Invoice Reference', index=True)
     invoice = fields.Many2one('account.invoice', string='Invoice Reference', index=True)
     reference = fields.Char(string='Invoice Reference', help="Invoice Reference")
     reference = fields.Char(string='Invoice Reference', help="Invoice Reference")
-    state = fields.Selection([('cancel','Cancelado'),('open','Abierto'),('invoiced','Facturado')],'Estado del pago', default="open")
+    state = fields.Selection([  ('discount','Descuento total'),
+                                ('open','Abierto'),
+                                ('invoiced','Facturado'),
+                                ('invoice_cancel', 'Factura Cancelada'),
+                                ('invoice_draft', 'Factura Borrador'),
+                                ('paid', 'Pagado')],'Estado del pago de la linea ', default="open")
     amount_dicount = fields.Float('amount disconut', digits_compute=dp.get_precision('Account'), help="Monto del descuento")
     amount_dicount = fields.Float('amount disconut', digits_compute=dp.get_precision('Account'), help="Monto del descuento")
 
 
 
 

+ 7 - 0
models/account_interest_config.py

@@ -20,6 +20,13 @@ class accountInterestConfig(models.Model):
     ''' Bloquear pagos '''
     ''' Bloquear pagos '''
     lock_move_line =  fields.Boolean('Bloquear la factura',default=True, help="Bloquear la factura cuando existan interés a pagar.")
     lock_move_line =  fields.Boolean('Bloquear la factura',default=True, help="Bloquear la factura cuando existan interés a pagar.")
 
 
+    ## forma de calculo de interes
+    # si  va calcular atomantico cunado entre en cliente
+    partner_calculate_automatic =  fields.Boolean('partner interest calculate',default=True, help = "Calcular interés de forma automática cuando entra el apartado del cliente")
+    # si  va calcular atomantico cunado entre en Factura
+    invoice_calculate_automatic = fields.Boolean('invoice interest calculate',default=True, help = "Calcular interés de forma automática cuando entra el apartado de la Factura")
+
+    # def _get_journal_invoice_sale():
 
 
     @api.model
     @api.model
     def create_default_interest_config(self):
     def create_default_interest_config(self):

+ 30 - 26
models/eiru_account_interest.py

@@ -239,30 +239,33 @@ class EiruAccountInterest(models.Model):
                 descrip = descrip+" Descuento %d" % (line['discount'])
                 descrip = descrip+" Descuento %d" % (line['discount'])
 
 
             if (accountInterestLine):
             if (accountInterestLine):
-                invoice_line.append([0,False, {
-                    'name': descrip,
-                    'account_id': interestConfig.line_account_id.id,
-                    'quantity': 1,
-                    'price_unit': round((accountInterestLine.amount_interest - line['discount']),decimal_precision),
-                    'price_subtotal': round((accountInterestLine.amount_interest - line['discount']),decimal_precision),
-                    'partner_id': accountInterest.customer_id.id,
-                    'invoice_line_tax_id': [(6, 0,[x.id for x in interestConfig.line_tax_id])],
-                }])
-
-        invoice = {
-            'partner_id': accountInterest.customer_id.id,
-            'currency_id': accountInterest.currency_id.id,
-            'date_invoice': dateServer,
-            'journal_id': interestConfig.invoice_journal_id.id,
-            'account_id': interestConfig.invoice_account_id.id,
-            'invoice_line': invoice_line,
-            'origin': '%s/%s' % (accountInterest.name, accountInterest.reference),
-            'is_interest': True
-        }
+                if (accountInterestLine.amount_interest > line['discount']):
+                    invoice_line.append([0,False, {
+                        'name': descrip,
+                        'account_id': interestConfig.line_account_id.id,
+                        'quantity': 1,
+                        'price_unit': round((accountInterestLine.amount_interest - line['discount']),decimal_precision),
+                        'price_subtotal': round((accountInterestLine.amount_interest - line['discount']),decimal_precision),
+                        'partner_id': accountInterest.customer_id.id,
+                        'invoice_line_tax_id': [(6, 0,[x.id for x in interestConfig.line_tax_id])],
+                    }])
+
+        accountInvoice=[]
+        if (invoice_line):
+            invoice = {
+                'partner_id': accountInterest.customer_id.id,
+                'currency_id': accountInterest.currency_id.id,
+                'date_invoice': dateServer,
+                'journal_id': interestConfig.invoice_journal_id.id,
+                'account_id': interestConfig.invoice_account_id.id,
+                'invoice_line': invoice_line,
+                'origin': '%s/%s' % (accountInterest.name, accountInterest.reference),
+                'is_interest': True
+            }
 
 
-        ''' Create / open /invoice '''
-        accountInvoice = self.env['account.invoice'].create(invoice)
-        accountInvoice.signal_workflow('invoice_open')
+            ''' Create / open /invoice '''
+            accountInvoice = self.env['account.invoice'].create(invoice)
+            accountInvoice.signal_workflow('invoice_open')
 
 
         for line in interestLine:
         for line in interestLine:
             accountInterestLine = self.env['account.interest.line'].browse(line['id'])
             accountInterestLine = self.env['account.interest.line'].browse(line['id'])
@@ -272,12 +275,13 @@ class EiruAccountInterest(models.Model):
                     moveLine.write({'date_interest': dateServer})
                     moveLine.write({'date_interest': dateServer})
 
 
                 accountInterestLine.write({
                 accountInterestLine.write({
-                    'invoice': accountInvoice.id,
-                    'reference':  accountInvoice.number,
-                    'state': 'invoiced',
+                    'invoice': accountInvoice.id if (accountInvoice and (line['interes'] > line['discount'])) else '',
+                    'reference':  accountInvoice.number if(accountInvoice and (line['interes'] > line['discount'])) else '',
+                    'state': 'invoiced' if (line['interes'] > line['discount']) else 'discount',
                     'amount_dicount': round(line['discount'],decimal_precision)
                     'amount_dicount': round(line['discount'],decimal_precision)
                 })
                 })
 
 
+
         return {
         return {
             'state': True,
             'state': True,
             'message': 'Operación exitosa'
             'message': 'Operación exitosa'

+ 18 - 2
static/src/js/verify_interest_invoice.js

@@ -7,6 +7,8 @@
     openerp.VerifyInterestInvoice = openerp.Widget.extend({
     openerp.VerifyInterestInvoice = openerp.Widget.extend({
         id: undefined,
         id: undefined,
         buttons: undefined,
         buttons: undefined,
+        accountInvoice: [],
+        insteresConfig: [],
         /* init */
         /* init */
         init: function(parent) {
         init: function(parent) {
             this._super(parent);
             this._super(parent);
@@ -30,15 +32,22 @@
                 return accountInvoice;
                 return accountInvoice;
             }).then(function(accountInvoice) {
             }).then(function(accountInvoice) {
                 self.accountInvoice = accountInvoice;
                 self.accountInvoice = accountInvoice;
-                if ((accountInvoice[0].state !== 'open') || (accountInvoice[0].type !=='out_invoice') || ((accountInvoice[0].state === 'open') && (accountInvoice[0].is_interest))){
+                return self.fetchAccountInterestConfig();
+            }).then(function(insteresConfig) {
+                self.insteresConfig =insteresConfig;
+                if (!insteresConfig[0].invoice_calculate_automatic) {
                     return false;
                     return false;
                 }
                 }
-                self.verifyInterestPartner(accountInvoice[0].id).then(function(results) {
+                if ((self.accountInvoice[0].state !== 'open') || (self.accountInvoice[0].type !=='out_invoice') || ((self.accountInvoice[0].state === 'open') && (self.accountInvoice[0].is_interest))){
+                    return false;
+                }
+                self.verifyInterestPartner(self.accountInvoice[0].id).then(function(results) {
                     return results;
                     return results;
                 }).then(function(results){
                 }).then(function(results){
                     instanceWeb.notification.do_warn("Atencion",results.message);
                     instanceWeb.notification.do_warn("Atencion",results.message);
                     return self.reloadPage();
                     return self.reloadPage();
                 });
                 });
+
             });
             });
         },
         },
         fetchInvoice: function(id){
         fetchInvoice: function(id){
@@ -47,6 +56,13 @@
             var domain=[['id', '=', id]]
             var domain=[['id', '=', id]]
             return  invoice.query(fields).filter(domain).all();
             return  invoice.query(fields).filter(domain).all();
         },
         },
+        /* account.interest.config */
+        fetchAccountInterestConfig: function(){
+            var config = new instanceWeb.Model('account.interest.config');
+            var fields =['id', 'name', 'invoice_calculate_automatic', 'partner_calculate_automatic'];
+            var domain=[['active', '=', true]]
+            return  config.query(fields).filter(domain).all();
+        },
         /* Verificar  interest */
         /* Verificar  interest */
         verifyInterestPartner: function(id) {
         verifyInterestPartner: function(id) {
             var bankStatement = new instanceWeb.Model('account.invoice');
             var bankStatement = new instanceWeb.Model('account.invoice');

+ 22 - 6
static/src/js/verify_interest_partner.js

@@ -7,6 +7,7 @@
     openerp.VerifyInterestPartner = openerp.Widget.extend({
     openerp.VerifyInterestPartner = openerp.Widget.extend({
         id: undefined,
         id: undefined,
         buttons: undefined,
         buttons: undefined,
+        insteresConfig: [],
         /* init */
         /* init */
         init: function(parent) {
         init: function(parent) {
             this._super(parent);
             this._super(parent);
@@ -26,13 +27,28 @@
         // /* Método inicial  */
         // /* Método inicial  */
         fetchInitial: function() {
         fetchInitial: function() {
             var self = this;
             var self = this;
-            self.verifyInterestPartner(self.id).then(function(results) {
-                return results;
-            }).then(function(results) {
-                instanceWeb.notification.do_warn("Atencion",results.message);
-                return self.reloadPage();
+            self.fetchAccountInterestConfig().then(function(insteresConfig){
+                return insteresConfig;
+            }).then(function(insteresConfig){
+                self.insteresConfig = insteresConfig;
+                if (!insteresConfig[0].partner_calculate_automatic){
+                    return false;
+                }
+                self.verifyInterestPartner(self.id).then(function(results) {
+                    return results;
+                }).then(function(results) {
+                    instanceWeb.notification.do_warn("Atencion",results.message);
+                    return self.reloadPage();
+                });
             });
             });
         },
         },
+        /* account.interest.config */
+        fetchAccountInterestConfig: function(){
+            var config = new instanceWeb.Model('account.interest.config');
+            var fields =['id', 'name', 'invoice_calculate_automatic', 'partner_calculate_automatic'];
+            var domain=[['active', '=', true]]
+            return  config.query(fields).filter(domain).all();
+        },
         /* Verificar  interest */
         /* Verificar  interest */
         verifyInterestPartner: function(id) {
         verifyInterestPartner: function(id) {
             var bankStatement = new instanceWeb.Model('res.partner');
             var bankStatement = new instanceWeb.Model('res.partner');
@@ -57,7 +73,7 @@
                         openerp.widgetInstanceInterestPartner.id = undefined;
                         openerp.widgetInstanceInterestPartner.id = undefined;
                         return;
                         return;
                     }
                     }
-                    
+
                     openerp.widgetInstanceInterestPartner.checkState(record.id);
                     openerp.widgetInstanceInterestPartner.checkState(record.id);
                     return;
                     return;
                 }
                 }

+ 1 - 1
views/account_interest.xml

@@ -28,7 +28,7 @@
                             <page string="Detalles">
                             <page string="Detalles">
                                 <div class="account-interes-invoice"></div>
                                 <div class="account-interes-invoice"></div>
                                 <field name="lines_ids" >
                                 <field name="lines_ids" >
-                                    <tree colors="blue:state == 'invoiced'; red:state == 'open'; gray:state == 'cancel'" string="Detalles de la deuda" editable="bottom" create="false" delete="false">
+                                    <tree colors="blue:state == 'invoiced'; red:state == 'open'; red:state =='invoice_cancel'; red:state =='invoice_draft'; gray:state == 'discount'; black:state == 'paid'" string="Detalles de la deuda" editable="bottom" create="false" delete="false">
                                         <field name="date_maturity" string="Vencimiento"/>
                                         <field name="date_maturity" string="Vencimiento"/>
                                         <field name="amount" string="Monto de la cuota"/>
                                         <field name="amount" string="Monto de la cuota"/>
                                         <field name="amount_residual" string="Saldo pendiente"/>
                                         <field name="amount_residual" string="Saldo pendiente"/>

+ 17 - 1
views/account_interest_config.xml

@@ -14,7 +14,7 @@
                             <field name='name'/>
                             <field name='name'/>
                         </h1>
                         </h1>
                         <notebook>
                         <notebook>
-                            <!-- Interest -->
+                            <!-- Configuración de interés -->
                             <page string="Configuración de interés.">
                             <page string="Configuración de interés.">
                                 <group col="2" string="Detalles del interés" >
                                 <group col="2" string="Detalles del interés" >
                                     <group>
                                     <group>
@@ -28,6 +28,22 @@
                                 <group>
                                 <group>
                                     <field name="comment" string="Información adicional"/>
                                     <field name="comment" string="Información adicional"/>
                                 </group>
                                 </group>
+                                <!-- Automatización del calculo de interés -->
+                                <group col="2" string="Automatización del calculo de interés">
+                                    <group>
+                                        <field name="partner_calculate_automatic" string="Calculo automático de interés en el cliente"/>
+                                        <div colspan="4">
+                                            * Permitir que el calculo de interés se realice automáticamente cuando ingresas en  el formulario del cliente.
+                                        </div>
+                                    </group>
+                                    <group>
+                                        <field name="invoice_calculate_automatic" string="Calculo automático de interés en la factura"/>
+                                        <div colspan="4">
+                                            * Permitir que el calculo de interés se realice automáticamente cuando ingresas en el formulario de la factura.
+                                        </div>
+                                    </group>
+                                </group>
+
                             </page>
                             </page>
                             <!-- Invoice && Line  -->
                             <!-- Invoice && Line  -->
                             <page string="Configuraciones de facturas">
                             <page string="Configuraciones de facturas">