Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
4 Відповіді
6115 Переглядів

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
3166
4
січ. 16
10503
1
бер. 17
7160
2
квіт. 15
4927
0
бер. 25
1336