콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
4548 화면


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

아바타
취소
관련 게시물 답글 화면 활동
3
2월 24
11922
1
7월 16
3903
1
8월 19
9202
2
10월 17
9712
0
3월 25
1579