odoo programmatically add purchase order (rfq)

1.2k views Asked by At

I am confused on how to add a po manually, Should I inherit the purchase.order model or can i call the create function directly without inheritance?

Also, how can I find the values required for adding a po? I would like to add a request for quotation from a function and not from the web interface.

I want to pull some data and create a po based on it. If someone could give me some guideance that would help me alot.

1

There are 1 answers

2
Kenly On BEST ANSWER

You can create a purchase order without inheritance.
At least you should specify the required values which have no default values.
The following code will create a purchase order like if you click on the create button and choose a partner then end by saving:

self.env['purchase.order'].create({'partner_id': ?, 
                                   'location_id':?, 
                                   'pricelist_id': ?
                                  })

Edit: To create a purchase order with order lines you can use the following code:

self.env['purchase.order'].create({'partner_id': ?,
                                   'location_id':?,
                                   'pricelist_id': ?,
                                   'order_line': [(0, 0, {'product_id': ?,
                                                          'name': ?,
                                                          'date_planned': ?,
                                                          'price_unit': ?}), 
                                                  (...)
                                                 ] 
                                 })

For One2many values filling refer to x2many values filling