Python
from odoo import models, fields, api
from odoo import tools
from odoo.osv import expression

class ReportPurchaseHistory(models.Model):
    _name = 'report.purchase.history'
    _description = 'Purchase History'
    _rec_name = 'purchase_order_id'
    _auto = False

    purchase_order_id = fields.Many2one('purchase.order', string='Số đơn hàng')
    account_move_id = fields.Many2one('account.move', string='Số hoá đơn')
    invoice_date = fields.Date(string='Ngày hoá đơn')
    partner_id = fields.Many2one('res.partner', string='Nhà cung cấp')
    product_id = fields.Many2one('product.product', string='Sản phẩm')
    qty = fields.Float(string='Số lượng')
    price = fields.Float(string='Đơn giá')
    po_price = fields.Float(string='Đơn giá PO')
    amount = fields.Float(string='Thành tiền')
    search_product = fields.Char(string='Search Product')

    def init(self):
        tools.drop_view_if_exists(self.env.cr, self._table)
        query = """
            CREATE OR REPLACE VIEW report_purchase_history AS
            SELECT 
                row_number() OVER() AS id,
                po.id as purchase_order_id,
                am.id as account_move_id, 
                am.invoice_date as invoice_date,
                am.partner_id as partner_id,
                aml.product_id as product_id,
                aml.quantity as qty,
                aml.price_unit as price,
                pol.price_unit as po_price,
                aml.price_subtotal as amount,
                case
                    when pp.default_code != '' then '[' || pp.default_code || '] ' || pt.name
                    else pt.name
                end as search_product,
                po.create_uid as create_uid,
                po.create_date as create_date,
                po.write_uid as write_uid,
                po.write_date as write_date
            FROM account_move am
                LEFT JOIN account_move_line aml ON am.id = aml.move_id
                LEFT JOIN purchase_order_line pol ON aml.purchase_line_id = pol.id
                LEFT JOIN purchase_order po ON pol.order_id = po.id
                LEFT JOIN product_product pp ON aml.product_id = pp.id
                LEFT JOIN product_template pt ON pp.product_tmpl_id = pt.id
            WHERE am.state = 'posted'
            AND aml.purchase_line_id IS NOT NULL
        """
        self.env.cr.execute(query)

    @api.model
    def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None, **read_kwargs):
        res = super(ReportPurchaseHistory, self).search_read(domain=domain, fields=fields, offset=offset, limit=limit,
                                                             order=order, **read_kwargs)
        return res


class ProductProduct(models.Model):
    _inherit = 'product.product'

    def name_get(self):
        result = super(ProductProduct, self).name_get()
        # Thực hiện các thay đổi cần thiết
        return result

    @api.model
    def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
        args = args or []
        domain = []
        if name:
            domain = ['|', '|', ('default_code', operator, name), ('name', operator, name), ('barcode', operator, name)]
        return self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)

    def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None, **read_kwargs):
        res = super(ProductProduct, self).search_read(domain=domain, fields=fields, offset=offset, limit=limit,
                                                             order=order, **read_kwargs)
        return res


    @api.model
    def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None, **read_kwargs):
        res = super(ReportPurchaseHistory, self).search_read(domain=domain, fields=fields, offset=offset, limit=limit, order=order, **read_kwargs)
        return res
        
-------------------------------Code view----------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <record id="report_purchase_history_view_tree" model="ir.ui.view">
        <field name="name">report.purchase.history.view.tree</field>
        <field name="model">report.purchase.history</field>
        <field name="arch" type="xml">
            <tree string="" default_order="invoice_date desc" create="0" edit="0" duplicate="0" delete="0">
                <field name="purchase_order_id"/>
                <field name="account_move_id"/>
                <field name="invoice_date"/>
                <field name="partner_id"/>
                <field name="product_id"/>
                <field name="qty"/>
                <field name="price"/>
                <field name="po_price"/>
                <field name="amount"/>
                <field name="search_product" invisible="1"/>
            </tree>
        </field>
    </record>

    <record id="report_purchase_history_view_form" model="ir.ui.view">
        <field name="name">report.purchase.history.view.form</field>
        <field name="model">report.purchase.history</field>
        <field name="arch" type="xml">
            <form string="" create="0" edit="0" duplicate="0" delete="0">
                <sheet>
                    <group>
                        <field name="purchase_order_id" readonly="1"/>
                        <field name="account_move_id" readonly="1"/>
                        <field name="invoice_date" readonly="1"/>
                        <field name="partner_id" readonly="1"/>
                        <field name="product_id" readonly="1"/>
                        <field name="qty" readonly="1"/>
                        <field name="price" readonly="1"/>
                        <field name="po_price" readonly="1"/>
                        <field name="amount" readonly="1"/>
                        <field name="search_product" invisible="1"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record id="report_purchase_history_view_search" model="ir.ui.view">
        <field name="name">Lịch sử mua hàng Search</field>
        <field name="model">report.purchase.history</field>
        <field name="arch" type="xml">
            <search string="Search">
                <field name="purchase_order_id" string="Số đơn hàng"/>
                <field name="account_move_id" string="Số hóa đơn"/>
                <field name="partner_id" string="Nhà cung cấp"/>
                <field name="search_product" string="Sản phẩm"/>
                <group expand="0" string="Group By">
                    <filter string="Số đơn hàng" name="purchase_order_id" context="{'group_by':'purchase_order_id'}"/>
                    <filter string="Số hóa đơn" name="account_move_id" context="{'group_by':'account_move_id'}"/>
                    <filter string="Nhà cung cấp" name="partner_id" context="{'group_by':'partner_id'}"/>
                    <filter string="Sản phẩm" name="product_id" context="{'group_by':'product_id'}"/>
                </group>
            </search>
        </field>
    </record>

    <record id="report_purchase_history_action" model="ir.actions.act_window">
        <field name="name">Lịch sử mua hàng</field>
        <field name="res_model">report.purchase.history</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="report_purchase_history_view_search"/>
    </record>

    <menuitem
            id="report_purchase_history_menu"
            name="Lịch sử mua hàng"
            action="report_purchase_history_action"
            parent="purchase.menu_procurement_management"
            sequence="10"/>

</odoo>