首页 文章

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

提问于
浏览
1

我正在尝试更改某些属性字段的默认值,例如:'product_method','product_type'和'product'模块的'valu',但我只能更改非属性字段 .

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

  • 我创建了具有相同名称但是另一种类型(选择)而不是属性的新字段,但这两者都不起作用 .

代码:

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

_columns = {

'cost_method':fields.selection([('average','Average Price'),('standard','Standard Price'),('real','Real Price')]),'type':fields . 选择([('产品','可存储产品'),('服务','消费品'),('服务','服务'),'产品类型',要求=真,帮助=“消费品是产品如果您不管理库存,则服务是由公司或个人提供的非物质产品 . “),'company_id':fields.many2one('res.company','Company',required = False)}

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

1 回答

  • 1

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

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

    您是否在 __openerp__.py 中设置了正确的依赖项 . 在你的情况"product"?

    希望对你有所帮助 . 让我知道 .

    EDIT: 我可以重现你的问题 . 我的测试代码

    # -*- 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 -field从未有 consu 值 . 在我的情况下,我可以通过打开菜单 Settings -> Technical Settings -> Actions -> User-defined Defaults 来解决问题 . 我删除了名称为 type 且modelname为 product.template 的所有条目 .

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

相关问题