Search code examples
javascriptodoopoint-of-saleodoo-17

Get POS Resturant session User/ Cashier


In odoo v17 POS Resturant, for Multi Employees per Session how to get POS session user and check whether it belongs to Basic Rights or Advanced Rights.

Depending on the above condition need to make button show or hide in the Payment screen.

In the below Screens, I want to Check whether Manager1 is having Basic Rights or Advance Rights in the config and based on that Invoice Button should be visible in the payment screen.

Below code is working fine for the Odoo logged in User but I need to implement it for the POS Session user or Cashier user

enter image description hereenter image description here

class pos_config(models.Model):
    _inherit = 'pos.config'

    show_invoice = fields.Boolean(string="Show Invoice", compute="_compute_invoice_button", store=True)

    @api.depends('basic_employee_ids', 'advanced_employee_ids')
    def _compute_invoice_button(self):
        if self.env.user.employee_id in self.advanced_employee_ids:
            self.write({'show_invoice': True})
        else:
            self.write({'show_invoice': False})




<t t-name="pos_button.PaymentScreenButtons" t-inherit="point_of_sale.PaymentScreenButtons" t-inherit-mode="extension">
        <xpath expr="//button[hasclass('button') and hasclass('js_invoice')]" position="attributes">
            <attribute name="t-att-hidden">!pos.config.show_invoice</attribute>
        </xpath>
    </t>

Solution

  • By directly comparing with the values loaded in the component, the following xpath suffices to satisfy your requirements. You can simply do it without the python inheritance and the compute method.

    <t t-name="pos_button.PaymentScreenButtons" t-inherit="point_of_sale.PaymentScreenButtons" t-inherit-mode="extension">
       <xpath expr="//button[hasclass('button') and hasclass('js_invoice')]" position="attributes">
          <attribute name="t-att-hidden">!this.pos.config.advanced_employee_ids.includes(this.pos.cashier.id)</attribute>
       </xpath>
    </t>