openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #00229
lp:~pedro.baeza/ocb-addons/account_invoice-reconciliation-fixes into lp:ocb-addons/6.1
Pedro Manuel Baeza has proposed merging lp:~pedro.baeza/ocb-addons/account_invoice-reconciliation-fixes into lp:ocb-addons/6.1.
Requested reviews:
OpenERP Community Backports Team (ocb)
For more details, see:
https://code.launchpad.net/~pedro.baeza/ocb-addons/account_invoice-reconciliation-fixes/+merge/188328
These are backports of revisions 8876 (http://bazaar.launchpad.net/~openerp/openobject-addons/7.0/revision/8876) and 9156 (http://bazaar.launchpad.net/~openerp/openobject-addons/7.0/revision/9156) of 7.0 branch, that fixes 'residual' field value when there is a reconciliation with multiple invoices.
--
https://code.launchpad.net/~pedro.baeza/ocb-addons/account_invoice-reconciliation-fixes/+merge/188328
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~pedro.baeza/ocb-addons/account_invoice-reconciliation-fixes into lp:ocb-addons/6.1.
=== modified file 'account/account_invoice.py'
--- account/account_invoice.py 2013-09-10 09:15:01 +0000
+++ account/account_invoice.py 2013-09-30 13:28:26 +0000
@@ -91,19 +91,44 @@
return [('none', _('Free Reference'))]
def _amount_residual(self, cr, uid, ids, name, args, context=None):
+ if context is None:
+ context = {}
+ ctx = context.copy()
result = {}
+ currency_obj = self.pool.get('res.currency')
for invoice in self.browse(cr, uid, ids, context=context):
- checked_partial_rec_ids = []
+ nb_inv_in_partial_rec = max_invoice_id = 0
result[invoice.id] = 0.0
if invoice.move_id:
- for move_line in invoice.move_id.line_id:
- if move_line.account_id.type in ('receivable','payable'):
- if move_line.reconcile_partial_id:
- partial_reconcile_id = move_line.reconcile_partial_id.id
- if partial_reconcile_id in checked_partial_rec_ids:
- continue
- checked_partial_rec_ids.append(partial_reconcile_id)
- result[invoice.id] += move_line.amount_residual_currency
+ for aml in invoice.move_id.line_id:
+ if aml.account_id.type in ('receivable','payable'):
+ if aml.currency_id and aml.currency_id.id == invoice.currency_id.id:
+ result[invoice.id] += aml.amount_residual_currency
+ else:
+ ctx['date'] = aml.date
+ result[invoice.id] += currency_obj.compute(cr, uid, aml.company_id.currency_id.id, invoice.currency_id.id, aml.amount_residual, context=ctx)
+
+ if aml.reconcile_partial_id.line_partial_ids:
+ #we check if the invoice is partially reconciled and if there are other invoices
+ #involved in this partial reconciliation (and we sum these invoices)
+ for line in aml.reconcile_partial_id.line_partial_ids:
+ if line.invoice:
+ nb_inv_in_partial_rec += 1
+ #store the max invoice id as for this invoice we will make a balance instead of a simple division
+ max_invoice_id = max(max_invoice_id, line.invoice.id)
+ if nb_inv_in_partial_rec:
+ #if there are several invoices in a partial reconciliation, we split the residual by the number
+ #of invoice to have a sum of residual amounts that matches the partner balance
+ new_value = currency_obj.round(cr, uid, invoice.currency_id, result[invoice.id] / nb_inv_in_partial_rec)
+ if invoice.id == max_invoice_id:
+ #if it's the last the invoice of the bunch of invoices partially reconciled together, we make a
+ #balance to avoid rounding errors
+ result[invoice.id] = result[invoice.id] - ((nb_inv_in_partial_rec - 1) * new_value)
+ else:
+ result[invoice.id] = new_value
+
+ #prevent the residual amount on the invoice to be less than 0
+ result[invoice.id] = max(result[invoice.id], 0.0)
return result
# Give Journal Items related to the payment reconciled to this invoice
Follow ups