如何在函数中使用many2one字段?
这是我的代码:
def _get_unit(self, cr, uid, ids, fields,arg, context=None):
res = {}
list_data = []
for record in self.browse(cr, uid, ids,unit):
list_data.append(record[unit.id])
return super(learning_course, self)._get_unit(cr, uid, ids, context=context)
_columns = {
'unit': fields.many2one('hr.department', 'unit'),
'department': fields.function(_get_unit, string='department' , store=True ,type='many2one' ,relation='hr.department'),
}
def onchange_user(self, cr, uid, ids, user_id, context=None):
unit = False
if user_id:
unit = self.pool.get('res.users').browse(cr, uid, user_id, context=context).context_department_id.id
return {'value': {'unit' : unit }}
return {'value': {} }
但我收到此错误:
用于self.browse(cr,uid,ids,unit)中的记录: AttributeError:“ browse_record_list”对象没有属性“ id”
我该怎么办?
答案 0 :(得分:0)
private void showDialogDelete(final int idRecord) {
final AlertDialog.Builder dialogDelete=new AlertDialog.Builder(TraineeListActivity.this);
dialogDelete.setTitle("Warning!!");
dialogDelete.setMessage("Are you sure to delete?");
// final EditText idText=findViewById(R.id.idET);
dialogDelete.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
myDatabaseHelper.deleteData(idRecord);
Toast.makeText(TraineeListActivity.this,"Deleted data",Toast.LENGTH_SHORT).show();
}catch (Exception e){
Log.e("error",e.getMessage());
}
}
});
dialogDelete.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
dialogDelete.show();
}
}