This question has been flagged
1 Reply
3813 Views

Hi, im trying to extend pos_order_report in order to add the posibility of group by Product Category, but i get this error when i group-by the category:

*****************************************************************************************************************************************************************

Client Traceback (most recent call last): File "/vagrant/odoo/addons/web/http.py", line 204, in dispatch response["result"] = method(self, **self.params) File "/vagrant/odoo/addons/web/controllers/main.py", line 1128, in call_kw return self._call_kw(req, model, method, args, kwargs) File "/vagrant/odoo/addons/web/controllers/main.py", line 1120, in _call_kw return getattr(req.session.model(model), method)(*args, **kwargs) File "/vagrant/odoo/addons/web/session.py", line 42, in proxy result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw) File "/vagrant/odoo/addons/web/session.py", line 30, in proxy_method result = self.session.send(self.service_name, method, *args) File "/vagrant/odoo/addons/web/session.py", line 103, in send raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info) Server Traceback (most recent call last): File "/vagrant/odoo/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/vagrant/odoo/openerp/netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/vagrant/odoo/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, *params) File "/vagrant/odoo/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/vagrant/odoo/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/vagrant/odoo/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/vagrant/odoo/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/vagrant/odoo/openerp/osv/orm.py", line 2707, in read_group if fget[f]['type'] in ('integer', 'float') KeyError: 'categ_id'

*****************************************************************************************************************************************************************

this is the __init__.py

>>>>>>>>>
import report

<<<<<<<<<

this is the __openerp__.py

>>>>>>>>

{
    'name': 'Extended POS Orders Report ',
    'version': '1.0.11',
    'category': 'Sales',
    'description': """
    Agrega agrupamiento por categoria de productos al Analisis de Pedidos.
    """,
    'author': 'Sysfe',
    'website': 'http://www.sysfe.com.ar',
    'depends': [
    'sale','account','point_of_sale'
    ],
    'init_xml': [
    ],
    'data': [],
    # 'update_xml': [],
    'update_xml': ['report/pos_monthly_repo.xml'],
    'demo_xml': [
    ],
    'installable': True,
    'active': True,
}

<<<<<<<<

this is the pos_order_report.py

>>>>>>>>

from openerp import tools
from openerp.osv import fields,osv

class pos_order_report(osv.osv):
    
    _name = "report.pos.order"
    _inherit = "report.pos.order"
    _description = "Point of Sale Orders Statistics Monthly"
    _auto = False
    _columns = {
        'categ_id': fields.many2one('product.category','Category of Product', readonly=True),
    }
    
    _default = {
        'categ_id': '',
    }
    _order = 'date desc'
        
    def init(self, cr):
        tools.drop_view_if_exists(cr, 'pos_monthly_repo')
        cr.execute("""
            create or replace view pos_monthly_repo as (
                select
                    min(l.id) as id,
                    count(*) as nbr,
                    to_date(to_char(s.date_order, 'dd-MM-YYYY'),'dd-MM-YYYY') as date,
                    sum(l.qty * u.factor) as product_qty,
                    sum(l.qty * l.price_unit) as price_total,
                    sum((l.qty * l.price_unit) * (l.discount / 100)) as total_discount,
                    (sum(l.qty*l.price_unit)/sum(l.qty * u.factor))::decimal(16,2) as average_price,
                    sum(cast(to_char(date_trunc('day',s.date_order) - date_trunc('day',s.create_date),'DD') as int)) as delay_validation,
                    to_char(s.date_order, 'YYYY') as year,
                    to_char(s.date_order, 'MM') as month,
                    to_char(s.date_order, 'YYYY-MM-DD') as day,
                    s.partner_id as partner_id,
                    s.state as state,
                    s.user_id as user_id,
                    s.shop_id as shop_id,
                    s.company_id as company_id,
                    s.sale_journal as journal_id,
                    l.product_id as product_id,
                    pt.categ_id as categ_id
                from pos_order_line as l
                    left join pos_order s on (s.id=l.order_id)
                    left join product_template pt on (pt.id=l.product_id)
                    left join product_uom u on (u.id=pt.uom_id)
                group by
                    to_char(s.date_order, 'dd-MM-YYYY'),to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),
                    to_char(s.date_order, 'YYYY-MM-DD'), s.partner_id,s.state,
                    s.user_id,s.shop_id,s.company_id,s.sale_journal,l.product_id,s.create_date,pt.categ_id
                having
                    sum(l.qty * u.factor) != 0)""")    
pos_order_report()

<<<<<<<<

this is the pos_monthly_repo.xml

