I need an automated action python code that does the following:
Establish a relation between the sale.order.line model and the project.task model. I added a new field in the sale.order.line with technical name : x_studio_phase_name_1 and its a char field. We should write a condition that if the name of the task is similar to the name I recorded in the sale.order.line, then we need to update the quantity field in the sale.order.line model to be equal to the value of a newly created field in the project.task model under the technical name of : x_studio_area_1
This is the code I have done but its not working:
order_lines = record.env['sale.order.line'].search([])
for order_line in order_lines:
if order_line.x_studio_phase_name_1:
tasks = record.env['project.task'].search([
('project_id.sale_order_id', '=', order_line.order_id.id),
('name', '=', order_line.x_studio_phase_name_1)
])
if len(tasks) == 1:
task = tasks[0]
if order_line.order_id.state == 'sale':
order_line.write({'product_uom_qty': task.x_studio_area_1})