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

Functional fields

By
Marek Jan-Alexander
on 10/9/14, 1:17 PM 1,505 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

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 10/10/14, 3:19 AM

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!

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

2 follower(s)

Stats

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