linea_deuda.py 2.28 KB
# -*- coding: utf-8 -*-
from odoo import models, fields, api, exceptions
from odoo.exceptions import UserError, ValidationError

import odoo.addons.decimal_precision as dp
import math
import os

class vnt_linea_deuda(models.Model):
    _name = 'vnt.linea_deuda'

    ld_factura = fields.Many2one(
        string='Factura',
        comodel_name='asw.comprobante',
        ondelete='restrict',
        required=True,
    ) 

    ld_fecha_vto = fields.Datetime(
        string=u'Fecha de Vencimiento',
        related='ld_factura.comp_fecha_cancelacion'
    )

    ld_estado = fields.Selection(
        string=u'Estado Factura',
        related='ld_factura.comp_estado',
    )

    ld_total = fields.Float(
        string=u'Total Factura',
        compute="_compute_ld_total",
    )

    #no pude hacer funcionar la cosa como monetary, tuve q hacer el campo total como float 
    # ld_total = fields.Monetary(
    #     string=u'Total Factura',
    #     related='ld_factura.comp_total',
    # )

    # ld_moneda = fields.Many2one(
    #     string=u'Moneda',
    #     related='ld_factura.comp_moneda',
    # )

    # ld_moneda = fields.Many2one(
    #     string=u'Moneda',
    #     comodel_name='res.currency',
    #     ondelete='set null',
    #     default=lambda self: self.env.user.company_id.currency_id.id,
    # )

    ld_select = fields.Boolean(
        string="Seleccionar",
    )

    ld_nd = fields.Many2one(
        string='Nota Débito',
        comodel_name='asw.comprobante',
        ondelete='restrict',
    ) 

    ld_cobros = fields.Many2one(
        string='Cobros',
        comodel_name='vnt.cobros',
        ondelete='set null',
    )

    #calculo del total de la factura a traves de comp_total 
    @api.depends('ld_factura')
    def _compute_ld_total(self):
        for record in self:
            record.ld_total = record.ld_factura.comp_total 

    # #dominio p elegir solo facturas de venta, queda obsoleto pq las lineas se generaran en otra fx
    # @api.onchange('ld_factura')
    # def onchange_ld_factura(self):
    #     result = {}
    #     result['domain'] = []
    #     comp_venta_em = self.env['asw.comprobante'].search([('comp_talonario.tal_menu','=','fac'),('comp_tipo_comp','=','e')])
    #     result['domain'] = {'ld_factura' : [('id', 'in', comp_venta_em.ids)]}
    #     return result