>>>>>>>>>>>>

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="pos_monthly_repo_tree" model="ir.ui.view">
            <field name="name">pos.monthly.repo.tree</field>
            <field name="model">report.pos.order</field>
            <field name="arch" type="xml">
                <tree string="Point of Sale Analysis" create="false">
                    <field name="date" invisible="1"/>
                    <field name="user_id" invisible="1"/>
                    <field name="year" invisible="1"/>
                    <field name="day" invisible="1"/>
                    <field name="month" invisible="1"/>
                    <field name="partner_id" invisible="1"/>
                    <field name="product_id" invisible="1"/>
                    <field name="shop_id" invisible="1"/>
                    <!--<field name="journal_id" invisible="1"/>-->
                    <field name="company_id" invisible="1" groups="base.group_multi_company"/>
                    <field name="nbr" sum="# of Lines"/>
                    <field name="product_qty" sum="# of Qty"/>
                    <field name="average_price" sum="Average Price"/>
                    <field name="total_discount" sum="Total Discount"/>
                    <field name="price_total" sum="Total Price"/>
                    <field name="delay_validation"/>
                    <!--<field name="state" invisible="1"/>-->
                </tree>
            </field>
        </record>
        
        
        <record id="view_report_pos_order_search" model="ir.ui.view">
            <field name="name">pos.monthly.repo.search</field>
            <field name="model">report.pos.order</field>
            <field name="arch" type="xml">
                <search string="Point of Sale Analysis">
                    <field name="date"/>
                    <filter icon="terp-dolar" string="Invoiced" domain="[('state','=',('invoiced'))]"/>
                    <filter icon="terp-dolar" string="Not Invoiced" domain="[('state','=',('paid'))]"/>
                    <separator/>
                    <filter icon="terp-go-year" string="Year" name="year" domain="[('year','=',time.strftime('%%Y'))]" help="POS ordered created during current year"/>
                    <separator/>
                    <filter icon="terp-go-today" string="Today" name="today" domain="[('date','=', time.strftime('%%Y-%%m-%%d'))]"
                         help="POS ordered created by today"/>
                    <separator/>
                    <filter icon="terp-personal" string="My Sales" help="My Sales" domain="[('user_id','=',uid)]"/>
                    <field name="partner_id"/>
                    <field name="user_id"/>
                    <field name="partner_id"/>
                    <field name="user_id"/>
                    <group expand="1" string="Group By...">
                        <filter string="Salesperson" icon="terp-personal" name="User" context="{'group_by':'user_id'}"/>
                        <filter string="Customer" icon="terp-personal" context="{'group_by':'partner_id'}"/>
                        <filter string="Product" icon="terp-accessories-archiver" context="{'group_by':'product_id'}"/>
                        <filter string="Categoria de Producto" icon="terp-accessories-archiver" context="{'group_by':'categ_id'}"/>
                        <filter string="Day" icon="terp-go-today" context="{'group_by':'day'}" help="Day of order date"/>
                        <filter string="Month" icon="terp-go-month" context="{'group_by':'month'}" help="Month of order date"/>
                        <filter string="Year" icon="terp-go-year" context="{'group_by':'year'}" help="Year of order date"/>
                    </group>
                </search>
            </field>
        </record>

        <record id="pos_monthly_repo_all" model="ir.actions.act_window">
            <field name="name">Pedidos Mensuales</field>
            <field name="res_model">report.pos.order</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree</field>
            <field name="search_view_id" ref="view_report_pos_order_search"/>
            <field name="context">{'search_default_year':1,'search_default_today':1,'group_by_no_leaf':1,'group_by':['user_id']}</field>
        </record>

        <menuitem action="pos_monthly_repo_all" id="pos_monthly_repo_all" parent="base.menu_reporting_dashboard" sequence="7"/>        
    </data>
</openerp>

<<<<<<<<<<<

 

Can Anybody help me?

Thanks in advance

Martin

Avatar
Discard
Author Best Answer

Sorry, i forgot to add a __init__.py file in report folder, and inside there. So, i did set this code:

import pos_order_report

but when i did install again i get this new error

OpenERP Server Error

Client Traceback (most recent call last): File "/vagrant/odoo/addons/web/http.py", line 204, in dispatch response["result"] = method(self, **self.params) File "/vagrant/odoo/addons/web/controllers/main.py", line 1128, in call_kw return self._call_kw(req, model, method, args, kwargs) File "/vagrant/odoo/addons/web/controllers/main.py", line 1120, in _call_kw return getattr(req.session.model(model), method)(*args, **kwargs) File "/vagrant/odoo/addons/web/session.py", line 42, in proxy result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw) File "/vagrant/odoo/addons/web/session.py", line 30, in proxy_method result = self.session.send(self.service_name, method, *args) File "/vagrant/odoo/addons/web/session.py", line 103, in send raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info) Server Traceback (most recent call last): File "/vagrant/odoo/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/vagrant/odoo/openerp/netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/vagrant/odoo/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, *params) File "/vagrant/odoo/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/vagrant/odoo/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/vagrant/odoo/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/vagrant/odoo/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/vagrant/odoo/openerp/osv/orm.py", line 2685, 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

 

 

Avatar
Discard