Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
6104 Lượt xem

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 ?

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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 ?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

Vielen danke Gerhard

Câu trả lời hay nhất

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)

Ảnh đại diện
Huỷ bỏ

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 2 17
3150
4
thg 1 16
10480
1
thg 3 17
7136
2
thg 4 15
4893
0
thg 3 25
1292