← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/trunk-bug-725028-skh into lp:openobject-addons

 

Somesh Khare(OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-bug-725028-skh into lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #725028 in OpenERP Addons: "[6.0] sale.order picked_rate is wrong"
  https://bugs.launchpad.net/openobject-addons/+bug/725028

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-725028-skh/+merge/57666

Hello,

[Fix]: [6.0] sale.order picked_rate is wrong

Thanks
skh
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-725028-skh/+merge/57666
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-bug-725028-skh.
=== modified file 'project/project.py'
--- project/project.py	2011-04-07 11:41:45 +0000
+++ project/project.py	2011-04-14 11:52:28 +0000
@@ -334,6 +334,7 @@
 
     # Compute: effective_hours, total_hours, progress
     def _hours_get(self, cr, uid, ids, field_names, args, context=None):
+
         res = {}
         cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id IN %s GROUP BY task_id",(tuple(ids),))
         hours = dict(cr.fetchall())
@@ -345,6 +346,7 @@
                 res[task.id]['progress'] = round(min(100.0 * hours.get(task.id, 0.0) / res[task.id]['total_hours'], 99.99),2)
             if task.state in ('done','cancelled'):
                 res[task.id]['progress'] = 100.0
+        
         return res
 
 

=== modified file 'project_mrp/project_mrp.py'
--- project_mrp/project_mrp.py	2011-01-14 00:11:01 +0000
+++ project_mrp/project_mrp.py	2011-04-14 11:52:28 +0000
@@ -26,7 +26,8 @@
     _name = "project.task"
     _inherit = "project.task"
     _columns = {
-        'procurement_id': fields.many2one('procurement.order', 'Procurement', ondelete='set null')
+        'procurement_id': fields.many2one('procurement.order', 'Procurement', ondelete='set null'),
+        'sale_id': fields.many2one('sale.order','Sale Order')
     }
 
     def _validate_subflows(self, cr, uid, ids):
@@ -44,7 +45,8 @@
         res = super(project_task, self).do_cancel(cr, uid, ids, *args, **kwargs)
         self._validate_subflows(cr, uid, ids)
         return res
-
+   
+    
 project_task()
 
 class product_product(osv.osv):
@@ -55,4 +57,5 @@
 product_product()
 
 
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'project_mrp/project_mrp_view.xml'
--- project_mrp/project_mrp_view.xml	2011-01-14 00:11:01 +0000
+++ project_mrp/project_mrp_view.xml	2011-04-14 11:52:28 +0000
@@ -24,6 +24,8 @@
                 </field>
             </field>
         </record>
+        
+
     
     </data>
 </openerp>

=== modified file 'project_mrp/project_procurement.py'
--- project_mrp/project_procurement.py	2011-02-02 13:24:37 +0000
+++ project_mrp/project_procurement.py	2011-04-14 11:52:28 +0000
@@ -27,7 +27,8 @@
     _name = "procurement.order"
     _inherit = "procurement.order"
     _columns = {
-        'task_id': fields.many2one('project.task', 'Task')
+        'task_id': fields.many2one('project.task', 'Task'),
+        'sale_line_id': fields.many2one('sale.order.line', 'Sale order line')
     }
     def check_produce_service(self, cr, uid, procurement, context=None):
         return True
@@ -49,10 +50,87 @@
                 'project_id': procurement.product_id.project_id and procurement.product_id.project_id.id or False,
                 'state': 'draft',
                 'company_id': procurement.company_id.id,
+                'sale_id':procurement.sale_line_id.order_id.id
             },context=context)
-            self.write(cr, uid, [procurement.id],{'task_id':task_id}) 
+            self.write(cr, uid, [procurement.id],{'task_id':task_id})
         return task_id
-
+    
 procurement_order()
 
