in Automation Rules we do not have Triggers like Before Create but there is On Save which work fine for creating record(s) in another table(s), but if there is no relation field for Action Create Record and also if i want to create parent-child records how it can be done?
i tried using Execute Code as below but it throws error.
Model : Approval Request
Trigger : On Save
Execute Code:
if record.request_status=='approved' and record.category_id in (8, 9, 13):
# Create stock.picking record
picking_data = {
'picking_type_id': 1,
'company_id': 1,
# Add other required fields
}
stock_picking = env['stock.picking'].create(picking_data)
for approval_line in record.approval_product_line:
# Create stock.move record
move_data = {
'picking_id': stock_picking.id,
'product_id': approval_line.product_id.id,
'product_uom_qty': approval_line.quantity,
'company_id': 1,
'product_uom': 1,
# Add other required fields
}
stock_move = env['stock.move'].create(move_data)
error for stock.move:
ValueError: : "'approval.request' object has no attribute 'approval_product_line'" while evaluating
this is my first attempt to create a parent-child record using python code in Automation Rule, i don't know how to about the child side records in this scenario.
can somebody please help with correction in code for stock.move where i want to create Line records which can be multiple as i am totally blank here.
regards
please note: there is an another Automation Rule exists for On Save trigger for same Model mentioned above.