Odoo xml 树视图未显示所有预期结果

Odoo xml tree view not showing all expected results

我正在尝试对每个产品的销售和采购 t运行saction 进行报告,因为它从不同的模型(表)中选择字段,我必须根据 sql 查看 现在的问题是,在 xml 树视图中,它没有 return 返回它应该返回的所有结果,我检查了 sql 视图查询并 运行 postegres,它 return 有 30 行,但 xml 树视图上显示的只有 17

下面的代码

class ProductProfileReportView(models.Model):
    _name = "product.profile.report"
    _auto = False

    product_id = fields.Many2one(comodel_name="custom.product", string="Product", required=False, )
    action_type = fields.Char(string="Type")
    create_date = fields.Datetime(string="Date")
    invoice_id = fields.Many2one(comodel_name="custom.purchase", string="Invoice", required=False, )
    qty = fields.Integer(string="Qty")
    supplier_id = fields.Many2one(comodel_name="custom.supplier", string="Supplier", required=False, )
    customer_id = fields.Many2one(comodel_name="custom.customer", string="Customer", required=False, )
    price = fields.Float(string="Price")

    @api.model_cr
    def init(self):
        """ Event Question main report """
        tools.drop_view_if_exists(self._cr, 'product_profile_report')
        self._cr.execute(""" CREATE OR REPLACE VIEW product_profile_report AS (
            (select 
            ROW_NUMBER() OVER (ORDER BY product_id) AS id,
            custom_product.id as product_id, 
            'Purchase' as action_type, 
            custom_purchase.create_date as create_date, 
            custom_purchase.id as invoice_id, 
            custom_purchase_line.qty as qty, 
            custom_supplier.id as supplier_id,
            '0' as customer_id, 
            custom_product.sell_price as price
            from custom_product
            inner join custom_purchase_line
            on custom_product.id = custom_purchase_line.product_id
            inner join custom_purchase
            on custom_purchase_line.purchase_id = custom_purchase.id
            inner join custom_supplier
            on custom_purchase.supplier_id = custom_supplier.id)
            union
            (select 
            ROW_NUMBER() OVER (ORDER BY custom_product.id) AS id,
            custom_product.id as product_id,
            'Sale' as action_type, 
            custom_sale.create_date as create_date, 
            custom_sale.id as invoice_id, 
            custom_sale_line.qty as qty, 
            '0' as supplier_id,
            custom_customer.id as customer_id, 
            custom_product.sell_price as price
            from 
            custom_product
            inner join custom_sale_line
            on custom_product.id = custom_sale_line.branch_product_ids
            inner join custom_sale
            on custom_sale_line.order_id = custom_sale.id
            inner join custom_customer
            on custom_sale.customer_id = custom_customer.id))""")

最有可能的问题出在这里ROW_NUMBER() OVER (ORDER BY product_id) AS id, 所有 id 值都必须是唯一的且非零。而且当你过滤和分组时,ids 应该是稳定的。