cobros.py 1.31 KB
# -*- coding: utf-8 -*-
#from odoo.exceptions import UserError
from odoo import models, fields, api
#from datetime import datetime

class vnt_cobros(models.Model):
    _name = 'vnt.cobros'

    co_cliente = fields.Many2one(
        string='Cliente',
        comodel_name='hgt.instituciones',
    )

    co_lin_deuda = fields.One2many(
        string=u"Línea Deuda",
        comodel_name='vnt.linea_deuda',
        inverse_name='ld_cobros',
    )

    co_resumen = fields.Text(
        string="Resumen",
    )

    co_total_deuda = fields.Float(
        string="Total Deuda",
        compute="_compute_co_total_deuda",

    )

    co_total_interes = fields.Float(
        string=u"Total Interés",
    )

    co_total = fields.Float(
        string="Total",
        compute="_compute_co_total",
    )


    #Calculos de totales 
    @api.depends('co_lin_deuda')
    def _compute_co_total_deuda(self):
        sumita = 0
        for record in self:
            for lin in record.co_lin_deuda:
                if lin.ld_select == True: 
                    sumita += lin.ld_total
            record.co_total_deuda = sumita 

    @api.depends('co_total_deuda', 'co_total_interes')
    def _compute_co_total(self):
        sumita = 0
        for record in self:
            record.co_total = record.co_total_deuda + record.co_total_interes