Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
3151 Представления

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})

 

Аватар
Отменить
Лучший ответ

try this way:
order_lines = self.env['sale.order.line'].search([])


for order_line in order_lines:

if order_line.x_studio_phase_name_1:

tasks = self.env['project.task'].search([

('project_id.sale_order_id', '=', order_line.order_id.id),

('name', '=', order_line.x_studio_phase_name_1)

])

if tasks:

task = tasks[0] # Assuming you want to consider only the first matching task

order_line.quantity = task.x_studio_area_1

we first search for all the sale.order.line records. For each order line, we check if the x_studio_phase_name_1 field has a value. If it does, we search for project.task records based on the conditions you provided, and if there's a matching task, we update the quantity field of the order line with the value of x_studio_area_1 from the task.

Аватар
Отменить
Лучший ответ

Hi 


Try this Code

order_lines = env['sale.order.line'].search([])
tasks = env['project.task'].search([])
for line in order_lines:
for task in tasks:
if line.x_studio_phase_name_1 == task.name:
line.product_uom_qty = task.x_studio_area_1


Regards

Аватар
Отменить
Related Posts Ответы Просмотры Активность
3
мая 25
2496
0
февр. 24
1570
2
окт. 23
1732
Project and Tasks Решено
1
июл. 23
1946
0
июн. 24
2339