I want to be able to create a project from the sales order. Odoo seems to only allow this for a sales order with 'service' products, but I want to create a project for any sales order, regardless of the product.
The only way I can work out to achieve this is with an 'execute code' server action, as below.
This seems to achieve what I want, however as I am on an enterprise license I have to pay extra to use the code, so I am hoping there is a simpler solution to this. Also my python experience is quite limited and I am unsure if I have coded this in a reliable way...
Does anyone know of a better solution to this problem? any help is much appreciated.
if record.project_id:
raise UserError("This Sales Order already has a linked project.")
# Get sequence number
seq = env['ir.sequence'].next_by_code('project.seq')
# Combine with opportunity name if available
if record.opportunity_id:
opp_name = record.opportunity_id.name
else:
opp_name = ""
if opp_name:
project_name = f"{seq} | {opp_name}"
else:
project_name = seq
# Create project
project = env['project.project'].create({
'name': project_name,
'partner_id': record.partner_id.id,
'use_documents': False,
})
record.write({'project_id': project.id})