2017-10-09 16 views
0

'_defaults'を使用して関数を呼び出そうとしていますが、機能しません。デフォルトを使用して関数を呼び出す方法

ここで 'employee_id'は 'hr.payslip'の従業員フィールドであり、 'onchange_employee_id'は機能です。

def onchange_employee_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None): 
    #my code# 

_defaults = { 
    'employee_id' : 'onchange_employee_id(date_from, date_to, employee_id, contract_id)' 
} 
+0

あなたはそれがコメントするはずのデフォルトで関数を使用して、私もコメントせずにしようとした従業員ID – dccdany

+0

を返す必要がありますが、それは動作しない場合。 – phani

+0

ファンクションコードを表示 – dccdany

答えて

0
def onchange_employee_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None): 
    empolyee_obj = self.pool.get('hr.employee') 
    contract_obj = self.pool.get('hr.contract') 
    worked_days_obj = self.pool.get('hr.payslip.worked_days') 
    input_obj = self.pool.get('hr.payslip.input') 

    if context is None: 
     context = {} 
    #delete old worked days lines 
    old_worked_days_ids = ids and worked_days_obj.search(cr, uid, [('payslip_id', '=', ids[0])], context=context) or False 
    if old_worked_days_ids: 
     worked_days_obj.unlink(cr, uid, old_worked_days_ids, context=context) 

    #delete old input lines 
    old_input_ids = ids and input_obj.search(cr, uid, [('payslip_id', '=', ids[0])], context=context) or False 
    if old_input_ids: 
     input_obj.unlink(cr, uid, old_input_ids, context=context) 


    #defaults 
    res = {'value':{ 
        'line_ids':[], 
        'input_line_ids': [], 
        'worked_days_line_ids': [], 
        #'details_by_salary_head':[], TODO put me back 
        'name':'', 
        'contract_id': False, 
        'struct_id': False, 
        } 
     } 
    if (not employee_id) or (not date_from) or (not date_to): 
     return res 
    ttyme = datetime.fromtimestamp(time.mktime(time.strptime(date_from, "%Y-%m-%d"))) 
    employee_id = empolyee_obj.browse(cr, uid, employee_id, context=context) 
    res['value'].update({ 
       'name': _('Salary Slip of %s for the month of %s') % (employee_id.name, tools.ustr(ttyme.strftime('%B-%Y'))), 
       'company_id': employee_id.company_id.id 
    }) 

    if not context.get('contract', False): 
     #fill with the first contract of the employee 
     contract_ids = self.get_contract(cr, uid, employee_id, date_from, date_to, context=context) 
    else: 
     if contract_id: 
      #set the list of contract for which the input have to be filled 
      contract_ids = [contract_id] 
     else: 
      #if we don't give the contract, then the input to fill should be for all current contracts of the employee 
      contract_ids = self.get_contract(cr, uid, employee_id, date_from, date_to, context=context) 

    if not contract_ids: 
     return res 
    contract_record = contract_obj.browse(cr, uid, contract_ids[0], context=context) 
    res['value'].update({ 
       'contract_id': contract_record and contract_record.id or False 
    }) 
    struct_record = contract_record and contract_record.struct_id or False 
    if not struct_record: 
     return res 
    res['value'].update({ 
       'struct_id': struct_record.id, 
    }) 
    #computation of the salary input 
    worked_days_line_ids = self.get_worked_day_lines(cr, uid, contract_ids, date_from, date_to, context=context) 
    input_line_ids = self.get_inputs(cr, uid, contract_ids, date_from, date_to, context=context) 
    res['value'].update({ 
       'worked_days_line_ids': worked_days_line_ids, 
       'input_line_ids': input_line_ids, 
    }) 
    return res 
関連する問題