[IMP] sale_timesheet: provide hooks when billing a project

This commit restructures some code part in the "create SO
from project" wizard, in order to make this feature
extendable and adds new billable type or other checks.

Closes #31047

closes odoo/odoo#37796

Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
This commit is contained in:
Alexey Pelykh
2019-10-07 15:32:10 +00:00
committed by jem-odoo
parent 089755c1fa
commit 41ccb00400
@@ -69,7 +69,21 @@ class ProjectCreateSalesOrder(models.TransientModel):
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
# create SO according to the chosen billable type
sale_order = self._create_sale_order()
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 _create_sale_order(self):
""" Private implementation of generating the sales order """
sale_order = self.env['sale.order'].create({
'project_id': self.project_id.id,
'partner_id': self.partner_id.id,
@@ -81,24 +95,18 @@ class ProjectCreateSalesOrder(models.TransientModel):
sale_order.onchange_partner_shipping_id()
# create the sale lines, the map (optional), and assign existing timesheet to sale lines
self._make_billable(sale_order)
# confirm SO
sale_order.action_confirm()
return sale_order
def _make_billable(self, sale_order):
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