Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4850 Lượt xem

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.



Ảnh đại diện
Huỷ bỏ

You include relevant part of the log.

Câu trả lời hay nhất

Hi friend!!!

Try to make it like this:

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

Ảnh đại diện
Huỷ bỏ

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 21
11390
0
thg 3 15
4223
1
thg 8 23
2570
1
thg 1 21
4133
3
thg 9 20
71955