Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to find BoM for particular product and product_uom in Odoo?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 899
    Comment on it

    In Odoo first, we have to create own modules and then create a function to find the BOM in our own modules.

    After this, we will search product on the basis of the product_tmpl_id and relate it to the BOM. 

    Here, product_uom is the Unit of measure of a product and this will relate to the List of related properties and return true or false of the BOM id. And finally we have to Search a BOM which has all properties specified, or if you can not find one, you have to pass a BOM without any properties with the smallest sequence.

    Use this code in .py file:

    def bom_search(self, cr, uid, product_tmpl_id=None, product_id=None, properties=None, context=None):
       
            if not context:
                context = {}
            if properties is None:
                properties = []
            if product_id:
                if not product_tmpl_id:
                    product_tmpl_id = self.pool['product.product'].browse(cr, uid, product_id, context=context).product_tmpl_id.id
                domain = [
                    '|',
                        ('product_id', '=', product_id),
                        '&',
                            ('product_id', '=', False),
                            ('product_tmpl_id', '=', product_tmpl_id)
                ]
            elif product_tmpl_id:
                domain = [('product_id', '=', False), ('product_tmpl_id', '=', product_tmpl_id)]
            else:
                # neither product nor template, makes no sense to search
                return False
            if context.get('company_id'):
                domain = domain + [('company_id', '=', context['company_id'])]
            domain = domain + [ '|', ('date_start', '=', False), ('date_start', '<=', time.strftime(DEFAULT_SERVER_DATE_FORMAT)),
                                '|', ('date_stop', '=', False), ('date_stop', '>=', time.strftime(DEFAULT_SERVER_DATE_FORMAT))]
            # order to prioritize bom with product_id over the one without
            ids = self.search(cr, uid, domain, order='sequence, product_id', context=context)
            # Search a BoM which has all properties specified, or if you can not find one, you could
            # pass a BoM without any properties with the smallest sequence
            bom_empty_prop = False
            for bom in self.pool.get('mrp.bom').browse(cr, uid, ids, context=context):
                if not set(map(int, bom.property_ids or [])) - set(properties or []):
                    if not properties or bom.property_ids:
                        return bom.id
                    elif not bom_empty_prop:
                        bom_empty_prop = bom.id
            return bom_empty_prop
    
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: