From aa64cc273781ff94db664cf61d243a7f1b11c295 Mon Sep 17 00:00:00 2001 From: skh Date: Thu, 14 Apr 2011 17:19:50 +0530 Subject: [PATCH 1/8] [FIX] [6.0] sale.order picked_rate is wrong lp bug: https://launchpad.net/bugs/725028 fixed bzr revid: skh@tinyerp.com-20110414114950-cy55v185kkwsrxlw --- addons/project/project.py | 2 + addons/project_mrp/project_mrp.py | 7 +- addons/project_mrp/project_mrp_view.xml | 2 + addons/project_mrp/project_procurement.py | 84 ++++++++++++++++++++++- addons/sale/sale.py | 7 +- 5 files changed, 94 insertions(+), 8 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index 137ef3f8a3f..6fa1e8f21f8 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -328,6 +328,7 @@ class task(osv.osv): # 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()) @@ -339,6 +340,7 @@ class task(osv.osv): 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 diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index b027e9eb60f..c7f6c7368c1 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -26,7 +26,8 @@ class project_task(osv.osv): _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 @@ class project_task(osv.osv): 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 @@ class product_product(osv.osv): product_product() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/project_mrp/project_mrp_view.xml b/addons/project_mrp/project_mrp_view.xml index c8ed6fbc447..a50ccf9d832 100644 --- a/addons/project_mrp/project_mrp_view.xml +++ b/addons/project_mrp/project_mrp_view.xml @@ -24,6 +24,8 @@ + + diff --git a/addons/project_mrp/project_procurement.py b/addons/project_mrp/project_procurement.py index 0a7fa12ce6f..2e0fea81d71 100644 --- a/addons/project_mrp/project_procurement.py +++ b/addons/project_mrp/project_procurement.py @@ -27,7 +27,8 @@ class procurement_order(osv.osv): _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 @@ class procurement_order(osv.osv): '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: diff --git a/addons/sale/sale.py b/addons/sale/sale.py index f80d610eb03..452cb6b01a1 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -109,7 +109,7 @@ class sale_order(osv.osv): 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 @@ class sale_order(osv.osv): 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 @@ class sale_order(osv.osv): '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}) From c415283e80b5668ab5f132a0295c5339ed4143c8 Mon Sep 17 00:00:00 2001 From: skh Date: Thu, 14 Apr 2011 17:32:45 +0530 Subject: [PATCH 2/8] [FIX] [6.0] sale.order picked_rate is wrong lp bug: https://launchpad.net/bugs/725028 fixed bzr revid: skh@tinyerp.com-20110414120245-dj62d5fy3tk4ss8y --- addons/project/project.py | 2 -- addons/project_mrp/project_mrp.py | 3 --- 2 files changed, 5 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index 6fa1e8f21f8..137ef3f8a3f 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -328,7 +328,6 @@ class task(osv.osv): # 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()) @@ -340,7 +339,6 @@ class task(osv.osv): 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 diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index c7f6c7368c1..6acc88f833f 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -45,7 +45,6 @@ class project_task(osv.osv): res = super(project_task, self).do_cancel(cr, uid, ids, *args, **kwargs) self._validate_subflows(cr, uid, ids) return res - project_task() @@ -56,6 +55,4 @@ class product_product(osv.osv): } product_product() - - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From a057f018c51f7889c946b3b70094912bdb3271ee Mon Sep 17 00:00:00 2001 From: skh Date: Tue, 19 Apr 2011 14:56:25 +0530 Subject: [PATCH 3/8] [FIX] [6.0] sale.order picked_rate is wrong lp bug: https://launchpad.net/bugs/725028 fixed bzr revid: skh@tinyerp.com-20110419092625-40to23ivrd0jdilk --- addons/project_mrp/project_mrp.py | 64 +++++++++++++++++++ addons/project_mrp/project_mrp_view.xml | 3 - addons/project_mrp/project_procurement.py | 78 +---------------------- 3 files changed, 65 insertions(+), 80 deletions(-) diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index 6acc88f833f..3ecd6ec9baf 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -55,4 +55,68 @@ class product_product(osv.osv): } product_product() +class sale_order(osv.osv): + _inherit ='sale.order' + + def _picked_rate(self, cr, uid, ids, name, arg, context=None): + if not ids: + return {} + temp = {} + for id in ids: + temp[id] = {} + temp[id]['number_of_done'] = 0 + temp[id]['number_of_others'] = 0 + temp[id]['percentage'] = 0.0 + temp[id]['number_of_stockable'] = 0.0 + temp[id]['number_of_planned'] = 0.0 + temp[id]['time_spent'] = 0.0 + + 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 as planned_hours, t.state as task_state , + t.id as task_id, sum(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 group by so.id,t.planned_hours,t.state,t.id ''',(tuple(ids),)) + sale_task_result = cr.dictfetchall() + cr.execute('''select so.id as sale_id, count(t.id) as total, sum(t.planned_hours) as total_hours + from project_task as t + left join sale_order as so on so.id = t.sale_id + where so.id in %s group by so.id ''',(tuple(ids),)) + task_result = cr.dictfetchall() + if not sale_task_result: + return res + for task_item in task_result: + temp[task_item['sale_id']]['total_no_task'] = 0 + + for item in sale_task_result: + temp[item['sale_id']]['number_of_planned'] = task_item['total_hours'] + temp[task_item['sale_id']]['total_no_task']= task_item['total'] + if (not item['task_hours'] and item['task_state'] == 'done') or (item['task_hours'] and item['task_state'] == 'done'): # If Task hours not given and task completed + temp[item['sale_id']]['number_of_done'] += 1 + elif item['task_hours'] and not item['task_state'] in 'done': # If task work in the task + temp[item['sale_id']]['time_spent'] += item['task_hours'] + else: # To calculate the other record + temp[item['sale_id']]['number_of_others'] += 1 + temp[item['sale_id']]['percentage'] = float(temp[item['sale_id']]['time_spent']) / temp[item['sale_id']]['number_of_planned'] * 100 + temp[item['sale_id']]['percentage'] += (float(temp[item['sale_id']]['number_of_done']) / temp[item['sale_id']]['number_of_planned']) * 100 + + for sale in self.browse(cr,uid,ids,context=None): + # Non service type products are calculated here + temp[item['sale_id']]['number_of_stockable'] = len(sale.order_line) - temp[task_item['sale_id']]['total_no_task'] + # condition for the percent calculation + if temp[item['sale_id']]['percentage'] == 100 and res[sale.id] == 100: + continue + elif temp[item['sale_id']]['number_of_stockable'] == 0: + res[sale.id] = (temp[sale.id]['percentage']) + else: + res[sale.id] = (res[sale.id] + temp[sale.id]['percentage']) / (temp[item['sale_id']]['number_of_stockable'] + temp[task_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: diff --git a/addons/project_mrp/project_mrp_view.xml b/addons/project_mrp/project_mrp_view.xml index a50ccf9d832..3177f6ea67b 100644 --- a/addons/project_mrp/project_mrp_view.xml +++ b/addons/project_mrp/project_mrp_view.xml @@ -24,9 +24,6 @@ - - - \ No newline at end of file diff --git a/addons/project_mrp/project_procurement.py b/addons/project_mrp/project_procurement.py index 2e0fea81d71..fe56efbf3d6 100644 --- a/addons/project_mrp/project_procurement.py +++ b/addons/project_mrp/project_procurement.py @@ -54,83 +54,7 @@ class procurement_order(osv.osv): },context=context) 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: From 2e7d89d4939a1835e70fc8da29d42e5c175e1da6 Mon Sep 17 00:00:00 2001 From: skh Date: Wed, 20 Apr 2011 16:20:18 +0530 Subject: [PATCH 4/8] [FIX] [6.0] sale.order picked_rate is wrong lp bug: https://launchpad.net/bugs/725028 fixed bzr revid: skh@tinyerp.com-20110420105018-r05u5mw96288bvhm --- addons/project_mrp/project_mrp.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index 3ecd6ec9baf..8082f5b6b71 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -84,6 +84,7 @@ class sale_order(osv.osv): left join sale_order as so on so.id = t.sale_id where so.id in %s group by so.id ''',(tuple(ids),)) task_result = cr.dictfetchall() + if not sale_task_result: return res for task_item in task_result: @@ -92,25 +93,30 @@ class sale_order(osv.osv): for item in sale_task_result: temp[item['sale_id']]['number_of_planned'] = task_item['total_hours'] temp[task_item['sale_id']]['total_no_task']= task_item['total'] + if (not item['task_hours'] and item['task_state'] == 'done') or (item['task_hours'] and item['task_state'] == 'done'): # If Task hours not given and task completed temp[item['sale_id']]['number_of_done'] += 1 elif item['task_hours'] and not item['task_state'] in 'done': # If task work in the task temp[item['sale_id']]['time_spent'] += item['task_hours'] - else: # To calculate the other record + else: # To calculate the not done task temp[item['sale_id']]['number_of_others'] += 1 - temp[item['sale_id']]['percentage'] = float(temp[item['sale_id']]['time_spent']) / temp[item['sale_id']]['number_of_planned'] * 100 - temp[item['sale_id']]['percentage'] += (float(temp[item['sale_id']]['number_of_done']) / temp[item['sale_id']]['number_of_planned']) * 100 - + temp[item['sale_id']]['percentage'] = round(min(float(temp[item['sale_id']]['time_spent']) / temp[item['sale_id']]['number_of_planned'] * 100,100),2) + temp[item['sale_id']]['percentage'] += temp[item['sale_id']]['total_no_task'] and (float(temp[item['sale_id']]['number_of_done']) / temp[item['sale_id']]['total_no_task']) * 100 + for sale in self.browse(cr,uid,ids,context=None): # Non service type products are calculated here temp[item['sale_id']]['number_of_stockable'] = len(sale.order_line) - temp[task_item['sale_id']]['total_no_task'] + if temp[item['sale_id']]['number_of_stockable'] < 0: + temp[item['sale_id']]['number_of_stockable'] = 0 # condition for the percent calculation if temp[item['sale_id']]['percentage'] == 100 and res[sale.id] == 100: continue elif temp[item['sale_id']]['number_of_stockable'] == 0: res[sale.id] = (temp[sale.id]['percentage']) else: - res[sale.id] = (res[sale.id] + temp[sale.id]['percentage']) / (temp[item['sale_id']]['number_of_stockable'] + temp[task_item['sale_id']]['total_no_task']) + res[sale.id] = round((res[sale.id] + temp[sale.id]['percentage']) / (temp[item['sale_id']]['number_of_stockable'] + temp[task_item['sale_id']]['total_no_task']),2) + if res[sale.id] > 100: + res[sale.id] = 100 return res _columns = { From a6ba3557e791c9d49b3782cdfdbf098f56701ee2 Mon Sep 17 00:00:00 2001 From: skh Date: Wed, 27 Apr 2011 15:36:34 +0530 Subject: [PATCH 5/8] [FIX] [6.0] sale.order picked_rate is wrong lp bug: https://launchpad.net/bugs/725028 fixed bzr revid: skh@tinyerp.com-20110427100634-lugr5d311idx5a1w --- addons/project_mrp/project_mrp.py | 76 ++++++++++++------------------- 1 file changed, 28 insertions(+), 48 deletions(-) diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index 8082f5b6b71..a7ba1497c2f 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -57,72 +57,52 @@ product_product() class sale_order(osv.osv): _inherit ='sale.order' - + def _picked_rate(self, cr, uid, ids, name, arg, context=None): if not ids: return {} temp = {} + res = super(sale_order, self)._picked_rate(cr, uid, ids, name, arg, context=context) for id in ids: temp[id] = {} temp[id]['number_of_done'] = 0 - temp[id]['number_of_others'] = 0 temp[id]['percentage'] = 0.0 temp[id]['number_of_stockable'] = 0.0 - temp[id]['number_of_planned'] = 0.0 - temp[id]['time_spent'] = 0.0 - - 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 as planned_hours, t.state as task_state , - t.id as task_id, sum(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 group by so.id,t.planned_hours,t.state,t.id ''',(tuple(ids),)) - sale_task_result = cr.dictfetchall() - cr.execute('''select so.id as sale_id, count(t.id) as total, sum(t.planned_hours) as total_hours - from project_task as t - left join sale_order as so on so.id = t.sale_id - where so.id in %s group by so.id ''',(tuple(ids),)) - task_result = cr.dictfetchall() - - if not sale_task_result: - return res - for task_item in task_result: - temp[task_item['sale_id']]['total_no_task'] = 0 - - for item in sale_task_result: - temp[item['sale_id']]['number_of_planned'] = task_item['total_hours'] - temp[task_item['sale_id']]['total_no_task']= task_item['total'] + temp[id]['total_no_task'] = 0 + temp[id]['total'] = 0 - if (not item['task_hours'] and item['task_state'] == 'done') or (item['task_hours'] and item['task_state'] == 'done'): # If Task hours not given and task completed + cr.execute('''select so.id as sale_id, t.state as task_state , + t.id as task_id, count(t.id) as total + from project_task as t + left join sale_order as so on so.id = t.sale_id + where so.id in %s group by so.id,t.state,t.id ''',(tuple(ids),)) + sale_task_data = cr.dictfetchall() + + if not sale_task_data: + return res + for item in sale_task_data: + temp[item['sale_id']]['total_no_task'] += item['total'] + if item['task_state'] == 'done': temp[item['sale_id']]['number_of_done'] += 1 - elif item['task_hours'] and not item['task_state'] in 'done': # If task work in the task - temp[item['sale_id']]['time_spent'] += item['task_hours'] - else: # To calculate the not done task - temp[item['sale_id']]['number_of_others'] += 1 - temp[item['sale_id']]['percentage'] = round(min(float(temp[item['sale_id']]['time_spent']) / temp[item['sale_id']]['number_of_planned'] * 100,100),2) - temp[item['sale_id']]['percentage'] += temp[item['sale_id']]['total_no_task'] and (float(temp[item['sale_id']]['number_of_done']) / temp[item['sale_id']]['total_no_task']) * 100 - - for sale in self.browse(cr,uid,ids,context=None): - # Non service type products are calculated here - temp[item['sale_id']]['number_of_stockable'] = len(sale.order_line) - temp[task_item['sale_id']]['total_no_task'] - if temp[item['sale_id']]['number_of_stockable'] < 0: - temp[item['sale_id']]['number_of_stockable'] = 0 - # condition for the percent calculation - if temp[item['sale_id']]['percentage'] == 100 and res[sale.id] == 100: + else: + pass + for sale in self.browse(cr, uid, ids, context=None): + # Percent of service + other' Type product + temp[sale.id]['percentage'] = temp[sale.id]['total_no_task'] and (float(temp[sale.id]['number_of_done']) / temp[sale.id]['total_no_task']) * 100 + temp[sale.id]['number_of_stockable'] = len(sale.order_line) - temp[sale.id]['total_no_task'] + if temp[sale.id]['percentage'] == 100 and res[sale.id] == 100: continue - elif temp[item['sale_id']]['number_of_stockable'] == 0: + elif temp[sale.id]['number_of_stockable'] == 0: res[sale.id] = (temp[sale.id]['percentage']) - else: - res[sale.id] = round((res[sale.id] + temp[sale.id]['percentage']) / (temp[item['sale_id']]['number_of_stockable'] + temp[task_item['sale_id']]['total_no_task']),2) + else: + res[sale.id] = round((res[sale.id] + temp[sale.id]['percentage']) / (temp[sale.id]['number_of_stockable'] + temp[sale.id]['total_no_task']), 2) if res[sale.id] > 100: res[sale.id] = 100 return res - + _columns = { 'picked_rate': fields.function(_picked_rate, method=True, string='Picked', type='float'), } - -sale_order() +sale_order() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 289a56ced13b15f6adfaeeb77662da669ebebb21 Mon Sep 17 00:00:00 2001 From: skh Date: Thu, 28 Apr 2011 13:14:26 +0530 Subject: [PATCH 6/8] [FIX] [6.0] sale.order picked_rate is wrong lp bug: https://launchpad.net/bugs/725028 fixed bzr revid: skh@tinyerp.com-20110428074426-d1q77t1zg8xlof9b --- addons/project_mrp/project_mrp.py | 39 +++++++++++++------------ addons/project_mrp/project_mrp_view.xml | 12 ++++++++ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index a7ba1497c2f..91209962646 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -61,16 +61,8 @@ class sale_order(osv.osv): def _picked_rate(self, cr, uid, ids, name, arg, context=None): if not ids: return {} - temp = {} + res_sale = {} res = super(sale_order, self)._picked_rate(cr, uid, ids, name, arg, context=context) - for id in ids: - temp[id] = {} - temp[id]['number_of_done'] = 0 - temp[id]['percentage'] = 0.0 - temp[id]['number_of_stockable'] = 0.0 - temp[id]['total_no_task'] = 0 - temp[id]['total'] = 0 - cr.execute('''select so.id as sale_id, t.state as task_state , t.id as task_id, count(t.id) as total from project_task as t @@ -80,29 +72,38 @@ class sale_order(osv.osv): if not sale_task_data: return res + + for id in ids: + res_sale[id] = {} + res_sale[id]['number_of_done'] = 0 + res_sale[id]['percentage'] = 0.0 + res_sale[id]['number_of_stockable'] = 0.0 + res_sale[id]['total_no_task'] = 0 + res_sale[id]['total'] = 0 + for item in sale_task_data: - temp[item['sale_id']]['total_no_task'] += item['total'] + res_sale[item['sale_id']]['total_no_task'] += item['total'] if item['task_state'] == 'done': - temp[item['sale_id']]['number_of_done'] += 1 + res_sale[item['sale_id']]['number_of_done'] += 1 else: pass for sale in self.browse(cr, uid, ids, context=None): # Percent of service + other' Type product - temp[sale.id]['percentage'] = temp[sale.id]['total_no_task'] and (float(temp[sale.id]['number_of_done']) / temp[sale.id]['total_no_task']) * 100 - temp[sale.id]['number_of_stockable'] = len(sale.order_line) - temp[sale.id]['total_no_task'] - if temp[sale.id]['percentage'] == 100 and res[sale.id] == 100: + res_sale[sale.id]['percentage'] = res_sale[sale.id]['total_no_task'] and (float(res_sale[sale.id]['number_of_done']) / res_sale[sale.id]['total_no_task']) * 100 + res_sale[sale.id]['number_of_stockable'] = len(sale.order_line) - res_sale[sale.id]['total_no_task'] + if res_sale[sale.id]['percentage'] == 100 and res[sale.id] == 100 or res_sale[sale.id]['total_no_task'] == 0: continue - elif temp[sale.id]['number_of_stockable'] == 0: - res[sale.id] = (temp[sale.id]['percentage']) + elif res_sale[sale.id]['number_of_stockable'] == 0: + res[sale.id] = (res_sale[sale.id]['percentage']) else: - res[sale.id] = round((res[sale.id] + temp[sale.id]['percentage']) / (temp[sale.id]['number_of_stockable'] + temp[sale.id]['total_no_task']), 2) + res[sale.id] = round((res[sale.id] + res_sale[sale.id]['percentage']) / (res_sale[sale.id]['number_of_stockable'] + res_sale[sale.id]['total_no_task']), 2) if res[sale.id] > 100: res[sale.id] = 100 return res _columns = { - 'picked_rate': fields.function(_picked_rate, method=True, string='Picked', type='float'), - } + 'picked_rate': fields.function(_picked_rate, method=True, string='Picked', type='float'), + } sale_order() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/project_mrp/project_mrp_view.xml b/addons/project_mrp/project_mrp_view.xml index 3177f6ea67b..4b7760db919 100644 --- a/addons/project_mrp/project_mrp_view.xml +++ b/addons/project_mrp/project_mrp_view.xml @@ -24,6 +24,18 @@ + + + project.mrp.form.view.inherit + project.task + form + + + + + + + \ No newline at end of file From 726b1b96efefa1c6b57521ceec74eae021e0b7aa Mon Sep 17 00:00:00 2001 From: skh Date: Thu, 28 Apr 2011 14:35:32 +0530 Subject: [PATCH 7/8] [FIX] [6.0] sale.order picked_rate is wrong lp bug: https://launchpad.net/bugs/725028 fixed bzr revid: skh@tinyerp.com-20110428090532-2i8uuz1suvp31q0o --- addons/project_mrp/project_mrp_view.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/project_mrp/project_mrp_view.xml b/addons/project_mrp/project_mrp_view.xml index 4b7760db919..8ede831c66f 100644 --- a/addons/project_mrp/project_mrp_view.xml +++ b/addons/project_mrp/project_mrp_view.xml @@ -31,8 +31,8 @@ form - - + + From d809f7988163bfec7da3e60243fc479f4a75d331 Mon Sep 17 00:00:00 2001 From: "Ujjvala Collins (OpenERP)" Date: Fri, 16 Sep 2011 13:04:52 +0530 Subject: [PATCH 8/8] [IMP] project_mrp: Improved code. Fixed computation problem. bzr revid: uco@tinyerp.com-20110916073452-qg0k91uzw7jdj1sk --- addons/project_mrp/project_mrp.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index 91209962646..20471aabc06 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -74,12 +74,13 @@ class sale_order(osv.osv): return res for id in ids: - res_sale[id] = {} - res_sale[id]['number_of_done'] = 0 - res_sale[id]['percentage'] = 0.0 - res_sale[id]['number_of_stockable'] = 0.0 - res_sale[id]['total_no_task'] = 0 - res_sale[id]['total'] = 0 + res_sale[id] = { + 'number_of_done': 0, + 'percentage': 0.0, + 'number_of_stockable': 0.0, + 'total_no_task': 0, + 'total': 0 + } for item in sale_task_data: res_sale[item['sale_id']]['total_no_task'] += item['total'] @@ -87,7 +88,7 @@ class sale_order(osv.osv): res_sale[item['sale_id']]['number_of_done'] += 1 else: pass - for sale in self.browse(cr, uid, ids, context=None): + for sale in self.browse(cr, uid, ids, context=context): # Percent of service + other' Type product res_sale[sale.id]['percentage'] = res_sale[sale.id]['total_no_task'] and (float(res_sale[sale.id]['number_of_done']) / res_sale[sale.id]['total_no_task']) * 100 res_sale[sale.id]['number_of_stockable'] = len(sale.order_line) - res_sale[sale.id]['total_no_task'] @@ -96,7 +97,7 @@ class sale_order(osv.osv): elif res_sale[sale.id]['number_of_stockable'] == 0: res[sale.id] = (res_sale[sale.id]['percentage']) else: - res[sale.id] = round((res[sale.id] + res_sale[sale.id]['percentage']) / (res_sale[sale.id]['number_of_stockable'] + res_sale[sale.id]['total_no_task']), 2) + res[sale.id] = round((res[sale.id] + res_sale[sale.id]['percentage']) / (res_sale[sale.id]['total_no_task']), 2) if res[sale.id] > 100: res[sale.id] = 100 return res