美文网首页odoo
odoo12 在自己的账号里添加菜单

odoo12 在自己的账号里添加菜单

作者: 隔壁小红馆 | 来源:发表于2020-03-03 17:11 被阅读0次

    有时,客户有自己的属性,比如自己买的东西,要随时能查看自己的订单信息,即需要来查看自己的东西。
    以自己写过的为例:


    图片.png
    • 在客户自己的账号里添加菜单


      图片.png
    # t-set="title" 菜单名称
    # t-set="url" 跳转路径
    # t-set="count" 显示条数
    
    # xml 定义菜单
        <template id="custom_myself_ticket_order" name="Portal My Home : My Tickets"
                  inherit_id="portal.portal_my_home" priority="45">
            <xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
                <t t-call="portal.portal_docs_entry">
                    <t t-set="title">My Tickets</t>
                    <t t-set="url" t-value="'/my/ticket'"/>
                    <t t-set="count" t-value="myself_ticket_count"/>
                </t>
            </xpath>
        </template>
    
    • 跳转到 t-set="url" 指定地址


      图片.png
    #controllers.py 定义菜单跳转到那个视图去
    @http.route(['/my/ticket'], type='http', auth="user", website=True)
        def my_ticket(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw):
            values = self._prepare_portal_layout_values()
            TD = request.env['ticket.detail']
            searchbar_sortings = {   # seq: 搜索项在页面上的排序
                'sequence': {'label': _('Sequence'), 'order': 'sequence desc, id desc'},
                'date': {'label': _('Date'), 'order': 'date desc, id desc'},
                # 'name': {'label': _('Name'), 'order': 'name'},
            }
            if not sortby:
                sortby = 'date'
            order = searchbar_sortings[sortby]['order']
            searchbar_filters = {  # 筛选项
                'all': {'label': _('All'), 'domain': [('state', 'in', ['reserved', 'purchased', 'entered', 'cancel', 'refund'])],
                        'seq': 1},
                'reserved': {'label': _('Reserved'), 'domain': [('state', '=', 'reserved')], 'seq': 2},
                'purchased': {'label': _('Purchased'), 'domain': [('state', '=', 'purchased')], 'seq': 3},
                'entered': {'label': _('Entered'), 'domain': [('state', '=', 'entered')], 'seq': 4},
                'cancel': {'label': _('Cancel'), 'domain': [('state', '=', 'cancel')], 'seq': 5},
                'refund': {'label': _('Refund'), 'domain': [('state', '=', 'refund')], 'seq': 6},
            }
    
            domain = [('id_number', '=', request.env.user.partner_id.id_number), ('name', '=', request.env.user.name)]
            if not filterby:
                filterby = 'all'
            domain += searchbar_filters[filterby]['domain']
            ticket_count = TD.sudo().search_count(domain)
            pager = portal_pager(
                url="/my/ticket",
                url_args={'date_begin': date_begin, 'date_end': date_end},
                total=ticket_count,
                page=page,
            )
            tickets = TD.sudo().search(domain, order=order, offset=pager['offset'])
            request.session['my_tickets_history'] = tickets.ids[:100]
            values.update({
                'date': date_begin,
                'tickets': tickets,
                'page_name': 'Ticket',
                'pager': pager,
                'searchbar_sortings': searchbar_sortings,
                'sortby': sortby,
                'filterby': filterby,
                'searchbar_filters': OrderedDict(sorted(searchbar_filters.items(), key=lambda item: item[1]['seq'])),
                'default_url': '/my/ticket',
                'partner_id': request.env.user.id,
            })
            return request.render("ticket_management.myself_ticket_management_order", values)
    

    searchbar_filters # 筛选项


    图片.png
    • 根据py文件里跳转到指定视图
        <template id="myself_ticket_management_order" name="Portal: My Tickets">
            <t t-call="portal.portal_layout">
                <t t-call="portal.portal_searchbar">
                    <t t-set="title">My Tickets</t>
                </t>
                <t t-if="not tickets">
                    <p>You don't have ticket orders.</p>
                </t>
                <t t-if="tickets" t-call="portal.portal_table">
                    <thead>
                        <tr class="form_center">
                            <th>Order NO</th>
                            <th>Name</th>
                            <th>Museum</th>
                            <th>Ticket Date</th>
                            <!--<th style="vertical-align:middle;text-align:center">Museum Address</th>-->
                            <th>Order State</th>
                            <!--<th style="vertical-align:middle;text-align:center"></th>-->
                        </tr>
                    </thead>
                    <tbody>
                        <t t-foreach="tickets" t-as="ticket">
                            <tr>
                                <td class="form_center">
                                    <a t-attf-href="/buy/ticket/my/ticket/detail/#{ticket.id}?">
                                        <t t-esc="ticket.sequence"/>
                                    </a>
                                </td>
                                <td class="form_center">
                                    <span t-field="ticket.name"/>
                                </td>
                                <td class="form_center">
                                    <span t-field="ticket.ticket_id.name"/>
                                </td>
                                <td class="form_center">
                                    <span t-field="ticket.date"/>
                                </td>
                                <td class="form_center">
                                    <span t-field="ticket.state"/>
                                </td>
                                <!--<td style="vertical-align:middle;text-align:center">-->
                                <!--<a role="button" t-attf-href="/my/ticket/detail/#{ticket.id}?"-->
                                <!--class="btn btn-sm btn-secondary oe_stat_button">-->
                                <!--详情-->
                                <!--</a>-->
                                <!--</td>-->
                            </tr>
                        </t>
                    </tbody>
                </t>
            </t>
        </template>
    

    显示 xml 里面定义的样式,类似这样,多个就这样显示

    图片.png

    根据 xml里的 a 标签,再次跳转到指定视图

    # py定义
    @http.route(['/buy/ticket/my/ticket/detail/<int:ticket_id>'], type='http', auth="user", website=True)
        def my_ticket_detail(self, ticket_id):
            ticket = request.env['ticket.detail'].sudo().browse(ticket_id)
            values = {'ticket': ticket}
            return request.render('ticket_management.my_tickets_detail', values)
    # xml
    <template id="my_tickets_detail" name="My Tickets Detail">
            <t t-call="portal.frontend_layout">
                ....
            </t>
        </template>
    
    • 然后根据需要定义适合自己的视图页面

    看完记得点赞哦,笔芯

    相关文章

      网友评论

        本文标题:odoo12 在自己的账号里添加菜单

        本文链接:https://www.haomeiwen.com/subject/ykihlhtx.html