Skip to Content
Menu
This question has been flagged

from Approval Request when a Purchase related request like: Create RFQ's is approved i want to create record(s) in Internal Transfer (stock.picking -parent- and stock.move -child-) with all approval product line records using Automation Rules. i don't know how to create records using python code and if there is something to override Create method here for stock.picking and stock.move?

please help.

Note: see my working in below comment.

regards


Avatar
Discard
Author

i have tried below code to achieve:

Python Code Block in Automation Rule Action

if record.request_status=='new':
#raise UserError(record.create_date)

# if not record.create_date:
sequncecode = 'appr.sequence.'+record.x_abbreviation
# print(sequncecode)
seq = env['ir.sequence'].next_by_code(sequncecode)
# name_length = len(seq)
record.write({'name': seq})

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

above code is for:

1) in Approval Request have separate sequences by departments which working fine

2) create record in stock.picking, it creates records in stock.picking but creates 2 records instead of 1

when adding code below for stock.move after stock.picking code it is throwing error as below.

for approval_line in record.approval_product_line: # Assuming there's a related field linking approval request to lines
# 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: <class 'AttributeError'>: "'approval.request' object has no attribute 'approval_product_line'" while evaluating

please help.

regards

Best Answer

Hi Smith,

If you are using the Enterprise edition of Odoo, you can utilize the Studio module to set up automated actions for creating records in the stock.picking or stock.move models when a purchase order (PO) is created. For guidance on setting up automated action workflows, you can refer to the following documentation:

Automated Actions - Odoo Documentation


Hope it helps

Avatar
Discard
Author

thank you to consider for help. it has already been resolved before at least 20 days ago.

Related Posts Replies Views Activity
2
Aug 24
562
2
Jul 24
984
1
Jan 24
863
2
Dec 23
1541
1
May 24
945