cobros.py
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- 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='asw.cliente',
)
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",
compute="_compute_co_total_interes",
)
co_total = fields.Float(
string="Total",
compute="_compute_co_total",
)
co_deucarg = fields.Boolean(
string="Deudas cargadas",
default=False,
)
#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_lin_deuda')
def _compute_co_total_interes(self):
sumita = 0
for record in self:
for lin in record.co_lin_deuda:
if lin.ld_select == True:
sumita += lin.ld_interes
record.co_total_interes = 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
def traer_ld(self):
self.co_deucarg = True
#recupero comprobantes de venta, adeudados, con el cliente seleccionado
comp_venta_adeud = self.env['asw.comprobante'].search([('comp_talonario.tal_menu','=','fac'),('comp_tipo_comp','=','e'),('comp_estado', '=', 'a'),('comp_cliente', '=', self.co_cliente.id)])
for comp in comp_venta_adeud:
nva_linea = self.env['vnt.linea_deuda'].create({'ld_factura': comp.id, 'ld_cobros': self.id})