跳至內容
選單
此問題已被標幟
1 回覆
3439 瀏覽次數

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


頭像
捨棄
作者

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

最佳答案

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

頭像
捨棄
作者

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

相關帖文 回覆 瀏覽次數 活動
2
8月 24
916
2
7月 24
1479
1
1月 24
1350
2
12月 23
2043
1
5月 24
1498