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

I've got a big problem, I overridden the sale.report like any other model, but when I delete the module it deletes the sale.report! This has probably something to do that sale.report isn't a table but a database view.

How I overridden it

class SaleReportGDPR(models.Model):
    _inherit = 'sale.report'


    def _from(self):
        from_str = """
                sale_order_line l
                      join sale_order s on (l.order_id=s.id)
                      join res_partner partner on (s.partner_id = partner.id and partner.personal_data=true)
                        left join product_product p on (l.product_id=p.id)
                            left join product_template t on (p.product_tmpl_id=t.id)
                    left join product_uom u on (u.id=l.product_uom)
                    left join product_uom u2 on (u2.id=t.uom_id)
                    left join product_pricelist pp on (s.pricelist_id = pp.id)
                    left join currency_rate cr on (cr.currency_id = pp.currency_id and
                        cr.company_id = s.company_id and
                        cr.date_start <= coalesce(s.date_order, now()) and
                        (cr.date_end is null or cr.date_end > coalesce(s.date_order, now())))    
        """
        return from_str

How is the right way to do this so I can upgrade my custom module so it won't delete the database view when I uninstall it? Now on uninstall it also breaks EVERY other database instance that uses the sale module so you can't see the product details when you select it. It just throws a ProgrammingError: relation "sale_report" does not exist!  

   

Avatar
Discard
Best Answer

Hello Samo Arko,


You don't need to Override, you can also use with call super()

 below example will help you in your case:

def _from(self):
    res = super(SaleReportGDPR, self)._from()
    from_str = res + """         here your query as per your requirement     """     return from_str


Thanks
Avatar
Discard
Author

But I need to inherit sale report or where should put this? I think that the inherit sale report breaks the sale addon when I remove the custom module.

hello,

my example already for Inherited sale.report,

I already used in my custom module and it will not breaks anything.

class sale_report(models.Model):

_inherit = 'sale.report'

event_id = fields.Many2one('event.event', string=_('Event'))

def _from(self):

res = super(sale_report, self)._from()

from_str = res + """

left join event_event e on e.id = s.event_id

"""

return from_str

def _select(self):

return super(sale_report, self)._select() + ", e.id as event_id"

def _group_by(self):

return super(sale_report, self)._group_by() + ", e.id"

Author

Ok... thanks I'll try it out.

Author

Nope this doesn't work! This would be useful if I'd wanted to add something to the original _from query. I need to change the query. But thanks for trying to help.

Author

from_str = """

left join event_event e on e.id = s.event_id

"""

This gets the same result like my code and when I uninstall it it also removes the sale_report database view!

Related Posts Replies Views Activity
1
Jul 18
2553
18
Dec 22
34558
0
Jun 17
4277
8
Sep 20
9376
2
Mar 18
3698