跳至内容
菜单
此问题已终结

When I create a filter, for example, for contacts with more than 10 sales orders, Odoo filters out all 99 of my contacts (seee image), even if only one contact has more than 10 sales orders.



How to correct this and create filters based on the number of sales orders?

Thanks

Ricardo

形象
丢弃
最佳答案

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)


形象
丢弃
编写者

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

相关帖文 回复 查看 活动
1
10月 25
1405
2
8月 25
2270
0
5月 25
1318
0
1月 25
1654
1
2月 24
1748