Advertisement
mariomolinos

Automated Update Cost Real + Forecasted

Aug 30th, 2022 (edited)
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. for record in records:
  2.   today = datetime.datetime.today().date()
  3.   order = record
  4.   costTotal = 0.0
  5.   costAnalytic = 0.0
  6.   costForecasted = 0.0
  7.   forecastedOrder = 0.0
  8.  
  9.  
  10.   if record.analytic_account_id:
  11.     account = record.analytic_account_id
  12.     for line in account.line_ids:
  13.       if line.is_timesheet == True:
  14.         costAnalytic += line.amount
  15.    
  16.     forecastedProject = env['planning.slot'].sudo().search([('project_id.analytic_account_id','=',account.id)])
  17.     for f in forecastedProject:
  18.       if f.start_datetime.date() >= today: #el comienzo es después de hoy
  19.         costForecasted += f.allocated_hours * f.employee_id.timesheet_cost
  20.       elif f.start_datetime.date() < today and f.end_datetime.date() > today:
  21.         elapsed = (today - f.start_datetime.date()).days
  22.         shiftDuration = (f.end_datetime.date() - f.start_datetime.date()).days + 1
  23.         costForecasted += (1 - (elapsed / shiftDuration)) * f.allocated_hours * f.employee_id.timesheet_cost
  24.    
  25.  
  26.   costTotal = -1*costAnalytic + costForecasted
  27.        
  28.   record['x_sorder_costrealforecasted'] = costTotal
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement