0

我想添加selection field如下:

class product_pricelist_item1(models.Model):
    _inherit = 'product.pricelist.item'

    x_type = fields.Selection(selection=[('sample', 'Sample'),('moq', 'MOQ'),('others', 'Others')],string="Choices")

product.pricelist.item形式上。我正在编写如下 XML 代码:

        <record id="product_pricelist_item_form_view_with_code" model="ir.ui.view">
            <field name="name">product.pricelist.item.form</field>
            <field name="model">product.pricelist.item</field>
            <field name="inherit_id" ref="product.product_pricelist_item_form_view" />
            <field name="arch" type="xml">
                <field name="min_quantity" position="after">
                    <field name="x_type"/>
                </field>
            </field>
        </record>

但是当我打开价格表时,它给了我一个这样的错误:

Odoo Server Error Traceback (most recent call last): File "C:\Odoo 9.0-20151122\server\.\openerp\http.py" 599, line in _handle_exception File "C:\Odoo 9.0-20151122\server\.\openerp\http.py", line 636, in dispatch File "C:\Odoo 9.0-20151122\server\.\openerp\http.py", line 315, in _call_function File "C:\Odoo 9.0-20151122\server\.\openerp\service\model.py", line 118, in wrapper File "C:\Odoo 9.0-20151122\server\.\openerp\http.py", line 308, in checked_call File "C:\Odoo 9.0-20151122\server\.\openerp\http.py", line 887, in __call__ File "C:\Odoo 9.0-20151122\server\.\openerp\http.py", line 465, in response_wrap File "C:\Odoo 9.0-20151122\server\openerp\addons\web\controllers\main.py", line 971, in call_kw File "C:\Odoo 9.0-20151122\server\openerp\addons\web\controllers\main.py", line 963, in _call_kw File "C:\Odoo 9.0-20151122\server\.\openerp\api.py", line 232, in wrapper File "C:\Odoo 9.0-20151122\server\.\openerp\models.py", line 3173, in read File "C:\Odoo 9.0-20151122\server\.\openerp\api.py", line 230, in wrapper File "C:\Odoo 9.0-20151122\server\.\openerp\models.py", line 3219, in read File "C:\Odoo 9.0-20151122\server\.\openerp\models.py", line 5684, in __getitem__ File "C:\Odoo 9.0-20151122\server\.\openerp\fields.py", line 807, in __get__ File "C:\Odoo 9.0-20151122\server\.\openerp\fields.py", line 914, in determine_value File "C:\Odoo 9.0-20151122\server\.\openerp\fields.py", line 869, in compute_value File "C:\Odoo 9.0-20151122\server\.\openerp\fields.py", line 859, in _compute_value File "C:\Odoo 9.0-20151122\server\.\openerp\api.py", line 230, in wrapper File "C:\Odoo 9.0-20151122\server\.\openerp\api.py", line 398, in new_api File "C:\Odoo 9.0-20151122\server\openerp\addons\product\pricelist.py", line 331, in _get_pricelist_item_name_price File "C:\Odoo 9.0-20151122\server\.\openerp\fields.py", line 807, in __get__ File "C:\Odoo 9.0-20151122\server\.\openerp\fields.py", line 905, in determine_value File "C:\Odoo 9.0-20151122\server\.\openerp\api.py", line 230, in wrapper File "C:\Odoo 9.0-20151122\server\.\openerp\models.py", line 3278, in _prefetch_field File "C:\Odoo 9.0-20151122\server\.\openerp\api.py", line 230, in wrapper File "C:\Odoo 9.0-20151122\server\.\openerp\models.py", line 3208, in read File "C:\Odoo 9.0-20151122\server\.\openerp\api.py", line 230, in wrapper File "C:\Odoo 9.0-20151122\server\.\openerp\models.py", line 3346, in _read_from_database File "C:\Odoo 9.0-20151122\server\.\openerp\sql_db.py", line 139, in wrapper File "C:\Odoo 9.0-20151122\server\.\openerp\sql_db.py", line 215, in execute ProgrammingError: column product_pricelist_item.x_type does not exist LINE 1: ...duct_pricelist_item"."create_uid" as "create_uid","product_p...

4

1 回答 1

1

扩展模型时,如果要向选择字段添加可能的值,可以使用 selection_add 关键字参数:

class SomeModel(models.Model):
    _inherits = 'some.model'
    type = fields.Selection(selection_add=[('b', 'B'), ('c', 'C')])

参考

尝试以下

class product_pricelist_item(models.Model):
    _inherit='product.pricelist.item'

    x_type= fields.Selection(selection_add=[('b', 'B')])

对于 xml

  <record id='product_product_pricelist_item_form_view' model='ir.ui.view'>
    <field name="model">product.pricelist.item</field>
    <field name="inherit_id" ref="product.product_pricelist_item_form_view"/>
    <field name="arch" type="xml">
      <form position="after">
        <field name="x_type" widget="radio"/>
      </form>
    </field>
  </record>

这应该有效。

于 2016-07-28T19:00:26.943 回答