Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4 Antwoorden
6080 Weergaven

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
Annuleer
Auteur Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

Vielen danke Gerhard

Beste antwoord

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
Annuleer

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

Gerelateerde posts Antwoorden Weergaven Activiteit
0
feb. 17
3120
4
jan. 16
10446
1
mrt. 17
7110
2
apr. 15
4869
0
mrt. 25
1286