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

Requested reviews:
  OpenERP Core Team (openerp)
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/trunk-bug-1008774-api/+merge/133682

See Account/Account_invoice.py
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-1008774-api/+merge/133682
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-1008774-api.
=== modified file 'account/account_invoice.py'
--- account/account_invoice.py	2012-11-02 09:21:06 +0000
+++ account/account_invoice.py	2012-11-09 14:28:40 +0000
@@ -88,13 +88,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

=== modified file 'account/account_move_line.py'
--- account/account_move_line.py	2012-11-08 11:34:23 +0000
+++ account/account_move_line.py	2012-11-09 14:28:40 +0000
@@ -119,6 +119,7 @@
         if context is None:
             context = {}
         cur_obj = self.pool.get('res.currency')
+        i = 1
         for move_line in self.browse(cr, uid, ids, context=context):
             res[move_line.id] = {
                 'amount_residual': 0.0,
@@ -130,7 +131,6 @@
             if not move_line.account_id.type in ('payable', 'receivable'):
                 #this function does not suport to be used on move lines not related to payable or receivable accounts
                 continue
-
             if move_line.currency_id:
                 move_line_total = move_line.amount_currency
                 sign = move_line.amount_currency < 0 and -1 or 1
@@ -153,7 +153,6 @@
                         else:
                             move_line_total += (payment_line.debit - payment_line.credit)
                     line_total_in_company_currency += (payment_line.debit - payment_line.credit)
-
             result = move_line_total
             res[move_line.id]['amount_residual_currency'] =  sign * (move_line.currency_id and self.pool.get('res.currency').round(cr, uid, move_line.currency_id, result) or result)
             res[move_line.id]['amount_residual'] = sign * line_total_in_company_currency

=== modified file 'analytic/analytic.py'
--- analytic/analytic.py	2012-11-02 16:16:29 +0000
+++ analytic/analytic.py	2012-11-09 14:28:40 +0000
@@ -98,7 +98,12 @@
 
     def name_get(self, cr, uid, ids, context=None):
         res = []
-        for id in ids:
+        full_ids = []
+        if isinstance(ids,list):
+            full_ids.extend(ids)
+        else:
+            full_ids.append(ids)
+        for id in full_ids:
             elmt = self.browse(cr, uid, id, context=context)
             res.append((id, self._get_one_full_name(elmt)))
         return res

=== modified file 'project/project.py'
--- project/project.py	2012-11-08 10:09:47 +0000
+++ project/project.py	2012-11-09 14:28:40 +0000
@@ -203,11 +203,7 @@
     
     def attachment_tree_view(self, cr, uid, ids, context):
         task_ids = self.pool.get('project.task').search(cr, uid, [('project_id', 'in', ids)])
-        domain = [
-            ('|', 
-             '&', 'res_model', '=', 'project.project'), ('res_id', 'in', ids),
-             '&', ('res_model', '=', 'project.task'), ('res_id', 'in', task_ids)
-		]
+        domain = ['|', '&', ('res_model', '=', 'project.project'), ('res_id', 'in', ids), '&', ('res_model', '=', 'project.task'), ('res_id', 'in', task_ids)]
         res_id = ids and ids[0] or False
         return {
             'name': _('Attachments'),

=== modified file 'project_timesheet/project_timesheet.py'
--- project_timesheet/project_timesheet.py	2012-10-29 05:45:52 +0000
+++ project_timesheet/project_timesheet.py	2012-11-09 14:28:40 +0000
@@ -199,8 +199,8 @@
 
                 if amount_unit and 'amount' in amount_unit.get('value',{}):
                     vals_line['amount'] = amount_unit['value']['amount']
-
-            self.pool.get('hr.analytic.timesheet').write(cr, uid, [line_id.id], vals_line, context=context)
+            if line_id.sheet_id.state in ['confirm' 'done']:
+                self.pool.get('hr.analytic.timesheet').write(cr, uid, [line_id.id], vals_line, context=context)
 
         return super(project_work,self).write(cr, uid, ids, vals, context)
 
@@ -241,7 +241,6 @@
             if vals.get('project_id',False):
                 project_obj = self.pool.get('project.project').browse(cr, uid, vals['project_id'], context=context)
                 acc_id = project_obj.analytic_account_id.id
-
             for task_obj in self.browse(cr, uid, ids, context=context):
                 if len(task_obj.work_ids):
                     for task_work in task_obj.work_ids:

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to