[FIX] [6.0] sale.order picked_rate is wrong
lp bug: https://launchpad.net/bugs/725028 fixed bzr revid: skh@tinyerp.com-20110414114950-cy55v185kkwsrxlw
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -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:
|
||||
|
||||
+4
-3
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user