4

In odoo V13, we need to "update" the BoM in a manufacturing order. We use the PLM application to make changes to BoMs, and a change was made after the manufacturing order was created. We would prefer to not delete and re-create the manufacturing order.

I came across this post but there are no instructions for Odoo V13. I tried to figure it out by trial and error but I don't know odoo enough to be certain the result is correct.

This is the code for V14 with functions unavailable in V13 identified:

for record in records:
  record._compute_allowed_product_ids() <- Not in V13
  record._onchange_bom_id()
  record._onchange_move_raw()
  record._onchange_move_finished() <- Not in V13
  record._onchange_location

I planned on adapting it to work with a wizard to allow selecting a specific BoM version.

How can I create a server action to "update/change" the BoM of a manufacturing order?

Matthew Goulart
  • 2,873
  • 4
  • 28
  • 63

1 Answers1

0

I haven't tested it fully but played around with it on an odoo 13 runbot instance.

# only change draft manufacturing orders
for record in records.filtered(lambda r: r.state == 'draft'):
    # trigger changing to the same product
    record.onchange_product_id()
    # trigger bom change from product onchange
    record._onchange_bom_id()
    # trigger raw materials moves change after bom change
    record._onchange_move_raw()
    # trigger some other changes which usually are done anyways
    record.onchange_picking_type()
    record._onchange_date_planned_start()
    record._onchange_location()
    # finally set procurement group again, which is usually done in create()
    record.move_raw_ids.write({
        'group_id': record.procurement_group_id.id,
        'reference': record.name,
    })

It will be much more difficult to change BoMs on confirmed manufacturing orders, so this solution only works for draft orders.

CZoellner
  • 13,553
  • 3
  • 25
  • 38