+class sale_order(osv.osv):
+    _inherit ='sale.order'
+       
+    def _picked_rate(self, cr, uid, ids, name, arg, context=None):
+        temp = {}
+        if not ids:
+            return {}
+        res = super(sale_order, self)._picked_rate(cr, uid, ids, name, arg, context=context)
+        cr.execute('''select so.id as sale_id, t.planned_hours, t.state as task_state ,
+                    t.id as task_id, ptw.hours as task_hours
+                    from project_task as t
+                    left join sale_order as so on so.id = t.sale_id  
+                    left join project_task_work as ptw on t.id = ptw.task_id
+                    where so.id in %s ''',(tuple(ids),))
+        r1 = cr.dictfetchall()
+        if not r1:
+            return res
+        test = {}
+        for id in ids:
+            test[id] = {}
+            test[id]['number_of_done'] = 0
+            test[id]['number_of_others'] = 0
+            test[id]['total_no_task'] = 0
+            test[id]['percentage'] = 0.0
+            test[id]['number_of_stockable'] = 0.0
+            test[id]['number_of_planned'] = 0.0
+            test[id]['time_spent'] = 0.0            
+
+        for item in r1:
+            flag = False
+            flag2 = False
+            if not item['task_hours'] and item['task_state'] == 'done': # If Task hours not given and task completed
+                flag = True
+                
+            if item['task_hours'] and item['task_state'] == 'done': #If Task hours but Task in Done state as well as task work != planned hours
+                flag2 = True
+
+            if item['task_hours']: # If task work in the task
+                test[item['sale_id']]['time_spent'] += item['task_hours']
+            
+            if item['task_state'] == 'done': # If State is in done state
+                test[item['sale_id']]['number_of_done'] += 1
+            else: # Else Part
+                 test[item['sale_id']]['number_of_others'] += 1
+            
+            # dict calculated here
+            test[item['sale_id']]['number_of_planned'] += item['planned_hours']
+            test[item['sale_id']]['total_no_task'] += 1
+            test[item['sale_id']]['percentage'] = float(test[item['sale_id']]['time_spent']) / test[item['sale_id']]['number_of_planned'] * 100
+            
+            
+            if flag: # Flag If Task is done without Task hours
+                test[item['sale_id']]['percentage'] = (float(test[item['sale_id']]['number_of_done']) / test[item['sale_id']]['number_of_planned']) * 100
+            
+            if flag2: # Flag 2 Task with work and state is in done state as well as task work != planned hours 
+               test[item['sale_id']]['percentage'] = (float(test[item['sale_id']]['number_of_done']) / test[item['sale_id']]['number_of_planned']) * 100
+
+    
+        for sale in self.browse(cr,uid,ids,context=None):
+            # Non service type products are calculated here 
+            test[item['sale_id']]['number_of_stockable'] = len(sale.order_line) - test[item['sale_id']]['total_no_task']
+           
+            # condition for the percent calculation
+            if test[item['sale_id']]['percentage'] == 100 and res[sale.id] == 100:
+                continue
+            elif test[item['sale_id']]['number_of_stockable'] == 0:
+                res[sale.id] = (test[sale.id]['percentage'])
+            else:    
+                res[sale.id] = (res[sale.id] + test[sale.id]['percentage']) / (test[item['sale_id']]['number_of_stockable'] + test[item['sale_id']]['total_no_task'])
+        return res
+     
+    _columns = {
+                    'picked_rate': fields.function(_picked_rate, method=True, string='Picked', type='float'),
+               }
+  
+sale_order()
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'sale/sale.py'
--- sale/sale.py	2011-02-22 09:27:33 +0000
+++ sale/sale.py	2011-04-14 11:52:28 +0000
@@ -109,7 +109,7 @@
         for item in cr.dictfetchall():
             if item['move_state'] == 'cancel':
                 continue
-           
+        
             if item['picking_type'] == 'in':#this is a returned picking
                 tmp[item['sale_order_id']]['total'] -= item['nbr'] or 0.0 # Deducting the return picking qty
                 if item['procurement_state'] == 'done' or item['move_state'] == 'done':
@@ -118,13 +118,13 @@
                 tmp[item['sale_order_id']]['total'] += item['nbr'] or 0.0
                 if item['procurement_state'] == 'done' or item['move_state'] == 'done':
                     tmp[item['sale_order_id']]['picked'] += item['nbr'] or 0.0
-                
+
         for order in self.browse(cr, uid, ids, context=context):
             if order.shipped:
                 res[order.id] = 100.0
             else:
                 res[order.id] = tmp[order.id]['total'] and (100.0 * tmp[order.id]['picked'] / tmp[order.id]['total']) or 0.0
-        return res
+        return res        
 
     def _invoiced_rate(self, cursor, user, ids, name, arg, context=None):
         res = {}
@@ -728,6 +728,7 @@
                         'move_id': move_id,
                         'property_ids': [(6, 0, [x.id for x in line.property_ids])],
                         'company_id': order.company_id.id,
+                        'sale_line_id': line.id,
                     })
                     proc_ids.append(proc_id)
                     self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id})


Follow ups