function field , store={}...

 1     def _get_product_state(self,cr,uid,ids,fields,arg=None,context=None):
 2         res={}
 3         dic=dict( self.pool.get('product.product')._columns['state'].selection )
 4         for sol in self.browse(cr,uid,ids,):
 5             if sol.product_id.state in dic:
 6                 res[sol.id]=dic[sol.product_id.state]
 7             else:
 8                 res[sol.id]='N/A'
 9         return res
10     def _get_sol_by_product(self,cr,uid,ids,context=None):
11         sol_ids = self.pool.get('sale.order.line').search(cr,uid,[('product_id','in',ids),])
12         return sol_ids
13     _columns={
14         'product_state':fields.function(_get_product_state,arg=None, type='char', string='Product State',readonly=True, store={
15                     'product.product': (_get_sol_by_product, ['state',], 20),   
16                     'sale.order.line': (lambda self, cr, uid, ids, c={}: ids, ['product_id'], 20),                                 
17                      }), 

store={ 'model.name': (  function_return_ids,  fieds_name_list, 20 ),}

when model.name's   field(include by fields_name_list) change, the  function_return_ids will return the ids ,

those ids will re-counter the function field and store it.

~~~~~~~ 需要odoo 实施,二开,培训 等服务 QQ:190170444
原文地址:https://www.cnblogs.com/alangwansui/p/3196268.html