Skip to content

Commit 93f4f84

Browse files
committed
[ADD] pos_salesperson: add salesperson dropdown and order field
Before: -The POS billing screen did not have any option to select a salesperson. -Salesperson data was not captured or displayed in POS order records. After: -Introduced a dropdown menu in the POS billing screen to select a salesperson (employee) from the available list. -Captured the selected salesperson in each POS order. -Displayed the salesperson field in both the POS order form view and list view. Impact: -Allows tracking of which employee handled each sale. Task: 4968061
1 parent fbf9ee9 commit 93f4f84

File tree

10 files changed

+126
-0
lines changed

10 files changed

+126
-0
lines changed

pos_salesperson/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import models

pos_salesperson/__manifest__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "Pos Salesperson",
3+
"depends": ["pos_hr"],
4+
"version": "0.1",
5+
"license": "LGPL-3",
6+
"installable": True,
7+
"data": ["views/pos_order_views.xml"],
8+
"assets": {
9+
"point_of_sale._assets_pos": [
10+
"pos_salesperson/static/src/app/**/*"
11+
]
12+
}
13+
}

pos_salesperson/models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import pos_order
4+
from . import pos_session

pos_salesperson/models/pos_order.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from odoo import models, fields
2+
3+
4+
class PosOrder(models.Model):
5+
_inherit = "pos.order"
6+
7+
salesperson_id = fields.Many2one("hr.employee", string="Salesperson")

pos_salesperson/models/pos_session.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from odoo import models
2+
3+
4+
class PosSession(models.Model):
5+
_inherit = "pos.session"
6+
7+
def _load_pos_data_models(self, config_id):
8+
models = super()._load_pos_data_models(config_id)
9+
models += ["hr.employee"]
10+
return models
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { patch } from "@web/core/utils/patch";
2+
import { ControlButtons } from "@point_of_sale/app/screens/product_screen/control_buttons/control_buttons";
3+
import { SalespersonButton } from "@pos_salesperson/app/components/salesperson_button/salesperson_button";
4+
5+
6+
patch(ControlButtons,{
7+
components:{
8+
...ControlButtons.components,
9+
SalespersonButton
10+
}
11+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<templates id="template" xml:space="preserve">
2+
<t t-name="pos_salesperson.SalesPersonButton" t-inherit="point_of_sale.ControlButtons" t-inherit-mode="extension">
3+
<xpath expr="//OrderlineNoteButton" position="after">
4+
<SalespersonButton/>
5+
</xpath>
6+
</t>
7+
</templates>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { useService } from "@web/core/utils/hooks";
2+
import { _t } from "@web/core/l10n/translation";
3+
import { usePos } from "@point_of_sale/app/store/pos_hook";
4+
import { makeAwaitable } from "@point_of_sale/app/store/make_awaitable_dialog";
5+
import { SelectionPopup } from "@point_of_sale/app/utils/input_popups/selection_popup";
6+
import { Component, useState } from "@odoo/owl";
7+
8+
9+
export class SalespersonButton extends Component{
10+
static template = "pos_salesperson.SalespersonButton";
11+
12+
setup(){
13+
this.state = useState({selectedSalesPerson:""})
14+
this.dialog = useService("dialog");
15+
this.pos = usePos();
16+
}
17+
18+
async chooseSalesPerson(){
19+
const order = this.pos.get_order();
20+
const allSalesPersonList = this.pos.models?.["hr.employee"];
21+
22+
let salesPersonList = allSalesPersonList.map((s)=>({
23+
id:s.id,
24+
item:s,
25+
label:s.name,
26+
isSelected:false
27+
}))
28+
29+
const selectedSalesPerson = await makeAwaitable(this.dialog, SelectionPopup, {
30+
list: salesPersonList,
31+
title: _t("Select the salesperson"),
32+
});
33+
34+
if(selectedSalesPerson){
35+
this.state.selectedSalesPerson = selectedSalesPerson;
36+
order.salesperson_id = selectedSalesPerson;
37+
}
38+
}
39+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<templates id="template" xml:space="preserve">
2+
<t t-name="pos_salesperson.SalespersonButton">
3+
<button class="btn btn-light btn-lg lh-lg text-truncate w-auto" t-on-click="chooseSalesPerson">
4+
<t t-if="state.selectedSalesPerson">
5+
<div class="text-truncate text-action" t-esc="state.selectedSalesPerson.name"/>
6+
</t>
7+
<t t-else="">SalesPerson</t>
8+
</button>
9+
</t>
10+
</templates>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<odoo>
2+
<record id="pos_form_view_salesperson" model="ir.ui.view">
3+
<field name="name">pos.order.form</field>
4+
<field name="model">pos.order</field>
5+
<field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/>
6+
<field name="arch" type="xml">
7+
<xpath expr="//group[@name='order_fields']" position="inside">
8+
<field name="salesperson_id" />
9+
</xpath>
10+
</field>
11+
</record>
12+
<record id="pos_list_view_salesperson" model="ir.ui.view">
13+
<field name="name">pos.order.list</field>
14+
<field name="model">pos.order</field>
15+
<field name="inherit_id" ref="point_of_sale.view_pos_order_tree"/>
16+
<field name="arch" type="xml">
17+
<xpath expr="//field[@name='partner_id']" position="after">
18+
<field name="salesperson_id" />
19+
</xpath>
20+
</field>
21+
</record>
22+
</odoo>

0 commit comments

Comments
 (0)