refactor: improve cashier name resolution logic and add print-specific CSS overrides for POS receipts
This commit is contained in:
parent
b0c09d15f8
commit
60dca947e1
@ -94,5 +94,24 @@
|
|||||||
padding-bottom: 0 !important;
|
padding-bottom: 0 !important;
|
||||||
margin-bottom: 0 !important;
|
margin-bottom: 0 !important;
|
||||||
}
|
}
|
||||||
|
.pos-receipt-container {
|
||||||
|
padding-bottom: 0 !important;
|
||||||
|
margin-bottom: 0 !important;
|
||||||
|
height: auto !important;
|
||||||
|
}
|
||||||
|
body, html, #app {
|
||||||
|
height: auto !important;
|
||||||
|
min-height: auto !important;
|
||||||
|
padding-bottom: 0 !important;
|
||||||
|
margin-bottom: 0 !important;
|
||||||
|
}
|
||||||
|
iframe, .no-print, button, .pos-receipt-print, .pos-receipt-actions {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
.pos-receipt-print-canvas {
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
height: auto !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,24 +24,53 @@ patch(PosOrder.prototype, {
|
|||||||
getCashierName() {
|
getCashierName() {
|
||||||
const pos = this.pos || this.models?.env?.services?.pos;
|
const pos = this.pos || this.models?.env?.services?.pos;
|
||||||
let employee = this.employee_id || this.original_employee_id || this.user_id || null;
|
let employee = this.employee_id || this.original_employee_id || this.user_id || null;
|
||||||
|
let empId = null;
|
||||||
// If employee is just an ID/number, look up the record from the POS store models
|
|
||||||
if (employee && (typeof employee === 'number' || typeof employee === 'string')) {
|
// Extract ID if employee is a record or number
|
||||||
const empId = parseInt(employee);
|
if (employee) {
|
||||||
if (pos && pos.models && pos.models['hr.employee']) {
|
if (typeof employee === 'number' || typeof employee === 'string') {
|
||||||
employee = pos.models['hr.employee'].get(empId) || { name: `Employee ${empId}` };
|
empId = parseInt(employee);
|
||||||
} else if (pos && pos.employees) {
|
} else if (typeof employee === 'object') {
|
||||||
employee = pos.employees.find(e => e.id === empId) || { name: `Employee ${empId}` };
|
empId = employee.id;
|
||||||
} else {
|
}
|
||||||
employee = { name: `Employee ${empId}` };
|
}
|
||||||
|
|
||||||
|
// Look up employee record from models or list
|
||||||
|
let employeeRecord = null;
|
||||||
|
if (empId) {
|
||||||
|
if (pos && pos.models && pos.models['hr.employee']) {
|
||||||
|
employeeRecord = pos.models['hr.employee'].get(empId);
|
||||||
|
}
|
||||||
|
if (!employeeRecord && pos && pos.employees) {
|
||||||
|
employeeRecord = pos.employees.find(e => e.id === empId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to employee object itself if it has a name
|
||||||
|
let name = "";
|
||||||
|
if (employeeRecord && employeeRecord.name) {
|
||||||
|
name = employeeRecord.name;
|
||||||
|
} else if (employee && typeof employee === 'object' && employee.name) {
|
||||||
|
name = employee.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to user if no employee name found
|
||||||
|
if (!name && this.user_id) {
|
||||||
|
const userId = typeof this.user_id === 'object' ? this.user_id.id : parseInt(this.user_id);
|
||||||
|
if (pos && pos.models && pos.models['res.users']) {
|
||||||
|
const userRec = pos.models['res.users'].get(userId);
|
||||||
|
if (userRec && userRec.name) name = userRec.name;
|
||||||
|
}
|
||||||
|
if (!name && this.user_id.name) {
|
||||||
|
name = this.user_id.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = employee ? (employee.name || "") : "";
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
// Extract prefix if present (e.g. "Served by:", "Order Taker:")
|
|
||||||
|
// Format name to: First Name + Last Name
|
||||||
let temp = name.trim();
|
let temp = name.trim();
|
||||||
let prefix = "";
|
let prefix = "";
|
||||||
const prefixMatch = temp.match(/^(served\s+by:?|order\s+taker:?|kasir:?)\s*/i);
|
const prefixMatch = temp.match(/^(served\s+by:?|order\s+taker:?|kasir:?)\s*/i);
|
||||||
@ -49,10 +78,10 @@ patch(PosOrder.prototype, {
|
|||||||
prefix = prefixMatch[0];
|
prefix = prefixMatch[0];
|
||||||
temp = temp.substring(prefix.length).trim();
|
temp = temp.substring(prefix.length).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
const parts = temp.split(/\s+/);
|
const parts = temp.split(/\s+/);
|
||||||
if (parts.length <= 2) {
|
if (parts.length <= 2) {
|
||||||
return name;
|
return prefix + temp;
|
||||||
}
|
}
|
||||||
return prefix + parts[0] + " " + parts[parts.length - 1];
|
return prefix + parts[0] + " " + parts[parts.length - 1];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user