콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
6048 화면

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!  

   

아바타
취소
베스트 답변

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
아바타
취소
작성자

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"

작성자

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

작성자

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.

작성자

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!

관련 게시물 답글 화면 활동
1
7월 18
3858
18
12월 22
37845
0
6월 17
5690
8
9월 20
11127
2
3월 18
5087