| 1 |
import { Component, onMounted, onWillUnmount, useState } from "@odoo/owl"; |
| 2 |
import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; |
| 3 |
import { Dialog } from "@web/core/dialog/dialog"; |
| 4 |
import { useService } from "@web/core/utils/hooks"; |
| 5 |
import { _t } from "@web/core/l10n/translation"; |
| 6 |
|
| 7 |
export class ScaleScreen extends Component { |
| 8 |
static template = "point_of_sale.ScaleScreen"; |
| 9 |
static components = { Dialog }; |
| 10 |
static props = { |
| 11 |
getPayload: Function, |
| 12 |
close: Function, |
| 13 |
}; |
| 14 |
|
| 15 |
setup() { |
| 16 |
this.scale = useState(useService("pos_scale")); |
| 17 |
this.dialog = useService("dialog"); |
| 18 |
onMounted(() => this.scale.start(this.onError.bind(this))); |
| 19 |
onWillUnmount(() => this.scale.reset()); |
| 20 |
} |
| 21 |
|
| 22 |
confirm() { |
| 23 |
this.props.getPayload(this.scale.confirmWeight()); |
| 24 |
this.props.close(); |
| 25 |
} |
| 26 |
|
| 27 |
onError(message) { |
| 28 |
this.props.getPayload(null); |
| 29 |
this.dialog.add( |
| 30 |
AlertDialog, |
| 31 |
{ |
| 32 |
title: _t("Scale error"), |
| 33 |
body: message, |
| 34 |
}, |
| 35 |
{ onClose: this.props.close } |
| 36 |
); |
| 37 |
} |
| 38 |
} |