1
votes

I'm trying to change the default value of some property fields such as: 'cost_method', 'product_type' and 'valuation' of the 'product' module but I can only change the non-property fields only.

What I tried: - I created a new module and inherited the 'product.template' model and overridden the '_default' dictionary only but it didn't work.

  • I created new fields with the same name but of another type (selection) not property but neither did this work.

The code:

 _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' : 'product'
    , 'cost_method': 'average'
    , 'barcode':'555'
}
1

1 Answers

1
votes

Use only _inherit="product.template". In your case you don't need the _name property.

Did you add your py. File to your __init__.py?

Did you set the correct dependencies in your __openerp__.py. In your case "product"?

Hope that helps you. Let me know.

EDIT: I could reproduce your problem. My Code for testing

# -*- 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'
    }

Here the type-field never had the consu value. In my case I could solve the problem by opening the menu Settings -> Technical Settings -> Actions -> User-defined Defaults. I deleted all entries where the name is type and modelname is product.template.

Now if I create a new product the default type is consu. Same behaviour with cost_method-field.