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

I have a custom Many2many field (product_group_tags_id) in the Products model, and I would like to include it in the Sale Analysis report. I attempted to add it but was unable to retrieve the values. Is this possible?

Here is the code I tried:

class SaleReport(models.Model):

    _inherit = "sale.report"


    product_group_tags_id = fields.Many2many(

        'product.group',

        'product_product_product_group_rel', 'product_id', 'group_id',

        string='Product Group'

    )


    def _from_sale(self):

        res = super()._from_sale()

        res += """

            LEFT JOIN product_product_product_group_rel pg_rel ON p.id = pg_rel.product_id

            LEFT JOIN product_group g ON g.id = pg_rel.group_id

        """

        return res


    def _select_additional_fields(self):

        res = super()._select_additional_fields()

        res['product_group_tags_id'] = "ARRAY_AGG(g.id)"  # Aggregates IDs of product groups

        return res


    def _group_by_sale(self):

        res = super()._group_by_sale()

        res += """

            g.id

        """

        return res


아바타
취소
관련 게시물 답글 화면 활동
1
11월 23
1628
1
4월 24
3688
4
6월 20
4567
1
3월 15
5140
0
11월 23
1826