Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
5560 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Autor

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"

Autor

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

Autor

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.

Autor

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!

Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 18
3494
18
dic 22
36964
0
jun 17
5370
8
sept 20
10708
2
mar 18
4750