2
# -*- encoding: utf-8 -*-
3
###########################################################################
4
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
7
# Credits######################################################
8
# Coded by: Humberto Arocha <hbto@vauxoo.com>
9
# Planified by: Rafael Silva <rsilvam@vauxoo.com>
10
# Audited by: Nhomar Hernandez <nhomar@vauxoo.com>
11
#############################################################################
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the GNU Affero General Public License as published by
14
# the Free Software Foundation, either version 3 of the License, or
15
# (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU Affero General Public License for more details.
22
# You should have received a copy of the GNU Affero General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
##########################################################################
28
from report import report_sxw
32
class aging_parser(report_sxw.rml_parse):
33
def __init__(self, cr, uid, name, context):
34
super(aging_parser, self).__init__(cr, uid, name, context=context)
35
self.localcontext.update({
38
'get_invoice_by_partner': self._get_invoice_by_partner,
39
'get_total_by_comercial': self._get_total_by_comercial,
40
'get_aged_lines': self._get_aged_lines,
43
def _get_aml(self, ids):
44
aml_obj = self.pool.get('account.move.line')
48
aml_gen = (aml_brw.debit and aml_brw.debit or aml_brw.credit *
49
-1 for aml_brw in aml_obj.browse(self.cr, self.uid, ids))
54
def _get_total_by_comercial(self, rp_brws):
55
ixp_gen = self._get_invoice_by_partner(rp_brws)
59
usr_id = ixp['rp_brw'].user_id and ixp[
60
'rp_brw'].user_id.id or False
62
if usr_dict.get(usr_id):
63
usr_dict[usr_id]['total'] += ixp['due_total']
66
'usr_brw': ixp['rp_brw'].user_id,
67
'total': ixp['due_total']
69
total += ixp['due_total']
72
return [{'total': total, 'vendor': (usr_dict[i] for i in usr_dict)}]
74
def _get_invoice_by_partner(self, rp_brws):
76
rp_obj = self.pool.get('res.partner')
77
inv_obj = self.pool.get('account.invoice')
78
mun_obj = self.pool.get('account.wh.munici.line')
79
for rp_brw in rp_brws:
80
inv_ids = inv_obj.search(
81
self.cr, self.uid, [('partner_id', '=', rp_brw.id),
82
('type', '=', 'out_invoice'), ('residual', '!=', 0), ('state', 'not in', ('cancel', 'draft'))])
93
'pay_left_total': 0.0,
97
for inv_brw in inv_obj.browse(self.cr, self.uid, inv_ids):
99
pay_ids = [aml.id for aml in inv_brw.payment_ids]
112
#~ refund_ids = inv_obj.search(self.cr,self.uid,[('parent_id','=',inv_brw.id),('type','=','out_refund'),('state','not in',('draft','cancel')),('move_id','!=',False)])
113
#~ refund_ids = inv_obj.search(self.cr,self.uid,[('parent_id','=',inv_brw.id),('type','=','out_refund'),('state','not in',('draft','cancel')),('move_id','!=',False)])
115
#~ refund_brws = refund_ids and inv_obj.browse(self.cr,self.uid,refund_ids) or []
116
#~ aml_gen = (refund_brw.move_id.line_id for refund_brw in refund_brws)
118
#~ for aml_brws in aml_gen:
119
#~ pay_refund_ids += [aml.id for aml in aml_brws if aml.account_id.id == inv_brw.account_id.id]
122
#~ ACUMULACION DE LOS NOPAGOS, OBTENCION DEL PAGO
123
pay_left_ids = list(set(pay_ids).difference(
128
wh_vat = self._get_aml(pay_vat_ids)
129
wh_islr = self._get_aml(pay_islr_ids)
130
wh_muni = self._get_aml(pay_muni_ids)
131
wh_src = self._get_aml([])
132
debit_note = self._get_aml([])
133
credit_note = self._get_aml(pay_refund_ids)
134
payment_left = self._get_aml(pay_left_ids)
135
payment = wh_vat + wh_islr + wh_muni + \
136
wh_src + debit_note + credit_note + payment_left
137
residual = inv_brw.amount_total + payment
138
date_due = mx.DateTime.strptime(
139
inv_brw.date_due or inv_brw.date_invoice, '%Y-%m-%d')
140
today = mx.DateTime.now()
141
due_days = (today - date_due).day
143
#~ TODO: Si se incluye un reporte de revisiones
144
#~ no se eliminara la factura
145
#~ si la factura no tiene saldo entonces
146
#~ no incluirla en el reporte
150
res[rp_brw.id]['inv_ids'].append({
156
'debit_note': debit_note,
157
'credit_note': credit_note,
158
'refund_brws': refund_brws,
160
'payment_left': payment_left,
161
'residual': residual,
164
res[rp_brw.id]['inv_total'] += inv_brw.amount_total
165
res[rp_brw.id]['wh_vat'] += wh_vat
166
res[rp_brw.id]['wh_islr'] += wh_islr
167
res[rp_brw.id]['wh_muni'] += wh_muni
168
res[rp_brw.id]['credit_note'] += credit_note
169
res[rp_brw.id]['pay_left_total'] += payment_left
170
res[rp_brw.id]['pay_total'] += payment
171
res[rp_brw.id]['due_total'] += residual
172
#~ TODO: Report donde no se elimine esta clave del diccionario
173
#~ y se use para revisiones internas
174
#~ Si no tiene saldo, sacarlo del reporte
175
not res[rp_brw.id]['due_total'] and res.pop(rp_brw.id)
177
#~ ordenando los registros en orden alfabetico
178
#~ si llegaran a existir
181
rp_ids = rp_obj.search(self.cr, self.uid, [(
182
'id', 'in', res.keys())], order='name asc')
184
res2.append(res[rp_id])
187
def _get_aged_lines(self, rp_brws, span=30, date_from=time.strftime('%Y-%m-%d')):
192
ixp_gen = self._get_invoice_by_partner(rp_brws)
205
'due_total':due_total,
212
'id' : ixp['rp_brw'].id,
213
'rp_brw' : ixp['rp_brw'],
225
'id': ixp['rp_brw'].id,
226
'rp_brw': ixp['rp_brw'],
236
for inv in ixp['inv_ids']:
237
res['total'] += inv['residual']
238
if inv['due_days'] <= 0:
239
res['not_due'] += inv['residual']
241
elif inv['due_days'] > 0 and inv['due_days'] <= 30:
242
res['1to30'] += inv['residual']
244
elif inv['due_days'] > 30 and inv['due_days'] <= 60:
245
res['31to60'] += inv['residual']
247
elif inv['due_days'] > 60 and inv['due_days'] <= 90:
248
res['61to90'] += inv['residual']
250
elif inv['due_days'] > 90 and inv['due_days'] <= 120:
251
res['91to120'] += inv['residual']
254
res['120+'] += inv['residual']
257
print 'THIS IS THE RESULT ', result
260
report_sxw.report_sxw(
261
'report.formal_due_report',
263
'addons/aging_due_report/report/formal_due_report.rml',
267
report_sxw.report_sxw(
268
'report.detail_due_report',
270
'addons/aging_due_report/report/detail_due_report.rml',
274
report_sxw.report_sxw(
275
'report.aging_due_report',
277
'addons/aging_due_report/report/aging_due_report.rml',
281
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: