Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
4213 มุมมอง


I have two models 
class Management(models.Model):
_name = 'management.project'
     line_impact_ids = fields.One2many('management.project.reference.impact', 'change_management_id')

class ManagementProductImpact(models.Model):
_name = 'management.project.reference.impact'

partner_id = fields.Many2one('res.partner', string="Client", required=True,)
project_id = fields.Many2one('project.project', string="Projet", required=True,)

change_management_id = fields.Many2one('sirail_change_management.project', string="Management",)
I defined a function to assign default values depends on line_impact_ids like this
class Management(models.Model):
_name = 'management.project'

line_impact_ids = fields.One2many('management.project.reference.impact', 'change_management_id')
@api.onchange('line_impact_ids')
def onchange_method(self):
result = self.env['management.project.reference.impact'].default_get(['partner_id', 'project_id'])
if self.line_impact_ids:
last = self.env['management.project.reference.impact'].search([])[-1]
result['partner_id'] = last.partner_id.id
result['project_id'] = last.project_id.id
does not work please can you help me and how should i use default_get in this case


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi

default_get(cr, uid, fields_list, context=None)

Returns default values for the fields in fields_list.

Parameters:

  • fields_list (list) -- list of fields to get the default values for (example ['field1', 'field2',])

  • context -- optional context dictionary - it may contains keys for specifying certain options like context_lang (language) or context_tz (timezone) to alter the results of the call. It may contain keys in the form default_XXX (where XXX is a field name), to set or override a default value for a field. A special bin_size boolean flag may also be passed in the context to request the value of all fields.binary columns to be returned as the size of the binary instead of its contents. This can also be selectively overriden by passing a field-specific flag in the form bin_size_XXX: True/False where XXX is the name of the field. Note: The bin_size_XXX form is new in OpenERP v6.0.

Returns:

dictionary of the default values (set on the object model class, through user preferences, or in the context)

Example, from stock_return_picking.py, default value of invoice_state in return picking depends on the state of previous picking (invoiced or not):

def default_get(self, cr, uid, fields, context=None):
      res = super(stock_return_picking, self).default_get(cr, uid, fields, context=context)
      record_id = context and context.get('active_id', False) or False
      pick_obj = self.pool.get('stock.picking')
      pick = pick_obj.browse(cr, uid, record_id, context=context)
      if pick:
         if 'invoice_state' in fields:
             if pick.invoice_state=='invoiced':
                 res.update({'invoice_state': '2binvoiced'})              else:                  res.update({'invoice_state': 'none'})       return res

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ก.พ. 24
11582
1
ก.ค. 16
3612
1
ส.ค. 19
8854
2
ต.ค. 17
9324
0
มี.ค. 25
1262