Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Add custom field in Settings->Configuration->Sales

By
mohamed aboelfadl
on 10/25/16, 10:47 AM 202 views

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

1

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 10/26/16, 3:07 AM

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 ...

1

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 10/26/16, 2:54 AM

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.


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/25/16, 10:47 AM
Seen: 202 times
Last updated: 10/26/16, 9:31 AM