Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
689 Представления

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


Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
нояб. 23
1566
1
апр. 24
3588
4
июн. 20
4502
1
мар. 15
5077
0
нояб. 23
1792