Use Automated Actions to create a BOM

This is a great example of the power of Automated Actions to do something useful.

Credit to Jake Robinson for this tip, which automatically creates a BOM for new items:

if record.categ_id.id == 6:
      env['mrp.bom'].browse(1).copy({'product_tmpl_id': record.id})  

Notes:

  1. The “apply on” means that it will not create a BOM for service items.
  2. Selection by product category is done in the Python code.
    • You need to know the record IDs of the product category and the BOM you will be copying (in this case the product category id is 6 and the BOM we are copying is record 1).
  3. You could easily have different BOM templates for different product categories:
if record.categ_id.id == 6:
     env['mrp.bom'].browse(1).copy({'product_tmpl_id': record.id}) 
if record.categ_id.id == 7:
     env['mrp.bom'].browse(2).copy({'product_tmpl_id': record.id})   

2 thoughts on “Use Automated Actions to create a BOM

    1. You need to create the BOM first and check its record ID.

      The first BOM you create should have a record id of 1, and that is what is used in the first example. The second example assumes you have created two BOMs with record ids of 1 and 2.

      Instead of using browse(1) you can select the BOM you want to copy in other ways.

      Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s