Skip to Content
Menu
This question has been flagged
1 Reply
2388 Views

In my odoo app I have extended partner model so in the adrees it can hold information about the municipality and neightbourhood of a partner. I have also extended the the sale_report model, so I can get a report of sales grouped by the state, municipality and neighbourhood of the partner. But when I want to edit the information of the biling address in the website_sale (ecommerce) i am getting the following error: psycopg2.OperationalError: cannot update view "sale_report"

here is the error:

Traceback (most recent call last):
  File "/home/ernesto/Programming/odoo/odoo13/odoo/addons/base/models/ir_http.py", line 234, in _dispatch
    result = request.dispatch()
  File "/home/ernesto/Programming/odoo/odoo13/odoo/http.py", line 809, in dispatch
    r = self._call_function(**self.params)
  File "/home/ernesto/Programming/odoo/odoo13/odoo/http.py", line 350, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/ernesto/Programming/odoo/odoo13/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/ernesto/Programming/odoo/odoo13/odoo/http.py", line 346, in checked_call
    flush_env(self._cr)
  File "/home/ernesto/Programming/odoo/odoo13/odoo/sql_db.py", line 76, in flush_env
    env_to_flush['base'].flush()
  File "/home/ernesto/Programming/odoo/odoo13/odoo/models.py", line 5497, in flush
    process(self.env[model_name], id_vals)
  File "/home/ernesto/Programming/odoo/odoo13/odoo/models.py", line 5488, in process
    recs._write(vals)
  File "/home/ernesto/Programming/odoo/odoo13/odoo/models.py", line 3691, in _write
    cr.execute(query, params + [sub_ids])
  File "/home/ernesto/Programming/odoo/odoo13/odoo/sql_db.py", line 173, in wrapper
    return f(self, *args, **kwargs)
  File "/home/ernesto/Programming/odoo/odoo13/odoo/sql_db.py", line 250, in execute
    res = self._obj.execute(query, params)
psycopg2.OperationalError: cannot update view "sale_report"
DETAIL:  Views containing GROUP BY are not automatically updatable.
HINT:  To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule

here is my code:

class Partner(models.Model):
    _inherit = 'res.partner'

    municipality_id = fields.Many2one('res.country.state.municipality', string='Municipality',  domain="[('state_id', '=?', state_id)]")
    neighbourhood_id = fields.Many2one('res.country.state.municipality.neighbourhood', string='Neighbourhood',  domain="[('municipality_id', '=?', municipality_id)]")

class SaleReport(models.Model):
    _inherit = 'sale.report'
    
    shipping_state_id = fields.Many2one('res.country.state', string='State', related="partner_id.state_id", store="True")
    shipping_municipality_id = fields.Many2one('res.country.state.municipality', string='Municipality', related="partner_id.municipality_id",store="True")
    shipping_neighbourhood_id = fields.Many2one('res.country.state.municipality.neighbourhood', string='Neighbourhoods', related="partner_id.neighbourhood_id", store="True")



    def _query(self, with_clause='', fields={}, groupby='', from_clause=''):
        fields['shipping_state_id'] = ", s.shipping_state_id as shipping_state_id"
        
        fields['shipping_municipality_id'] = ", s.shipping_municipality_id as shipping_municipality_id"
        fields['shipping_neighbourhood_id'] = ", s.shipping_neighbourhood_id as shipping_neighbourhood_id"
        
        groupby += ', s.shipping_state_id, s.shipping_municipality_id, s.shipping_neighbourhood_id'
        return super(SaleReport, self)._query(with_clause, fields, groupby, from_clause)


Avatar
Discard
Best Answer

Hi Ernesto Ruiz,

Let me know which version you are using. I think you need to redefine _query completely as the column names might not be present in select query. To add group by ColumnName, that ColumnName should be present in select query columns as well.

Avatar
Discard
Related Posts Replies Views Activity
1
Sep 24
326
1
Jul 24
273
1
May 24
1634
1
May 24
647
0
Mar 24
4