Skip to content

[ADD] salesperson_pos: added sales person button in pos and view in list #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions salesperson_pos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions salesperson_pos/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "SalesPerson Choosing Button In Pos",
"version": "1.0",
"depends": ["point_of_sale", "hr"],
"data": ["views/pos_order_views.xml"],
"appication": True,
"installable": True,
"assets": {
"point_of_sale._assets_pos": [
"salesperson_pos/static/src/**/*",
],
},
"license": "LGPL-3",
}
1 change: 1 addition & 0 deletions salesperson_pos/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import pos_order
7 changes: 7 additions & 0 deletions salesperson_pos/models/pos_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class PosOrder(models.Model):
_inherit = "pos.order"

salesperson_id = fields.Many2one("hr.employee", string="Salesperson", readonly=True)
13 changes: 13 additions & 0 deletions salesperson_pos/static/src/control_buttons/control_buttons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { patch } from "@web/core/utils/patch";
import { ControlButtons } from "@point_of_sale/app/screens/product_screen/control_buttons/control_buttons";
import { SelectSalesPersonButton } from "../salesperson_button/salesperson_button";

patch(ControlButtons, {
setup() {
super.setup();
},
components: {
...ControlButtons.components,
SelectSalesPersonButton,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="salesperson_pos.SelectSalesPersonButton" t-inherit="point_of_sale.ControlButtons" t-inherit-mode="extension">
<xpath expr="//button[contains(@class, 'btn') and contains(., 'Actions')]" position="before">
<SelectSalesPersonButton/>
</xpath>
</t>
</templates>
11 changes: 11 additions & 0 deletions salesperson_pos/static/src/pos_order/pos_order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { patch } from "@web/core/utils/patch";
import { PosOrder } from "@point_of_sale/app/models/pos_order";
patch(PosOrder.prototype, {
set_salesperson(salespersonID) {
try {
this.update({ salesperson_id: salespersonID });
} catch (error) {
console.log("error", error);
}
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Component, useState } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";
import { usePos } from "@point_of_sale/app/store/pos_hook";
import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
import { SalespersonListPopup } from "../salesperson_dialog/salesperson_dialog";

export class SelectSalesPersonButton extends Component {
static template = "salesperson_pos.SelectSalesPersonButton";
static components = { SalespersonListPopup };
static props = {};
setup() {
this.pos = usePos();
this.dialog = useService("dialog");
this.orm = useService("orm");
this.state = useState({
selectedSalesperson: null,
});
}

async SelectSalesPerson() {
const currentOrder = this.pos.get_order();

if (!currentOrder) {
return false;
}

try {
const salespersonList = await this.orm.searchRead(
"hr.employee",
[],
["id", "name", "work_email"]
);

if (salespersonList.length === 0) {
this.dialog.add(AlertDialog, {
title: "No Salesperson",
body: "No salesperson found in the system.",
});
return;
}
this.dialog.add(SalespersonListPopup, {
title: "Select Salesperson",
salespersonList,
confirm: (salesperson) => {
this.state.selectedSalesperson = salesperson;
if (salesperson) {
currentOrder.set_salesperson(salesperson?.id);
}
},
});
} catch (error) {
console.log(error);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="salesperson_pos.SelectSalesPersonButton">
<button class="set-partner btn btn-light btn-lg lh-lg text-truncate w-auto" t-on-click="SelectSalesPerson">
<t t-if="state.selectedSalesperson">
<div class="mt-2 text-muted">
<t t-esc="state.selectedSalesperson.name" />
</div>
</t>
<t t-else="">
Sales Person
</t>
</button>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<templates xml:space="preserve">
<t t-name="salesperson_pos.SalespersonListPopup" owl="1">
<Dialog bodyClass="'partner-list overflow-y-auto'" contentClass="'h-100'">
<t t-set-slot="header">
</t>
<table class="table table-hover">
<thead>
<tr>
<th class="py-2">Name</th>
<th class="py-2">Email</th>
</tr>
</thead>
<tbody>
<t t-foreach="props.salespersonList" t-as="salesperson" t-key="salesperson.id">
<tr class="partner-line partner-info" t-on-click="() => selectSalesperson(salesperson)">
<td class="text-truncate">
<t t-esc="salesperson.name" />
</td>
<td class="partner-line-email">
<i class="fa fa-fw fa-paper-plane-o me-2"/><t t-esc="salesperson.work_email" />
</td>
</tr>
</t>
</tbody>
</table>

<t t-set-slot="footer">
<div class="d-flex justify-content-start flex-wrap gap-2 w-100">
<button class="btn btn-secondary btn-lg lh-lg o-default-button" t-on-click="cancelSelection">Discard</button>
</div>
</t>
</Dialog>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component, useState } from "@odoo/owl";
import { Dialog } from "@web/core/dialog/dialog";
export class SalespersonListPopup extends Component {
static template = "salesperson_pos.SalespersonListPopup";
static props = {
title: String,
salespersonList: Array,
confirm: Function,
close: Function,
};

static components = { Dialog };
setup() {
this.selectSalesperson = this.selectSalesperson.bind(this);
}

selectSalesperson(salesperson) {
this.props.confirm(salesperson);
this.props.close();
}

cancelSelection() {
this.props.confirm(null);
this.props.close();
}
}
24 changes: 24 additions & 0 deletions salesperson_pos/views/pos_order_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_pos_order_tree_inherit" model="ir.ui.view">
<field name="name">pos.order.list.inherit</field>
<field name="model">pos.order</field>
<field name="inherit_id" ref="point_of_sale.view_pos_order_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="salesperson_id" />
</xpath>
</field>
</record>

<record id="view_pos_pos_form_inherit" model="ir.ui.view">
<field name="name">pos.order.form.inherit</field>
<field name="model">pos.order</field>
<field name="inherit_id" ref="point_of_sale.view_pos_pos_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='fiscal_position_id']" position="after">
<field name="salesperson_id" />
</xpath>
</field>
</record>
</odoo>