| 1 |
import { Transition } from "@web/core/transition"; |
| 2 |
import { MainComponentsContainer } from "@web/core/main_components_container"; |
| 3 |
import { Navbar } from "@point_of_sale/app/components/navbar/navbar"; |
| 4 |
import { usePos } from "@point_of_sale/app/hooks/pos_hook"; |
| 5 |
import { reactive, Component, onMounted, onWillStart } from "@odoo/owl"; |
| 6 |
import { effect } from "@web/core/utils/reactive"; |
| 7 |
import { batched } from "@web/core/utils/timing"; |
| 8 |
import { useOwnDebugContext } from "@web/core/debug/debug_context"; |
| 9 |
import { CustomerDisplayPosAdapter } from "@point_of_sale/app/customer_display/customer_display_adapter"; |
| 10 |
import { useIdleTimer } from "./utils/use_idle_timer"; |
| 11 |
import useTours from "./hooks/use_tours"; |
| 12 |
import { init as initDebugFormatters } from "./utils/debug-formatter"; |
| 13 |
|
| 14 |
/** |
| 15 |
* Chrome is the root component of the PoS App. |
| 16 |
*/ |
| 17 |
export class Chrome extends Component { |
| 18 |
static template = "point_of_sale.Chrome"; |
| 19 |
static components = { Transition, MainComponentsContainer, Navbar }; |
| 20 |
static props = { disableLoader: Function }; |
| 21 |
setup() { |
| 22 |
this.pos = usePos(); |
| 23 |
useIdleTimer(this.pos.idleTimeout, (ev) => { |
| 24 |
const stopEventPropagation = ["mousedown", "click", "keypress"]; |
| 25 |
if (stopEventPropagation.includes(ev.type)) { |
| 26 |
ev.stopPropagation(); |
| 27 |
} |
| 28 |
this.pos.navigateToFirstPage(); |
| 29 |
return false; |
| 30 |
}); |
| 31 |
if (this.pos.router.state.current === "SaverScreen") { |
| 32 |
this.pos.navigateToFirstPage(); |
| 33 |
} |
| 34 |
|
| 35 |
const reactivePos = reactive(this.pos); |
| 36 |
window.posmodel = reactivePos; |
| 37 |
useOwnDebugContext(); |
| 38 |
if (this.env.debug) { |
| 39 |
initDebugFormatters(); |
| 40 |
} |
| 41 |
|
| 42 |
if (odoo.use_pos_fake_tours) { |
| 43 |
window.pos_fake_tour = useTours(); |
| 44 |
} |
| 45 |
|
| 46 |
if (this.pos.config.iface_big_scrollbars) { |
| 47 |
const body = document.getElementsByTagName("body")[0]; |
| 48 |
body.classList.add("big-scrollbars"); |
| 49 |
} |
| 50 |
|
| 51 |
onWillStart(this.pos._loadFonts); |
| 52 |
onMounted(this.props.disableLoader); |
| 53 |
effect( |
| 54 |
batched(({ selectedOrder, scale }) => { |
| 55 |
if (selectedOrder) { |
| 56 |
const scaleData = scale.product |
| 57 |
? { |
| 58 |
product: { ...scale.product }, |
| 59 |
unitPrice: scale.unitPriceString, |
| 60 |
totalPrice: scale.totalPriceString, |
| 61 |
netWeight: scale.netWeightString, |
| 62 |
grossWeight: scale.grossWeightString, |
| 63 |
tare: scale.tareWeightString, |
| 64 |
} |
| 65 |
: null; |
| 66 |
this.sendOrderToCustomerDisplay(selectedOrder, scaleData); |
| 67 |
} |
| 68 |
}), |
| 69 |
[this.pos] |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
sendOrderToCustomerDisplay(selectedOrder, scaleData) { |
| 74 |
const adapter = new CustomerDisplayPosAdapter(); |
| 75 |
adapter.formatOrderData(selectedOrder); |
| 76 |
adapter.data.scaleData = scaleData; |
| 77 |
adapter.dispatch(this.pos); |
| 78 |
} |
| 79 |
|
| 80 |
// GETTERS // |
| 81 |
get showCashMoveButton() { |
| 82 |
return Boolean(this.pos.config.cash_control); |
| 83 |
} |
| 84 |
} |