콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
3561 화면

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

아바타
취소