Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
11699 Vizualizări

I would like to add a custom field under the sales configuration here is the pyhton code:


class auto_sales_Settings_saved(models.Model):
 _name = 'sale.config.settings.saved'
     managerrequired = fields.Boolean(default=False)
     officerrequired = fields.Boolean(default=True)

class auto_sales_Settings(models.TransientModel):
    _inherit = 'sale.config.settings'  
    _name = 'sale.config.settings'
    default_managerrequired = fields.Boolean(default_model='sale.config.settings.saved')
    default_officerrequired = fields.Boolean(default_model='sale.config.settings.saved')   
   

I created the first class to hold the values as TransientModel doesn't save values, Is this the correct way ?

and how can I access the values of these fields from other classes

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

No, you don't need to create a new model to save the values. You will save the value in the ir.values model

you can check this line in the sales config . You also need to make a function such as set_xx_defaults  to set_default in the ir.values and this function will be called automatically when the user press the Apply button ..

Hope this could helps ...

Imagine profil
Abandonează
Cel mai bun răspuns

Config object is designed slightly different way,

It uses TransientModel, just for View declaration, however the actual data will be saved in the Params object, as you must be already aware data/record in the TransientModel can be stored only for intermediate/temporary period of time.


Hence after defining the fields, do write these two method, which acts as Saving data and Retrieving Data from the Params object.

# GETS: latest data    
def get_default_values(self, cr, uid, ids, context=None):
    param_obj = self.pool.get("ir.config_parameter")
    
    res = {'XYZ_COLUMN': param_obj.get_param(cr, uid, 'XYZ_COLUMN')
         }
    return res


similarly to store the data

# POST: saves new data    
def set_values(self, cr, uid, ids, context=None):
    param_obj = self.pool.get("ir.config_parameter")
    for record in self.browse(cr, uid, ids, context=context):
        param_obj.set_param(cr, uid, field, record['XYZ_COLUMN] or '0')


Note:

1. The above referenced sample code is in traditional style, as it was defined in osv.osv_memory but works well in V8, So the fundamentals stays true, change it to suite your new API style

2. no need to create a column name prefixed with 'default_', and it's better to avoid this, since these kind of prefixes serves a different purpose when used in the relevant places.


Hope this helps you.


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
6
mai 19
15304
3
sept. 24
8214
2
apr. 24
4299
0
mar. 15
7435
1
mar. 15
6742