如何在OpenERP(Odoo)中更改many21字段的显示值?

2024-04-26 09:54:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在Odoo(OpenERP)上创建一个新模块,但是不能正确使用字段。

http://i.stack.imgur.com/pKQpT.png

我可以从另一个类(在同一个模块中定义)中选择一个字段,但我需要更改显示的值。

在这个例子中,我有一个字符串“menu,2”,用于字段piatto。此字符串是从类ordini中获取的,其中有一个many2one字段,但我想显示名为nome的字段(如下图所示)。

http://i.stack.imgur.com/nQwRL.png

这是python文件。

class menu(osv.Model):
_name = "menu"
_description = "Menu"
_order = "tipo"
_columns = {
    'nome': fields.char('Nome', size=80, required=True),
    'tipo': fields.selection([
                ('antipasto', 'antipasto'),
                ('primo', 'primo piatto'),
                ('secondo', 'secondo piatto'),
                ('contorno', 'contorno'),
                ('dolce', 'dolce')
                ], 'Tipo di piatto'),
    'prezzo': fields.float('Prezzo', digits=(10,2), required=True),
    'ingredienti': fields.text('Lista ingredienti'),
    'immagine': fields.binary('Immagine'),
}
_sql_constraints = [('unique_name', 'unique(nome)', 'Il piatto è già presente.')]

class ordini(osv.Model):
_name = "ordini"
_description = "Ordini"
_columns = {
    'dipendente': fields.many2one('hr.employee', 'Dipendente', ondelete='set null', required=True),
    'dettagli_ids': fields.one2many('ordini.dettagli', 'n_ordine', 'Ordine'), 
}

class ordini_dettagli(osv.Model):        
_name = "ordini.dettagli"
_description = "Dettagli ordine"
_columns = {
    'n_ordine': fields.integer('Ordine', readonly=True),
    'piatto': fields.many2one('menu', 'Piatto'),
    'qta': fields.integer('Quantità'),
    'prezzo_piatto': fields.related('piatto','prezzo',type='float',string='Prezzo',readonly=True),
}
_defaults = {
     'qta': 1,
}

编辑 当我选择piatto条目时,还需要更新字段prezzo

谢谢。


Tags: columnsnametruefieldsmodeldescriptionclassmenu
1条回答
网友
1楼 · 发布于 2024-04-26 09:54:07

您需要使用^{} attribute声明哪个字段用于对象名。就你而言:

class menu(osv.Model):
    _name = "menu"
    _description = "Menu"
    _order = "tipo"
    _rec_name = 'nome'

    # ...

或者,您可以将nome重命名为name,因为name_rec_name的默认值。

相关问题 更多 >