Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Create marketing automation filters based on number of sales orders

Avatar
Discard
1 Answer
0
Avatar
odoo
Best Answer

Hi, Ricardo!
Odoo, by default, does not allow filtering directly by aggregated fields, with that, Odoo ends up applying the filter to all contacts, without considering the actual number of orders associated with each of them.

The suggestion would be to create a custom field that counts and stores the number of sales orders related to the contact:

from odoo import models, fields, api

class ResPartner(models.Model):
    _inherit = 'res.partner'

    # Computed field that counts the associated sales orders
    new_sales_order_count = fields.Integer(
        string='Número de Pedidos de Vendas',
        compute='_compute_sales_order_count'
    )

    @api.depends('sale_order_ids')
    def _compute_sales_order_count(self):
        for partner in self:
            partner.new_sales_order_count = len(partner.sale_order_ids)


1 Comment
Avatar
Discard
Avatar
odoo
-

obrigado Renata!what if my question tag is wrong and it should be 18SaaS, i.e. only with Studio available for customisation?
thanks
BR
Ricardo