This question has been flagged
4 Replies
4943 Views

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 ?

Avatar
Discard
Author Best Answer

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 ?

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

Vielen danke Gerhard

Best Answer

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)

Avatar
Discard

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