Merge lp:~vauxoo/openerp-venezuela-localization/luiseev_fiscal_requeriments into lp:~openerp-venezuela/openerp-venezuela-localization/6.0-trunk

Proposed by Luis Escobar V. (Vauxoo)
Status: Merged
Merged at revision: 569
Proposed branch: lp:~vauxoo/openerp-venezuela-localization/luiseev_fiscal_requeriments
Merge into: lp:~openerp-venezuela/openerp-venezuela-localization/6.0-trunk
Diff against target: 76 lines (+37/-9)
1 file modified
l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py (+37/-9)
To merge this branch: bzr merge lp:~vauxoo/openerp-venezuela-localization/luiseev_fiscal_requeriments
Reviewer Review Type Date Requested Status
Gabriela Quilarque Pending
Review via email: mp+90310@code.launchpad.net

Description of the change

[FIX] Add method to unconcile payment.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py'
2--- l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py 2012-01-24 20:12:25 +0000
3+++ l10n_ve_fiscal_requirements/wizard/account_invoice_refund.py 2012-01-26 18:55:04 +0000
4@@ -241,17 +241,15 @@
5 def validate_total_payment_inv(self, cr, uid, ids, context=None):
6 """
7 Method that validate if invoice is totally paid.
8-
9+ @param ids: list of invoices.
10 return: True: if invoice is paid.
11 False: if invoice is not paid.
12 """
13+ res = False
14 inv_obj = self.pool.get('account.invoice')
15- for inv in inv_obj.browse(cr, uid, context.get('active_ids'), context=context):
16- if inv.reconciled:
17- raise osv.except_osv(_('Invoice Paid!'), \
18- _('The invoice refund can not be procesed because invoice "%s" was paid!' % inv.number))
19- return False
20- return True
21+ for inv in inv_obj.browse(cr, uid, ids, context=context):
22+ res = inv.reconciled
23+ return res
24
25 def validate_wh(self, cr, uid, ids, context=None):
26 """
27@@ -265,17 +263,47 @@
28 """
29 return True
30
31+ def unreconcile_paid_invoices(self, cr, uid, invoiceids, context=None):
32+ """
33+ Method that unreconcile the payments of invoice.
34+ @param invoiceids: list of invoices.
35+ return: True: unreconcile successfully.
36+ False: unreconcile unsuccessfully.
37+ """
38+ inv_obj = self.pool.get('account.invoice')
39+ moveline_obj = self.pool.get('account.move.line')
40+ voucher_pool = self.pool.get('account.voucher')
41+ res = True
42+ rec = []
43+ mid = []
44+ if self.validate_total_payment_inv(cr, uid, invoiceids, context=context):
45+ for inv in inv_obj.browse(cr, uid, invoiceids, context=context):
46+ movelineids = inv.move_line_id_payment_get(cr, uid,[inv.id])
47+ for moveline in moveline_obj.browse(cr, uid, movelineids,context=context):
48+ if moveline.reconcile_id:
49+ rec += [moveline.reconcile_id.id]
50+ if moveline.reconcile_partial_id:
51+ rec += [moveline.reconcile_partial_id.id]
52+ movelines = moveline_obj.search(cr, uid, [('|'),('reconcile_id','in',rec),('reconcile_partial_id','in',rec)],context=context)
53+ for mids in moveline_obj.browse(cr, uid, movelines, ['move_id']):
54+ mid +=[mids.move_id.id]
55+ voucherids = voucher_pool.search(cr, uid,[('move_id','in',mid)])
56+ if voucherids:
57+ voucher_pool.cancel_voucher(cr, uid, voucherids, context=context)
58+ else:
59+ res = False
60+ return res
61+
62 def invoice_refund(self, cr, uid, ids, context=None):
63 if context is None:
64 context = {}
65 if not self.validate_wh(cr, uid, context.get('active_ids'), context=context):
66 raise osv.except_osv(_('Error !'), \
67 _('There are non-valid withholds for the document which refund is being processed!' % inv.wh_iva_id.code ))
68+ self.unreconcile_paid_invoices(cr, uid, context.get('active_ids'), context=context)
69 data_refund = self.read(cr, uid, ids, [],context=context)[0]['filter_refund']
70 return self.compute_refund(cr, uid, ids, data_refund, context=context)
71
72-
73-
74 account_invoice_refund()
75
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: