如何在Odoo(旧API)中更改属性字段的默认值?

时间:2016-11-03 17:56:40

标签: openerp

我试图更改某些属性字段的默认值,例如:' cost_method',' product_type'和'估值'的产品'模块,但我只能更改非属性字段。

我尝试了什么: - 我创建了一个新模块并继承了' product.template'模型并覆盖了' _default'只有字典,但它没有用。

  • 我创建了具有相同名称但另一种类型(选择)而非属性的新字段,但这两者都没有。

代码:

 _name = "product.template"
 _inherit = "product.template"

_columns = {

' cost_method&#39 ;: fields.selection([('平均','平均价格'),('标准',&# 39;标准价格'),('真实','真实价格')])         ,' type&#39 ;: fields.selection([(' product',' Stockable Product'),' consu','耗材'),('服务'服务'),'产品类型',required = True,help ="耗材是产品如果您不管理库存,则服务是由公司或个人提供的非物质产品。")  ,' company_id&#39 ;: fields.many2one(' res.company','公司',必需=假)         }

 _defaults = {
    'company_id': False
    ,'type' : 'product'
    , 'cost_method': 'average'
    , 'barcode':'555'
}

1 个答案:

答案 0 :(得分:1)

仅使用_inherit="product.template"。在您的情况下,您不需要_name属性。

你添加了你的py吗?归档到__init__.py

您是否在__openerp__.py中设置了正确的依赖项。在您的情况下"产品"?

希望能帮到你。让我知道。

修改 我可以重现你的问题。我的测试代码

# -*- coding: utf-8 -*-
from openerp.osv import osv, fields

class product_template(osv.osv):
    _name = "product.template"
    _inherit = "product.template"

    _columns = {
        'cost_method': fields.selection([('average', 'Average Price'),('standard', 'Standard Price'),('real', 'Real Price')]),
        'type': fields.selection([('product', 'Stockable Product'),('consu', 'Consumable'),('service','Service')],'Product Type', required=True, help="Consumable are product where you don't manage stock, a service is a non-material product provided by a company or an individual.") ,
        'company_id': fields.many2one('res.company', 'Company', required=False)
    }

    _defaults = {
        'company_id': False,
        'type' : 'consu',
        'cost_method': 'average',
        'barcode':'555'
    }

此处type - 字段从未拥有consu值。在我的情况下,我可以通过打开菜单Settings -> Technical Settings -> Actions -> User-defined Defaults来解决问题。我删除了名称为type且型号为product.template的所有条目。

现在,如果我创建新产品,则默认类型为consu。与cost_method - 字段相同的行为。