Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Purchase order: add order line programmatically

By
mohamed aboelfadl
on 11/17/16, 4:11 AM 166 views

I am trying to create a module that creates new type of product, the new type act as a bundle of products, so that when this bundle is selected in the purchase order , it is automatically removed and replaced by all the products in the bundle. instead of selecting each product manually.


right now I'm stuck in the on_change function of product id to remove the bundle and add its child products

if product.is_package:
     for child_product in product.product_ids:
         active_id = context.get('active_id', [])
         line_vals = {'product_id' : child_product.product_id,}
         order_lines = []
         order_lines = order_lines.append([0,False,line_vals])
         po_line_obj = self.pool.get('purchase.order.line')
         po_line_id = po_line_obj.write(cr,uid,active_id, {'order_line' : order_lines})

But it isn't working any clue ?

0
fasluca
On 11/17/16, 11:04 PM

Odoo have almost same functionality...if you are aware of the BOM type 'Set', it will be easy.
Suppose you have a product 'ABC' with a type 'Set' BOM contains products A ,B & C
When you make a sale order for ABC Sale order line will remain as ABC, But the delivery of ABC will be as a set of product A, B & C.

So i hope you can use the same method with slight modification for your case

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 11/17/16, 7:15 AM

In the first step, you create a line, like:

line_id = po_line_obj.create(cr, uid, line_vals, context=context)

then you can manipulate it.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/17/16, 4:11 AM
Seen: 166 times
Last updated: 11/17/16, 11:04 PM