В моем модуле я иметь следующее many2one поле: 'xx_insurance_type': fields.many2one('xx.insurance.type', string='Insurance')
odoo - отображаемое имя many2one поля комбинации 2-х полей
где xx.insurance.type
является следующее:
class InsuranceType(osv.Model):
_name='xx.insurance.type'
_columns = {
'name' : fields.char(size=128, string = 'Name'),
'sale_ids': fields.one2many('sale.order', 'xx_insurance_type', string = 'Sale orders'),
'insurance_percentage' : fields.float('Insurance cost in %')
}
Я знаю, что поле many2one принимает имя поле как его отображаемое имя, но я хотел бы использовать его в комбинации name
и insurance_percentage
в форме name + " - " + insurance_percentage + "%"
Я прочитал это лучше переписать метод get_name
поэтому я попытался следующее:
def get_name(self,cr, uid, ids, context=None):
if context is None:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
res = []
for record in self.browse(cr, uid, ids, context=context):
name = record.name
percentage = record.insurance_percentage
res.append(record.id, name + " - " + percentage + "%")
return res
и разместил внутри класса ÌnsuranceType`. Поскольку ничего не произошло: Должен ли я разместить его внутри основного класса, содержащего поле? Если да, есть ли другой способ сделать это, так как это, вероятно, также изменит способы отображения других многозонных полей?
название метода 'name_get' вместо' get_name' – ChesuCR