Odoo 16 / 自定义网站:分页问题

问题描述 投票:0回答:1

我对搜索结果进行了分页。对于第一个,查询集给了我完美的结果,但是分页设置了所有页面,我通过单击任何页码从数据库中获取所有数据。

这是我的代码:

这是我添加的控制器:

 class MyCustomWeb(http.Controller):
        @http.route(['/customer', '/customer/page/<int:page>'], type="http", auth="user", website=True)
        def customer_kanban(self, page=1, search=None, **post):
            domain = []
            if search:
                domain.append(('name', 'ilike', search))
            post["search"] = search
            customer_obj = request.env['res.partner'].sudo().search(domain)
            total = customer_obj.sudo().search_count([])
            pager = request.website.pager(
            url='/customer',
            total=total,
            page=page,
            step=3,
            )

            offset = pager['offset']
            customer_obj = customer_obj[offset: offset + 5]
            return request.render('my_module.customer_form', {
                'search': search,
                'customer_details': customer_obj,
                'pager': pager,
            })

这是XML代码:客户网站模板:

    <template id="customer_form" name="Customers">
        <t t-call="website.layout">
            <div>
                <div class="col-md-6">
                    <br/>
                    <div>
                        <form action="/customer" method="post">
                            <t t-call="website.website_search_box">
                            </t>
                            <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
                            <div>
                                <section>
                                    <div class="customer_details">
                                        <center>
                                            <h3>Customers</h3>
                                        </center>
                                    </div>
                                    <br/>
                                    <div class="oe_product_cart_new row" style="overflow: hidden;">
                                        <t t-foreach="customer_details" t-as="customers">
                                            <div class="col-md-3 col-sm-3 col-xs-12"
                                                 style="padding:1px 1px 1px 1px;">
                                                <div style="border: 1px solid #f0eaea;width: 150px;height: auto;padding: 7% 0% 10% 0%;
border-radius: 3px;overflow: hidden;
margin-bottom: 44px !important;width: 100%;height: 100%;">
                                                    <div class="oe_product_image">
                                                        <center>
                                                            <div style="width:100%;overflow: hidden;">
                                                                <img t-if="customers.image_1920"
                                                                     t-attf-src="/web/image/res.partner/#{customers.id}/image_1920"
                                                                     class="img oe_product_image"
                                                                     style="padding: 0px; margin: 0px; width:auto; height:100%;"/>
                                                            </div>
                                                            <div style="text-align: left;margin: 10px 15px 3px 15px;">
                                                                <t t-if="customers.name">
                                                                    <span t-esc="customers.name"
                                                                          style="font-weight: bolder;color: #3e3b3b;"/>
                                                                    <br/>
                                                                </t>
                                                            </div>
                                                        </center>
                                                    </div>
                                                </div>
                                            </div>
                                        </t>
                                    </div>
                                    <div class="products_pager form-inline justify-content-center mt-3">
                                        <t t-call="website.pager">
                                            <t t-set="_classes">mt-2 ml-md-2</t>
                                        </t>
                                    </div>
                                </section>
                                <br/>
                                <hr class="border-600 s_hr_1px w-100 mx-auto s_hr_dotted"/>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </t>
    </template>

请问有什么帮助吗? 谢谢。

python xml controller odoo
1个回答
0
投票

如果是由不正确的偏移引起的,您可以尝试此代码来解决问题。

offset = (page - 1) * step
© www.soinside.com 2019 - 2024. All rights reserved.