openERP变量赋值错误
Variable value passing eeror in openERP
我有一个名为 hr_bank_account
(osv.osv
) 的模型,它看起来像这样:
class hr_bank_account(osv.osv):
def create(self, cr, uid, values, context=None):
vals = {}
acc_no = 'account_no'
bank = self.pool.get('hr.bank.register').browse(cr, uid, values['bank_id']).name
branch = self.pool.get('hr.branch.registration').browse(cr, uid, values['branch_id']).name
# name = str(bank) + '/' + str(branch) + '/' + str(values['account_no'])
# get 'account_no' and replace it with acc_no bellow.
name = str(bank) + '/' + str(branch) + '/' + acc_no
values.update({'name': name})
return super(hr_bank_account, self).create(cr, uid, values, context=context)
_name = "hr.bank.account"
_description = "hr_bank_account"
_columns = {
'name': fields.char('Account No', size=256),
'bank_id': fields.many2one('hr.bank.register', 'Bank Name',),
'branch_id': fields.many2one('hr.branch.registration','Branch Name',domain="[('bank_id','=',bank_id)]"),
'account_no': fields.integer('account_no', size=64, required=True),
}
hr_bank_account()
我有一个名为 hr_employee
的 table,它具有以下关系:
'bank_account_id': fields.one2many('hr.bank.account', 'account_no', 'Bank account'),
我的问题是,当它被赋予银行帐号时,它会传递错误的值,如下所示:
我给的银行账号=123456
进入数据库的号码是=account_no
请帮我解决这个问题。
用 ->
替换 create 方法
def create(self, cr, uid, values, context=None):
vals = {}
for item in self.browse(cr, uid, ids, context=context):
acc_no = str(item.name)
bank = self.pool.get('hr.bank.register').browse(cr, uid, values['bank_id']).name
branch = self.pool.get('hr.branch.registration').browse(cr, uid, values['branch_id']).name
# name = str(bank) + '/' + str(branch) + '/' + str(values['account_no'])
# get 'account_no' and replace it with acc_no bellow.
name = str(bank) + '/' + str(branch) + '/' + acc_no
values.update({'name': name})
return super(hr_bank_account, self).create(cr, uid, values, context=context)
希望对您有所帮助。
替换您的创建方法:
def create(self, cr, uid, values, context=None):
# Check all values are in values or not
if values.get('account_no','') and values.get('bank_id','') and values.get('branch_id',''):
acc_no = values.get('account_no','')
bank = self.pool.get('hr.bank.register').browse(cr, uid, values.get('bank_id','')).name
branch = self.pool.get('hr.branch.registration').browse(cr, uid, values.get('branch_id','')).name
# Concate all fields
name = str(bank) + '/' + str(branch) + '/' + acc_no
values.update({'name': name})
return super(hr_bank_account, self).create(cr, uid, values, context=context)
我有一个名为 hr_bank_account
(osv.osv
) 的模型,它看起来像这样:
class hr_bank_account(osv.osv):
def create(self, cr, uid, values, context=None):
vals = {}
acc_no = 'account_no'
bank = self.pool.get('hr.bank.register').browse(cr, uid, values['bank_id']).name
branch = self.pool.get('hr.branch.registration').browse(cr, uid, values['branch_id']).name
# name = str(bank) + '/' + str(branch) + '/' + str(values['account_no'])
# get 'account_no' and replace it with acc_no bellow.
name = str(bank) + '/' + str(branch) + '/' + acc_no
values.update({'name': name})
return super(hr_bank_account, self).create(cr, uid, values, context=context)
_name = "hr.bank.account"
_description = "hr_bank_account"
_columns = {
'name': fields.char('Account No', size=256),
'bank_id': fields.many2one('hr.bank.register', 'Bank Name',),
'branch_id': fields.many2one('hr.branch.registration','Branch Name',domain="[('bank_id','=',bank_id)]"),
'account_no': fields.integer('account_no', size=64, required=True),
}
hr_bank_account()
我有一个名为 hr_employee
的 table,它具有以下关系:
'bank_account_id': fields.one2many('hr.bank.account', 'account_no', 'Bank account'),
我的问题是,当它被赋予银行帐号时,它会传递错误的值,如下所示:
我给的银行账号=123456
进入数据库的号码是=account_no
请帮我解决这个问题。
用 ->
替换 create 方法 def create(self, cr, uid, values, context=None):
vals = {}
for item in self.browse(cr, uid, ids, context=context):
acc_no = str(item.name)
bank = self.pool.get('hr.bank.register').browse(cr, uid, values['bank_id']).name
branch = self.pool.get('hr.branch.registration').browse(cr, uid, values['branch_id']).name
# name = str(bank) + '/' + str(branch) + '/' + str(values['account_no'])
# get 'account_no' and replace it with acc_no bellow.
name = str(bank) + '/' + str(branch) + '/' + acc_no
values.update({'name': name})
return super(hr_bank_account, self).create(cr, uid, values, context=context)
希望对您有所帮助。
替换您的创建方法:
def create(self, cr, uid, values, context=None):
# Check all values are in values or not
if values.get('account_no','') and values.get('bank_id','') and values.get('branch_id',''):
acc_no = values.get('account_no','')
bank = self.pool.get('hr.bank.register').browse(cr, uid, values.get('bank_id','')).name
branch = self.pool.get('hr.branch.registration').browse(cr, uid, values.get('branch_id','')).name
# Concate all fields
name = str(bank) + '/' + str(branch) + '/' + acc_no
values.update({'name': name})
return super(hr_bank_account, self).create(cr, uid, values, context=context)