Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to filter a data/field base on a many2one?

By
Anirudh Lou
on 7/24/15, 2:30 AM 650 views

Does any one can help how to solve this issue: Uncaught TypeError: undefined is not a function? Here is what i did:

I made a module that inhereit on sale, crm, and account. On class crm_lead i add some changes:

 def _get_available_product(self, cr, uid, ids, name, arg, context=None):
vals = {}
pr_id = []
for rec in self.browse(cr, uid, ids, context=context):
id = rec.id
product_list = self.pool.get('product.product').search(cr,uid,[('product_state','=','available')])
pr_id = [product.id if product.id else False for product in self.pool.get('product.product').browse(cr,uid,product_list,context=context)]
vals[id] = {'product_ids':pr_id}
return vals

def _defaults_product(self, cr, uid, ids, context=None):
product_list = self.pool.get('product.product').search(cr,uid,[('product_state','=','available')]) 
pr_id = [product.id if product.id else False for product in self.pool.get('product.product').browse(cr,uid,product_list,context=context)]
value = {"value":{'product_ids':pr_id}}
_logger.info("\n\n\t\t\tVALUE %s"%(str(value)))
return value

 _columns = {
    'product_id' : fields.many2one('product.product','Product'),
     'product_ids' : fields.function(_get_available_product, type='many2many', relation='product.product', method=True, store=False, multi='compute_available_product', string='Available Product'),
 }

 _defaults = {
          'product_ids' : _defaults_product,
}


On crm_lead_view.xml

<group>
<field name="product_ids" nolabel="1" widget="many2many" invisible="1"
</group>
<group>
    <group>
<field name="product_id" required="1" domain="[('id','in',product_ids[0][2])]"/>
....


and when i try to create a Lead, the client error pop up just like above. My aim actually is that if i create a lead, i want to filter the product_id so that the only shown are those products w/c product_state is 'available'.


Any help is much appreciated.



You include relevant part of the log.

zbik
on 7/24/15, 6:12 AM
0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 7/24/15, 6:15 AM

Hi friend!!!

Try to make it like this:

'product_id' : fields.many2one('product.product','Product',domain="[('id','in',product_ids[0][2])]"),

The problem here as i think is product_ids[0][2] is unrecognized :/

Drees Far
on 7/24/15, 6:16 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/24/15, 2:30 AM
Seen: 650 times
Last updated: 7/24/15, 6:15 AM