Odoo Help

1

Fetch Sale Order Lines from mrp.bom lines

By
Cyrus Waithaka
on 5/13/15, 7:56 PM 1,150 views

I am trying to auto-populate the sales order lines with the records in an mrp bill of materials record. This means that a user will select a product's bill of material when creating a sales order and odoo will fill pick all the "building blocks" of the selected product.

This is what I have done so far:

class sale_order(osv.osv): 
_inherit = "sale.order" _columns = {'bom_id' :fields.many2one('mrp.bom',string='Product to Manufacture'), } def onchange_bom_id(self,cr,uid,ids,bom_id,context=None): this_order = self.browse(cr, uid, ids, context=context) o_lines = this_order.order_line #preserve what was there bom = self.pool.get('mrp.bom').browse(cr, uid, bom_id, context=context) bom_lines = bom.bom_line_ids for line in bom_lines: data = { 'product_id': line.product_id.id, 'name': line.product_id.name, #'price_unit': line.price_unit, 'product_uom_qty': line.product_qty, 'product_uom': line.product_uom.id, } o_lines.append((0, 0, data)) return {'value': {'order_line':o_lines}}

I have then added the bom_id field to the sales order view as follows

        <record id="view_order_form" model="ir.ui.view">
<field name="name">nisbau_quotation_order_form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<field name='date_order' position="after">
<field name="number_of_days" on_change="onchange_days(number_of_days, context)"/>
<field name="validity_date"/>
</field>
<field name="partner_id" position="after">
<field name="bom_id" on_change="onchange_bom_id(bom_id, context)"/>
</field>
</field>
</record>

I am however stuck with this. Any pointers will highly be appreciated.


0
Sakli
On 11/11/15, 4:12 AM

Hello

Try installing the module Mrp Bom Sale Pack.

Hope this will help you.

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 5/13/15, 7:56 PM
Seen: 1150 times
Last updated: 12/29/16, 1:26 PM