odoo,在下拉列表中查看 id 和 nt 名称
odoo, see id and nt the name in dropdown
我没有看到我的错误在哪里,在我的产品页面上,我看到 create/choose 一个品牌的下拉菜单,但值是:clicshopping.manufacturer,1 而不是例如 Asus
当我查看我的品牌页面时,我看到 asus 已经创建并且一切正确。
我的产品上有一部分 xml 模板。
你有想法吗?
谢谢
<record model="ir.ui.view" id="product_template_search_view">
<field name="name">product.template.search</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view"/>
<field name="arch" type="xml">
<field name="categ_id" position="after">
<field name="clicshopping_product_manufacturer_id"/>
</field>
<group string='Group by...' position="inside">
<filter string="Manufacturer" name="groupby_manufacturer" domain="[]" context="{'group_by' : 'clicshopping_product_manufacturer_id'}"/>
</group>
</field>
</record>
<record model="ir.ui.view" id="product_template_form_manufacturer">
<field name="name">product.template.product.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="clicshopping.template_product_form_view" />
<field name="arch" type="xml">
<field name="clicshopping_products_id" position="after" >
<field name="clicshopping_product_manufacturer_id" placeholder="Brand"/>
</field>
</field>
</record>
<record model="ir.actions.act_window" id="action_clicshopping_manufacturer">
<field name="name">Brand</field>
<field name="res_model">clicshopping.manufacturer</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Brand management" id="menu_clicshopping_manufacturer" action="action_clicshopping_manufacturer" parent="product.prod_config_main"/>
有我的.py的代码
from openerp.osv import orm, fields
from openerp.tools.translate import _
class clicshopping_manufacturer(orm.Model):
_name = 'clicshopping.manufacturer'
_columns = {
'clicshopping_manufacturers_id': fields.char('Brand manufacturer Id', size=5, help="Id manufacturer Brand table of ClicShopping must be unique"),
'clicshopping_manufacturers_name': fields.char('Brand Name', size=70, help='Name of brand manufacturer.'),
'clicshopping_manufacturers_url': fields.char('Brand Url', translate=True, size=70, help='Url of brand manufacturer.'),
'clicshopping_partner_id': fields.many2one('res.partner','Partner', help='Select a partner for this brand if it exists.', ondelete='restrict'),
'clicshopping_manufacturers_image': fields.binary('brand logo'),
'clicshopping_manufacturers_status': fields.boolean('Brand Manufacturer Status', default='1', help="If a manufacturer brand is not active, it will not be displayed in the catalog"),
'clicshopping_manufacturer_description': fields.text('Description', translate=True),
'clicshopping_manufacturer_seo_title': fields.char('Brand manufacturer Seo title', translate=True, size=70, help="If it empty, default in ClicSshopping will be taken"),
'clicshopping_manufacturer_seo_description': fields.char('Brand manufacturer Seo Description', translate=True, size=150, help="If it empty, default in ClicSshopping will be taken"),
'clicshopping_manufacturer_seo_keyword': fields.text('Brand manufacturer Seo Keywords', translate=True, help="If it empty, default in ClicSshopping will be taken"),
}
class product_template(orm.Model):
_inherit = 'product.template'
_columns = {
'clicshopping_product_manufacturer_id': fields.many2one('clicshopping.manufacturer','Brand', help='Select a brand for this product.')
}
您需要使用 _rec_name
attribute 声明对象名称使用哪个字段。你的情况:
class clicshopping_manufacturer(orm.Model):
_name = 'clicshopping.manufacturer'
_rec_name = 'clicshopping_manufacturers_name'
# ...
或者,您可以将 clicshopping_manufacturers_name
重命名为 name
,因为 name
是 _rec_name
的默认值。
如果我是你,我会选择第二个选项 - 老实说,我认为你所有的字段名称都太长了。我看不出为几乎所有字段名称添加前缀 "clicshopping_manufacturers" 有什么好处。这会减慢您的速度并使您的代码可读性大大降低。
我没有看到我的错误在哪里,在我的产品页面上,我看到 create/choose 一个品牌的下拉菜单,但值是:clicshopping.manufacturer,1 而不是例如 Asus
当我查看我的品牌页面时,我看到 asus 已经创建并且一切正确。
我的产品上有一部分 xml 模板。
你有想法吗?
谢谢
<record model="ir.ui.view" id="product_template_search_view">
<field name="name">product.template.search</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view"/>
<field name="arch" type="xml">
<field name="categ_id" position="after">
<field name="clicshopping_product_manufacturer_id"/>
</field>
<group string='Group by...' position="inside">
<filter string="Manufacturer" name="groupby_manufacturer" domain="[]" context="{'group_by' : 'clicshopping_product_manufacturer_id'}"/>
</group>
</field>
</record>
<record model="ir.ui.view" id="product_template_form_manufacturer">
<field name="name">product.template.product.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="clicshopping.template_product_form_view" />
<field name="arch" type="xml">
<field name="clicshopping_products_id" position="after" >
<field name="clicshopping_product_manufacturer_id" placeholder="Brand"/>
</field>
</field>
</record>
<record model="ir.actions.act_window" id="action_clicshopping_manufacturer">
<field name="name">Brand</field>
<field name="res_model">clicshopping.manufacturer</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Brand management" id="menu_clicshopping_manufacturer" action="action_clicshopping_manufacturer" parent="product.prod_config_main"/>
有我的.py的代码
from openerp.osv import orm, fields
from openerp.tools.translate import _
class clicshopping_manufacturer(orm.Model):
_name = 'clicshopping.manufacturer'
_columns = {
'clicshopping_manufacturers_id': fields.char('Brand manufacturer Id', size=5, help="Id manufacturer Brand table of ClicShopping must be unique"),
'clicshopping_manufacturers_name': fields.char('Brand Name', size=70, help='Name of brand manufacturer.'),
'clicshopping_manufacturers_url': fields.char('Brand Url', translate=True, size=70, help='Url of brand manufacturer.'),
'clicshopping_partner_id': fields.many2one('res.partner','Partner', help='Select a partner for this brand if it exists.', ondelete='restrict'),
'clicshopping_manufacturers_image': fields.binary('brand logo'),
'clicshopping_manufacturers_status': fields.boolean('Brand Manufacturer Status', default='1', help="If a manufacturer brand is not active, it will not be displayed in the catalog"),
'clicshopping_manufacturer_description': fields.text('Description', translate=True),
'clicshopping_manufacturer_seo_title': fields.char('Brand manufacturer Seo title', translate=True, size=70, help="If it empty, default in ClicSshopping will be taken"),
'clicshopping_manufacturer_seo_description': fields.char('Brand manufacturer Seo Description', translate=True, size=150, help="If it empty, default in ClicSshopping will be taken"),
'clicshopping_manufacturer_seo_keyword': fields.text('Brand manufacturer Seo Keywords', translate=True, help="If it empty, default in ClicSshopping will be taken"),
}
class product_template(orm.Model):
_inherit = 'product.template'
_columns = {
'clicshopping_product_manufacturer_id': fields.many2one('clicshopping.manufacturer','Brand', help='Select a brand for this product.')
}
您需要使用 _rec_name
attribute 声明对象名称使用哪个字段。你的情况:
class clicshopping_manufacturer(orm.Model):
_name = 'clicshopping.manufacturer'
_rec_name = 'clicshopping_manufacturers_name'
# ...
或者,您可以将 clicshopping_manufacturers_name
重命名为 name
,因为 name
是 _rec_name
的默认值。
如果我是你,我会选择第二个选项 - 老实说,我认为你所有的字段名称都太长了。我看不出为几乎所有字段名称添加前缀 "clicshopping_manufacturers" 有什么好处。这会减慢您的速度并使您的代码可读性大大降低。