'Finds BoM for particular product, picking and company'

@api.model
def _bom_find(self, product_tmpl=None, product=None, picking_type=None, company_id=False):

    if product:
        if (not product_tmpl):
            product_tmpl = product.product_tmpl_id
        domain = ['|', ('product_id', '=', product.id), '&', ('product_id', '=', False), ('product_tmpl_id', '=', product_tmpl.id)]
    elif product_tmpl:
        domain = [('product_tmpl_id', '=', product_tmpl.id)]
    else:
        return False
    if picking_type:
        domain += ['|', ('picking_type_id', '=', picking_type.id), ('picking_type_id', '=', False)]
    if (company_id or self.env.context.get('company_id')):
        domain = (domain + [('company_id', '=', (company_id or self.env.context.get('company_id')))])
    return self.search(domain, order='sequence,    product_id', limit=1)
