Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged

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


Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
lis 23
1559
1
dub 24
3579
4
čvn 20
4496
1
bře 15
5072
0
lis 23
1788