Odoo Help

0

Functional fields

By
Marek Jan-Alexander
on 10/9/14, 1:17 PM 2,401 views

Hi,

i would like to add some fields to account.move and get them calculated. Let´s say I would like to add two fields - tax_base, tax_amount:

_columns = {
        'tax_base': fields.function(
            _tax_balance, method=True,
            string='Tax base',
            store=True),
        'tax_amount': fields.function(
            _tax_balance, method=True,
            string="Amount Tax",
            store=True),

However, when I try to use following function to calculate these fields (this just should throw zeros, but not functioning) for all account.move objects:

def _tax_balance(self, cr, uid, ids, field_name, arg, context=None):
        res = {}

        for move in self.read(cr, uid, ids, context=context):
            res[move['id']] = {
                'tax_base': 0.0,
                'tax_amount': 0.0,
            }      
        return res

This error appears:

Server Traceback (most recent call last): File "E:\erp7\addons\web\session.py", line 90, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "E:\erp7\openerp\netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "E:\erp7\openerp\service\web_services.py", line 626, in dispatch res = fn(db, uid, *params) File "E:\erp7\openerp\osv\osv.py", line 188, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "E:\erp7\openerp\osv\osv.py", line 131, in wrapper return f(self, dbname, *args, **kwargs) File "E:\erp7\openerp\osv\osv.py", line 197, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "E:\erp7\openerp\osv\osv.py", line 185, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "E:\erp7\addons\base\module\module.py", line 426, in button_immediate_install return self._button_immediate_function(cr, uid, ids, self.button_install, context=context) File "E:\erp7\addons\base\module\module.py", line 473, in _button_immediate_function _, pool = pooler.restart_pool(cr.dbname, update_module=True) File "E:\erp7\openerp\pooler.py", line 39, in restart_pool registry = RegistryManager.new(db_name, force_demo, status, update_module) File "E:\erp7\openerp\modules\registry.py", line 233, in new openerp.modules.load_modules(registry.db, force_demo, status, update_module) File "E:\erp7\openerp\modules\loading.py", line 354, in load_modules loaded_modules, update_module) File "E:\erp7\openerp\modules\loading.py", line 256, in load_marked_modules loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks) File "E:\erp7\openerp\modules\loading.py", line 165, in load_module_graph init_module_models(cr, package.name, models) File "E:\erp7\openerp\modules\module.py", line 385, in init_module_models t[1](cr, *t[2]) File "E:\erp7\openerp\osv\orm.py", line 2807, in _update_store cr.execute(update_query, (ss[1](val), key)) File "E:\erp7\openerp\osv\fields.py", line 1092, in <lambda> self._symbol_set = ('%s', lambda x: float_repr(float_round(__builtin__.float(x or 0.0), TypeError: float() argument must be a string or a number

 

Thanks for help!

3

Hi,

If you are use one function to calculate more then one field then you have to use multi attribute into field defination. So, first of all put multi attribute into your code as like below.

_columns = {
        'tax_base': fields.function(
            _tax_balance, method=True,
            string='Tax base',
            store=True, multi=True),
        'tax_amount': fields.function(
            _tax_balance, method=True,
            string="Amount Tax",
            store=True, multi=True),

0
Alcaline
On 10/11/14, 4:46 AM

Got the same problem. but it doesn't work the multi = True on my codes..

0
Marek Jan-Alexander
On 10/10/14, 6:07 AM

easy solution & works great. Thanks!

About This Community

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

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 10/9/14, 1:17 PM
Seen: 2401 times
Last updated: 4/1/15, 7:48 AM