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

Fields in 'groupby' must be regular database-persisted fields ?

By
heru
on 1/30/15, 1:38 AM 913 views

when i want to add 'group by' in form 'sales analysis' ...

i make code in .py :

class sales_analysis(osv.osv):
    _name = "sales.analysiss"
    _auto = False
    _columns = {
                'jenis': fields.selection([
                                            ('Jual', 'Jual'),
                                            ('Sewa', 'Sewa'),
                                            ], 'Jenis Transaksi', required=True, 
                                            help="jual or sewa", select=True),  
                }

in .xml :

<record id="sale_report_search_form_view" model="ir.ui.view">
             <field name="name">sale.report.search</field>
             <field name="model">sale.report</field>
             <field name="inherit_id" ref="sale.view_order_product_search"/>    
             <field name="arch" type="xml">
                 <xpath expr="//group/filter[@string='Salesperson']" position="after">
                    <filter string="Jenis Transaksi" context="{'group_by':'jenis'}"/>
                </xpath>
             </field>                  
         </record>

 

and the result is error, like :

2015-01-30 04:31:33,834 8627 ERROR century21-new2 openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/osv/osv.py", line 132, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/osv/osv.py", line 199, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/osv/osv.py", line 187, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/osv/orm.py", line 2717, in read_group
    assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True
2015-01-30 04:31:33,834 8627 ERROR century21-new2 openerp.netsvc: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True
Traceback (most recent call last):
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/netsvc.py", line 296, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/service/web_services.py", line 632, in dispatch
    res = fn(db, uid, *params)
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/osv/osv.py", line 190, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/osv/osv.py", line 132, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/osv/osv.py", line 199, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/osv/osv.py", line 187, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/heru/odoo/openerp-7.0/openerp-7.0-20150118/openerp/osv/orm.py", line 2717, in read_group
    assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"

 

how i fix my problems ?

thanks...

 

Column "jenis" exist in database? why _auto=False?

zbik
on 1/30/15, 9:52 AM

i look in example in module odoo, but i don't know function _auto . @zbik, can you explain about _auto ?

heru
on 2/2/15, 11:22 PM
1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 1/30/15, 11:21 AM

@heru.  Your class definition will create a model name "sales.analysiss" that has 1 column/field, which is 'jenis' and when instantiated it WOULD NOT create a table (_auto=False).  If you need to add 'jenis' field into "sale.report" model (as your view XML indicated), then you need to:

  1. inherit sale.report model (put _inherit = "sale.report" in the class but don't put _name = "sales.analysiss" as this way ORM will think that there is another database "object"
  2. add the column as you have stated. BUT, since "sale.report" table (italics on purpose) is not created by default (_auto = False, from odoo/odoo/addons/sale/report/sale_report.py), you NEED to re-define the view.  In the original definition of "sale.report" you'll see a view is created instead of table in the class' init method.  You need to do the same with the inherited model and add the 'jenis' field into the view definition SQL statement.

ok thanks Ivan

heru
on 2/2/15, 11:21 PM

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: 1/30/15, 1:38 AM
Seen: 913 times
Last updated: 3/16/15, 8:10 AM