Arnaud Pineux (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/7.0-bug-1008774-api into 
lp:openobject-addons/7.0.

Requested reviews:
  qdp (OpenERP) (qdp)
Related bugs:
  Bug #1008774 in OpenERP Addons: "partial reconciliation"
  https://bugs.launchpad.net/openobject-addons/+bug/1008774

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/7.0-bug-1008774-api/+merge/142332

Manual Reconciliation: Divide the amount proportionally to number of account 
move line.
(This is the resubmit of a previous branch trunk-bug-108774-api which were 
pushed wrong.)
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/7.0-bug-1008774-api/+merge/142332
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/7.0-bug-1008774-api.
=== modified file 'account/account_invoice.py'
--- account/account_invoice.py	2013-01-05 23:29:19 +0000
+++ account/account_invoice.py	2013-01-08 15:07:27 +0000
@@ -91,13 +91,45 @@
         return [('none', _('Free Reference'))]
 
     def _amount_residual(self, cr, uid, ids, name, args, context=None):
+        """ It's the function of the field residual and it computes the residual amount (balance) for each invoice"""
         result = {}
+        #cur_obj and currency are used to compute the rounded value (of balance) depending on the currency used
+        cur_obj = self.pool.get('res.currency')
+        currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id
+        #to_divide is a dictionary where key = invoice.id and 
+        #value = the divisor (the computed balance will be divided by this value)
+        to_divide = {}
+        #last is a dictionary where key = invoice.id and
+        #value = the id of the last invoice linked to the first invoice by partial reconcilation
+        last = {}
         for invoice in self.browse(cr, uid, ids, context=context):
+            to_divide[invoice.id] = 0
             result[invoice.id] = 0.0
             if invoice.move_id:
                 for m in invoice.move_id.line_id:
                     if m.account_id.type in ('receivable','payable'):
                         result[invoice.id] += m.amount_residual_currency
+                        #if the invoice belongs to a reconcilation:
+                        if m.reconcile_partial_id.line_partial_ids:
+                            #we add the number of line contains in each reconsilation in to_divide
+                            for line in m.reconcile_partial_id.line_partial_ids:
+                                if line.invoice:
+                                    to_divide[invoice.id] += 1
+                                    last[invoice.id] = line.invoice.id
+        check_last = last.itervalues()
+        #for each invoice
+        for invoice_id, amount in result.items():
+            #if we need to divide that invoice:
+            if to_divide.get(invoice_id):
+                #we compute the value (balance)
+                rounded_value = cur_obj.round(cr,uid,currency,amount / to_divide[invoice_id])
+                #if it's the last the value will be different because we don't want to loose any cent
+                #in the computation. For example 1000/3 rounded will give 333,33 but if multiply that by
+                #3 we will have 999.99 
+                if invoice_id in check_last:
+                    result[invoice_id] = result[invoice_id] - ((to_divide[invoice_id] - 1) * rounded_value)
+                else:
+                    result[invoice_id] = rounded_value
         return result
 
     # Give Journal Items related to the payment reconciled to this invoice

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : openerp-dev-gtk@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to