Browse Source

[ADD] configuracion de bloqueo de factura

adrielso 6 years ago
parent
commit
0d156c9863

+ 10 - 0
models/account_interest.py

@@ -36,6 +36,7 @@ class accountInvoiceInterest(models.Model):
     _inherit = 'account.invoice'
 
     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.")
 
 '''
     partner
@@ -60,3 +61,12 @@ class AccountInterestLine(models.Model):
     reference = fields.Char(string='Invoice Reference', help="Invoice Reference")
     state = fields.Selection([('cancel','Cancelado'),('open','Abierto'),('invoiced','Facturado')],'Estado del pago', default="open")
     amount_dicount = fields.Float('amount disconut', digits_compute=dp.get_precision('Account'), help="Monto del descuento")
+
+'''
+    Move Line
+'''
+class accountMoveLineInterest(models.Model):
+    _inherit = 'account.move.line'
+
+    interest_line_ids = fields.One2many('account.interest.line', 'move_line_id', string=' Account Interest Line')
+    date_interest = fields.Date("Date interés", help="Fecha de la facturación de os interés")

+ 3 - 0
models/account_interest_config.py

@@ -17,6 +17,9 @@ class accountInterestConfig(models.Model):
     ''' Line '''
     line_account_id = fields.Many2one('account.account', string='Account', required=True, domain=[('type', '=', 'other')])
     line_tax_id = fields.Many2one('account.tax', string='Tax', domain=[('type_tax_use', '=', 'sale')])
+    ''' Bloquear pagos '''
+    lock_move_line =  fields.Boolean('Bloquear la factura',default=True, help="Bloquear la factura cuando existan interés a pagar.")
+
 
     @api.model
     def create_default_interest_config(self):

+ 29 - 4
models/eiru_account_interest.py

@@ -59,12 +59,16 @@ class EiruAccountInterest(models.Model):
         }for interest in self.env['account.interest'].browse(id)]
 
     '''
-        get Account Invoice
+       ____                           _         ___       _                     _
+      / ___| ___ _ __   ___ _ __ __ _| |_ ___  |_ _|_ __ | |_ ___ _ __ ___  ___| |_
+     | |  _ / _ \ '_ \ / _ \ '__/ _` | __/ _ \  | || '_ \| __/ _ \ '__/ _ \/ __| __|
+     | |_| |  __/ | | |  __/ | | (_| | ||  __/  | || | | | ||  __/ | |  __/\__ \ |_
+      \____|\___|_| |_|\___|_|  \__,_|\__\___| |___|_| |_|\__\___|_|  \___||___/\__|
     '''
     @api.model
     def get_account_invoice_interest(self, invoice=None, partner=None):
         _logger.info('Verify invoice')
-        domain = [('state', '=', 'open')]
+        domain = [('state', '=', 'open'),('is_interest', '=', False)]
 
         if (invoice):
             domain.append(('id', '=', invoice))
@@ -75,6 +79,8 @@ class EiruAccountInterest(models.Model):
         for invoice in accountInvoice:
             self.get_move_line_in_invoice(invoice.id)
 
+        return True
+
     '''
         Get move Line.
     '''
@@ -87,14 +93,23 @@ class EiruAccountInterest(models.Model):
         domain = [('state','!=','draft'), ('credit','<=', 0), ('partner_id','=',accountInvoice.partner_id.id),('invoice','=',accountInvoice.id)]
         for line in self.env['account.move.line'].search(domain):
             expiredDays = dateServer - self._convert_str_to_datetime(line.date_maturity)
+            if (line.date_interest):
+                expiredDays = dateServer - self._convert_str_to_datetime(line.date_interest)
+
             if ((line.amount_residual <= 0) or (expiredDays.days <= 0)):
                 continue
 
             ''' verify account.interest '''
             accountInterest = self.eiru_create_account_interest(accountInvoice.id)
+            if (not accountInterest):
+                return {'state': False}
 
             ''' verify account.interest.line '''
             interrstLine = self.eiru_create_account_interest_lines(accountInvoice.id, accountInterest.id, line.id, expiredDays.days)
+            if (not interrstLine):
+                return {'state': False}
+
+        return True
 
     '''
         Create Account Interest
@@ -129,7 +144,8 @@ class EiruAccountInterest(models.Model):
         accountInterest = self.env['account.interest'].browse(interestID)
         moveLine = self.env['account.move.line'].browse(moveId)
         interestConfig = self.env['account.interest.config'].search([('active', '=', True)])
-        interestLine = self.env['account.interest.line'].search([('interest_id.id', '=', accountInterest.id),('move_line_id.id', '=',moveLine.id)])
+        domain = [('interest_id.id', '=', accountInterest.id),('move_line_id.id', '=',moveLine.id),('state', '=', 'open')]
+        interestLine = self.env['account.interest.line'].search(domain)
 
         decimalPlaces = accountInvoice.currency_id.decimal_places
         if (not decimalPlaces):
@@ -145,7 +161,7 @@ class EiruAccountInterest(models.Model):
             'expired_days': expiredDays,
             'amount_residual': round(amount_residual,decimalPlaces),
             'amount_interest': round((expiredDays * (amount_residual * (interestConfig.interest_rate / 100))),decimalPlaces),
-            'interest_id': accountInterest.id
+            'interest_id': accountInterest.id,
         }
 
         if (not interestLine):
@@ -203,13 +219,22 @@ class EiruAccountInterest(models.Model):
             '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')
+
         for line in interestLine:
             accountInterestLine = self.env['account.interest.line'].browse(line['id'])
             if (accountInterestLine):
+                moveLine = self.env['account.move.line'].browse(accountInterestLine.move_line_id.id)
+                if (moveLine):
+                    moveLine.write({'date_interest': dateServer})
+
                 accountInterestLine.write({
                     'invoice': accountInvoice.id,
                     'reference':  accountInvoice.number,

+ 0 - 2
models/res_partner_interest.py

@@ -4,8 +4,6 @@ from openerp import models, fields, tools, api, _
 class ResPartnerInterest(models.Model):
     _inherit = 'res.partner'
 
-    '''
-    '''
     @api.model
     def eiru_account_interest_verify(self, id):
         interest = self. env['account.interest']

+ 1 - 2
views/account_interest.xml

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

+ 3 - 0
views/account_interest_config.xml

@@ -21,6 +21,9 @@
                                         <field name="interest_rate_year" on_change='1'/>
                                         <field name="interest_rate" on_change='1'/>
                                     </group>
+                                    <group>
+                                        <field name="lock_move_line"/>
+                                    </group>
                                 </group>
                                 <group>
                                     <field name="comment" string="Información adicional"/>