تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
11680 أدوات العرض

Hello everyone, I have customized a module that include a many2one field. Now, I would like to set the default value for that field with the codition is: [[u'bom_ids', u'!=', False]]. i have tried below code but it did not work probebly

width_id = field.Many2one('sale.order.line.width', default ='_get_width_default')
def _get_width_default(self, cr, uid, context=None):
     res = self.pool.get('product.template').search(cr, uid, [(u'bom_ids', u'!=', False)], context=context)
     return res and res[0] or False
default = {
'width_id' : _get_width_default,
}
Could you guy please help me to point what is the problem and how to sovle the problem and finnally get my purpose. Thank for watching
الصورة الرمزية
إهمال
أفضل إجابة

You are using the old api way to specify default values for fields. Put it like this:

_defaults = {
'width_id' : _get_width_default,
}


الصورة الرمزية
إهمال
أفضل إجابة

Hi,

In your _get_width function your querying the product.template model which doesn't match with your field's comodel 'sale.order.line.width'. Also you'r using field not fields:

 

you can try the below code:

@api.model
def _get_width_default(self):
     res = self.env['sale.order.line.width'].search([('bom_ids', '!=', [])], limit=1)
     return res and res.id or False

width_id = fields.Many2one('sale.order.line.width', default=_get_width_default)


Hope this could helps


الصورة الرمزية
إهمال
الكاتب

thanks for replying, i will try your code first and send the feedback when the result come out.

الكاتب

Hellp, Elmubarrak, i dont know why the system seem does not change any thing, the result is actually the same when i set default=1, not only for your code but also any other codes that have been customized:( do you have any Idea?

المنشورات ذات الصلة الردود أدوات العرض النشاط
4
يوليو 23
2206
1
فبراير 25
10354
4
ديسمبر 19
7164
2
يوليو 17
3688
0
مارس 15
3988