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

Hi

In Odoo server actions with python code i know the command to update a record (with record.write). But I would like to know the command to create records. What is this command? See below


#Server action with python code on model sale.order,code:

taxId = None


sType = record.opportunity_id.x_studio_type


if sType == 'Renovatie':

    taxId = [87]


if sType == 'Nieuwbouw':

    taxId = [82]


if sType == 'BTW Verlegd':

    taxId = [89]


if taxId != None:

    for record in record.order_line:

        record.write({'tax_id':taxId})


Here I would like to create a sale order line in a sale order. What is the command for this. 

頭像
捨棄
最佳答案

For creating new records in Odoo using Python code, especially in server actions, you're gonna use the .create() method. This method is pretty straightforward and powerful, allowing you to spawn new records in the database with all the data you specify.

Since you're looking to create a sale order line (sale.order.line) within a sale order (sale.order), you'd typically gather all the necessary field values for a sale.order.line record, then call .create() with those values in a dictionary.
Odoo Beratung Deutschland

頭像
捨棄
最佳答案

Hi,

Try this command to create sale order line:

record.create({
            'product_id': product_id,
            'product_uom_qty': quantity, 
            'price_unit': price,
            'tax_id': [(6, 0, taxid)], 
        })


Hope it helps

頭像
捨棄