Skip to content

Commit ea9c6a0

Browse files
committed
[ADD] salesperson_in_pos: adding salesperson button in POS
- inherit the pos.order model to use the app point_of_sale in form and list view of orders. - Also add salesperson button in pos dashboard
1 parent fbf9ee9 commit ea9c6a0

File tree

11 files changed

+159
-0
lines changed

11 files changed

+159
-0
lines changed

salesperson_in_pos/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

salesperson_in_pos/__manifest__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
'name': "Salesperson_Pos",
3+
'version': "1.0",
4+
'summary': "Add salesperson field in POS app",
5+
'description': """
6+
This module will add a button in the POS dashboard to assign a salesperson to respective orders.
7+
""",
8+
'author': "priyansi borda",
9+
'depends': ['base', 'point_of_sale', 'hr'],
10+
'data': [
11+
"views/pos_view.xml",
12+
],
13+
'assets': {
14+
'point_of_sale._assets_pos': [
15+
'salesperson_in_pos/static/src/**/*',
16+
],
17+
},
18+
'application': False,
19+
'installable': True,
20+
'license': 'LGPL-3',
21+
}

salesperson_in_pos/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import pos_order
2+
from . import pos_session
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from odoo import models, fields
2+
3+
4+
class PosOrder(models.Model):
5+
_inherit = "pos.order"
6+
salesperson_id = fields.Many2one('hr.employee', string='Salesperson', help='Salesperson who created the order')
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+
data = super()._load_pos_data_models(config_id)
9+
data.append("hr.employee")
10+
return data
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 { SelectSalespersonButton } from "@salesperson_in_pos/salesperson_button/salesperson_button";
4+
5+
patch(ControlButtons, {
6+
components: {
7+
...ControlButtons.components,
8+
SelectSalespersonButton,
9+
},
10+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates id="template" xml:space="preserve">
3+
<t t-name="pos_salesperson_assignment.ControlButtons" t-inherit="point_of_sale.ControlButtons" t-inherit-mode="extension">
4+
<xpath expr="//button[@t-if='!props.showRemainingButtons and !ui.isSmall and props.onClickMore']" position="before">
5+
<SelectSalespersonButton/>
6+
</xpath>
7+
</t>
8+
</templates>
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 { PosOrder } from "@point_of_sale/app/models/pos_order";
3+
4+
patch(PosOrder.prototype, {
5+
setSalesperson(sales_person) {
6+
this.update({ salesperson: sales_person });
7+
},
8+
getSalesperson(){
9+
return this.salesperson;
10+
},
11+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Component } from "@odoo/owl";
2+
import { usePos } from "@point_of_sale/app/store/pos_hook";
3+
import { useService } from "@web/core/utils/hooks";
4+
import { _t } from "@web/core/l10n/translation";
5+
import { makeAwaitable } from "@point_of_sale/app/store/make_awaitable_dialog";
6+
import { SelectionPopup } from "@point_of_sale/app/utils/input_popups/selection_popup";
7+
8+
export class SelectSalespersonButton extends Component {
9+
static template = "point_of_sale.SelectSalespersonButton";
10+
static props = ["salesperson?"]
11+
setup() {
12+
this.pos = usePos();
13+
this.dialog = useService("dialog");
14+
const currentOrder = this.pos.get_order();
15+
if (currentOrder) {
16+
const currentSalesperson = currentOrder.getSalesperson();
17+
if (currentSalesperson) {
18+
this.props.salesperson = currentSalesperson;
19+
}
20+
else{
21+
return;
22+
}
23+
}
24+
}
25+
async selectSalesperson(){
26+
const currentOrder = this.pos.get_order();
27+
if (!currentOrder) {
28+
return false;
29+
}
30+
const salesperson_list = this.pos.models['hr.employee'].map((sp) => {
31+
return {
32+
id: sp.id,
33+
item: sp,
34+
label: sp.name,
35+
isSelected: currentOrder.getSalesperson()?.id === sp.id || false
36+
}
37+
});
38+
console.log(this.pos.models['hr.employee'].getAll());
39+
const selectedSalesperson = await makeAwaitable(this.dialog, SelectionPopup, {
40+
title: _t("Select salesperson"),
41+
list: salesperson_list,
42+
});
43+
44+
if (selectedSalesperson) {
45+
if (currentOrder.getSalesperson()?.id === selectedSalesperson.id) {
46+
this.props.salesperson = null;
47+
currentOrder.setSalesperson("");
48+
}
49+
else {
50+
this.props.salesperson = selectedSalesperson;
51+
currentOrder.setSalesperson(selectedSalesperson);
52+
}
53+
}
54+
else{
55+
return;
56+
}
57+
}
58+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<templates id="temnplate" xml:space="preserve">
2+
<t t-name="point_of_sale.SelectSalespersonButton">
3+
<button class="btn btn-light btn-lg lh-lg text-truncate w-auto" t-on-click="() => this.selectSalesperson()">
4+
<div t-if="props.salesperson" t-esc="props.salesperson.name" class="text-truncate text-action"></div>
5+
<div t-else="">
6+
Salesperson
7+
</div>
8+
</button>
9+
</t>
10+
</templates>

0 commit comments

Comments
 (0)