Ir al contenido
Menú
Se marcó esta pregunta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 23
1547
1
abr 24
3575
4
jun 20
4494
1
mar 15
5068
0
nov 23
1785