This question has been flagged

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.


Avatar
Discard
Best Answer

Hello

Try installing the module Mrp Bom Sale Pack.

Hope this will help you.

Avatar
Discard