auto fill project to sale order budget qty added
This commit is contained in:
parent
6b0f3f811b
commit
92b712450a
|
@ -15,6 +15,7 @@ class ProjectCreateSalesOrder(models.TransientModel):
|
|||
self.ensure_one()
|
||||
task_left = self.project_id.tasks.filtered(lambda task: not task.sale_line_id)
|
||||
ticket_timesheet_ids = self.env.context.get('ticket_timesheet_ids', [])
|
||||
budgeted_qty = 0
|
||||
for wizard_line in self.line_ids:
|
||||
task_ids = self.project_id.tasks.filtered(lambda task: not task.sale_line_id and task.timesheet_product_id == wizard_line.product_id)
|
||||
task_left -= task_ids
|
||||
|
@ -33,7 +34,7 @@ class ProjectCreateSalesOrder(models.TransientModel):
|
|||
'task_id': task_id,
|
||||
'product_uom_qty': wizard_line.budgeted_qty,
|
||||
})
|
||||
|
||||
budgeted_qty += wizard_line.budgeted_qty
|
||||
if ticket_timesheet_ids and not self.project_id.sale_line_id and not task_ids:
|
||||
# With pricing = "project rate" in project. When the user wants to create a sale order from a ticket in helpdesk
|
||||
# The project cannot contain any tasks. Thus, we need to give the first sale_order_line created to link
|
||||
|
@ -76,6 +77,10 @@ class ProjectCreateSalesOrder(models.TransientModel):
|
|||
'sale_line_id': sale_order_line.id, # we take the last sale_order_line created
|
||||
'partner_id': self.partner_id.id,
|
||||
})
|
||||
if self.project_id.budgeted_hours <= 0:
|
||||
self.project_id.write({
|
||||
'budgeted_hours': budgeted_qty,
|
||||
})
|
||||
|
||||
if task_left:
|
||||
task_left.sale_line_id = False
|
||||
|
@ -97,6 +102,7 @@ class ProjectCreateSalesOrder(models.TransientModel):
|
|||
|
||||
# create SO lines: create on SOL per product/price. So many employee can be linked to the same SOL
|
||||
map_product_price_sol = {} # (product_id, price) --> SOL
|
||||
budgeted_qty = 0
|
||||
for wizard_line in self.line_ids:
|
||||
map_key = (wizard_line.product_id.id, wizard_line.price_unit)
|
||||
if map_key not in map_product_price_sol:
|
||||
|
@ -106,6 +112,7 @@ class ProjectCreateSalesOrder(models.TransientModel):
|
|||
'price_unit': wizard_line.price_unit,
|
||||
'product_uom_qty': wizard_line.budgeted_qty,
|
||||
}
|
||||
budgeted_qty += wizard_line.budgeted_qty
|
||||
if wizard_line.product_id.service_tracking in ['task_in_project', 'task_global_project']:
|
||||
values['task_id'] = task_id
|
||||
if wizard_line.product_id.service_tracking in ['task_in_project', 'project_only']:
|
||||
|
@ -131,6 +138,10 @@ class ProjectCreateSalesOrder(models.TransientModel):
|
|||
'sale_line_id': sale_order.order_line[0].id,
|
||||
'partner_id': self.partner_id.id,
|
||||
})
|
||||
if self.project_id.budgeted_hours <= 0:
|
||||
self.project_id.write({
|
||||
'budgeted_hours': budgeted_qty,
|
||||
})
|
||||
non_billable_tasks.write({
|
||||
'partner_id': sale_order.partner_id.id,
|
||||
'email_from': sale_order.partner_id.email,
|
||||
|
|
Loading…
Reference in New Issue