Skip to content
Permalink
Browse files

[IMP] sale_timesheet: hooks in project_create_sale_order

  • Loading branch information...
alexey-pelykh committed Feb 13, 2019
1 parent 7a1c8d5 commit 870a27c5be0660327b074e390c28ceffb945ae1d
Showing with 28 additions and 22 deletions.
  1. +28 −22 addons/sale_timesheet/wizard/project_create_sale_order.py
@@ -50,6 +50,33 @@ def _onchange_product_id(self):

@api.multi
def action_create_sale_order(self):
self._validate_input()

# create SO
sale_order = self.env['sale.order'].create({
'partner_id': self.partner_id.id,
'analytic_account_id': self.project_id.analytic_account_id.id,
'client_order_ref': self.project_id.name,
})
sale_order.onchange_partner_id()
sale_order.onchange_partner_shipping_id()

self._make_billable(sale_order)

# confirm SO
sale_order.action_confirm()

view_form_id = self.env.ref('sale.view_order_form').id
action = self.env.ref('sale.action_orders').read()[0]
action.update({
'views': [(view_form_id, 'form')],
'view_mode': 'form',
'name': sale_order.name,
'res_id': sale_order.id,
})
return action

def _validate_input(self):
# if project linked to SO line or at least on tasks with SO line, then we consider project as billable.
if self.project_id.sale_line_id:
raise UserError(_("The project is already linked to a sales order item."))
@@ -71,34 +98,13 @@ def action_create_sale_order(self):
if timesheet_with_so_line:
raise UserError(_('The sales order cannot be created because some timesheets of this project are already linked to another sales order.'))

# create SO
sale_order = self.env['sale.order'].create({
'partner_id': self.partner_id.id,
'analytic_account_id': self.project_id.analytic_account_id.id,
'client_order_ref': self.project_id.name,
})
sale_order.onchange_partner_id()
sale_order.onchange_partner_shipping_id()

def _make_billable(self, sale_order):
# create the sale lines, the map (optional), and assign existing timesheet to sale lines
if self.billable_type == 'project_rate':
self._make_billable_at_project_rate(sale_order)
else:
self._make_billable_at_employee_rate(sale_order)

# confirm SO
sale_order.action_confirm()

view_form_id = self.env.ref('sale.view_order_form').id
action = self.env.ref('sale.action_orders').read()[0]
action.update({
'views': [(view_form_id, 'form')],
'view_mode': 'form',
'name': sale_order.name,
'res_id': sale_order.id,
})
return action

def _make_billable_at_project_rate(self, sale_order):
# trying to simulate the SO line created a task, according to the product configuration
# To avoid, generating a task when confirming the SO

0 comments on commit 870a27c

Please sign in to comment.
You can’t perform that action at this time.