I try to add a new configuration field for sales configuration settings by inheriting the standard sales settings view/model using a custom module.
Creating the field in the model works fine and a value entered in the view is also successfully written to the database. However, if I reload the view for sales configuration, the previously stored value is back to 0.00 (while still being ok in the table!).
Struggling with this for days now, found related posts by research (odoo site and stackoverflow) which all unfortunately did not work for me.
This is the view definition XML file:
<openerp>
<data>
<!-- SALE CONFIG FORM VIEW Section -->
<record model="ir.ui.view" id="view_custom_sale_config_form_inherited">
<field name="name">sale settings</field>
<field name="model">sale.config.settings</field>
<field name="type">form</field>
<field name="inherit_id" ref="sale.view_sales_config" />
<field name="arch" type="xml">
<data>
<xpath expr="//div[@name='Sale Features']/div" position="inside">
<div name="threshold_price_mgr_sig">
<label for="threshold_price_mgr_sig"/>
<field name="threshold_price_mgr_sig" class="oe_inline"/>
</div>
</xpath>
</data>
</field>
</record>
</data>
</openerp>
This is the Python code:
from openerp.osv import osv, fields
import openerp.addons.decimal_precision as dp
# modify class sale.config.settings to insert a new field
class my_custom_sale_config_settings(osv.osv_memory):
_name = 'sale.config.settings'
_inherit = "sale.config.settings"
_columns = {
'threshold_price_mgr_sig': fields.float('Threshold Price for Managers Signature',
digits_compute=dp.get_precision('Product Price'),
default_model='sale.config.settings',
help="""Threshold price from which the managers signature is required.
This is valid for quotations and order confirmations."""),
}
_defaults = {
'threshold_price_mgr_sig': 0.00,
}
def get_default_threshold_price_mgr_sig(self, cr, uid, fields, context=None):
last_ids = self.pool.get('sale.config.settings').search(cr, uid, [], order='id desc', limit=1)
result_obj = self.pool.get('sale.config.settings').browse(cr,uid,last_ids[0])
t_p_m_s = result_obj.threshold_price_mgr_sig
return {'threshold_price_mgr_sig': t_p_m_s}
By debugging I also found, that the function get_default_threshold_price_mgr_sig
is never executed...
I know that configuration settings fields works different than normal fields - just can't figure out how.
Do you know, what I am doing wrong?