Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
6137 มุมมอง

Because I'm trying to create something more than just new fields ... could you help me with this ?

How  or what should I do to create SaleOrder from custom module, how can I call 'create' function from sale.py?

Or should I create a completely new function to achieve it ?

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

I managed to create new orders, pass all data into but  either I missed something or this method is useless because, once I create order and trying to create invoice it open a new view but without any data, no customer name, no product, nothing.

How's that ? why it won't get data from order ?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

self.env['sale.order'].create({
     'field': variable,
     'field2': variable2
     ...
})

With self.env you choose the foreign model you want to create. From there you can call a lot of usefull methods, create is one of them.

Further Information: https://www.odoo.com/documentation/8.0/reference/orm.html

อวตาร
ละทิ้ง
ผู้เขียน

Vielen danke Gerhard

คำตอบที่ดีที่สุด

This is a code I'm using in one of my modules. Use it as example by changing the values of the vals dict with your own values

vals = {

'name': self.name,

'date_order': self.appointment_date,

'partner_id': self.patient.partner_id.id,

'user_id': self.doctor.partner_id.user_id.id,

'order_line': [[0, 0, {

'name': self.consultations.name,

'price_unit': self.consultations.list_price,

'product_id': self.consultations.id,

}]],

}

if pricelist_id:

vals['pricelist_id'] = pricelist_id.id

vals['currency_id'] = pricelist_id.currency_id.id

self.sale_id = self.env['sale.order'].create(vals)

อวตาร
ละทิ้ง

Hi @Axel, how to write if we have multiple order_line?
I try to add new dictionary inside the list, but doesn't work,

may you help me how to do that?

Thanks,
Tri Nanda

Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.พ. 17
3208
4
ม.ค. 16
10548
1
มี.ค. 17
7189
2
เม.ย. 15
4976
0
มี.ค. 25
1419