在odoo中的product.pricelist.item中添加字段

时间:2016-06-19 10:22:12

标签: openerp odoo-8 odoo-9 odoo-view

我想添加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...

1 个答案:

答案 0 :(得分:1)

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

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

reference

尝试以下

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>

这应该有效。