I need retrieve the country name of the partner to display them in the sales quotations/orders in tree view.
I tried to use field but i received server error. The code is shown below:
'sale_country':fields.related('partner_id','country_id',type="char", readony=True),
I tried to write a function to retrieve the name. It seems that I can get the name(by printing the country_name, I can see that the data is retrieved), but the system still throw me exception/error. Please find my code below and the error message below.
Code:
def get_country(self, cr, uid, ids, name, arg, context=None):
"""
This method is to get the partner/customer's country name
"""
order = self.browse(cr, uid, ids)[0]
country_name = order.partner_id.country_id.name
print country_name
return country_name
_columns={
'country_test':fields.function(get_country, type='char', string='Country'),
}
Error message:
Belgium
2013-11-29 03:49:09,278 5036 ERROR moleac_v1_2 openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 131, in wrapper
return f(self, dbname, *args, **kwargs)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 197, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 185, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\orm.py", line 3604, in read
result = self._read_flat(cr, user, select, fields, context, load)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\orm.py", line 3724, in _read_flat
res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\fields.py", line 1137, in get
elif result.get(id):
AttributeError: 'unicode' object has no attribute 'get'
2013-11-29 03:49:09,282 5036 ERROR moleac_v1_2 openerp.netsvc: 'unicode' object has no attribute 'get'
Traceback (most recent call last):
File "C:\erpDev\workspace\openerp-7.0\openerp\netsvc.py", line 292, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "C:\erpDev\workspace\openerp-7.0\openerp\service\web_services.py", line 626, in dispatch
res = fn(db, uid, *params)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 188, in execute_kw
return self.execute(db, uid, obj, method, *args, **kw or {})
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 131, in wrapper
return f(self, dbname, *args, **kwargs)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 197, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\osv.py", line 185, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\orm.py", line 3604, in read
result = self._read_flat(cr, user, select, fields, context, load)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\orm.py", line 3724, in _read_flat
res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
File "C:\erpDev\workspace\openerp-7.0\openerp\osv\fields.py", line 1137, in get
elif result.get(id):
AttributeError: 'unicode' object has no attribute 'get'
Much appreciate your help!!!!!!!!!!!!!