合并sf代码
This commit is contained in:
13
sf_machine_connect/static/src/css/many2one_field.scss
Normal file
13
sf_machine_connect/static/src/css/many2one_field.scss
Normal file
@@ -0,0 +1,13 @@
|
||||
.o_form_view:not(.o_field_highlight) {
|
||||
.o_field_many2one_selection {
|
||||
.o_external_button, .o_dropdown_button {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
&:hover, &:focus-within {
|
||||
.o_external_button, .o_dropdown_button {
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
sf_machine_connect/static/src/js/test.js
Normal file
82
sf_machine_connect/static/src/js/test.js
Normal file
@@ -0,0 +1,82 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { Dialog } from "@web/core/dialog/dialog";
|
||||
import { _lt } from "@web/core/l10n/translation";
|
||||
import { useChildRef, useOwnedDialogs, useService } from "@web/core/utils/hooks";
|
||||
import { sprintf } from "@web/core/utils/strings";
|
||||
import { isMobileOS } from "@web/core/browser/feature_detection";
|
||||
import * as BarcodeScanner from "@web/webclient/barcode/barcode_scanner";
|
||||
|
||||
const {xml, Component} = owl;
|
||||
import { standardFieldProps } from "@web/views/fields/standard_field_props";
|
||||
// Import the registry
|
||||
import {registry} from "@web/core/registry";
|
||||
|
||||
|
||||
export class CodeField extends Component {
|
||||
setup() {
|
||||
super.setup();
|
||||
}
|
||||
async onBarcodeBtnClick() {
|
||||
const barcode = await BarcodeScanner.scanBarcode();
|
||||
if (barcode) {
|
||||
await this.onBarcodeScanned(barcode);
|
||||
if ("vibrate" in browser.navigator) {
|
||||
browser.navigator.vibrate(100);
|
||||
}
|
||||
} else {
|
||||
this.notification.add(this.env._t("Please, scan again !"), {
|
||||
type: "warning",
|
||||
});
|
||||
}
|
||||
}
|
||||
async search(barcode) {
|
||||
const results = await this.orm.call("sf.tray", "name_search", [code], {
|
||||
name: barcode,
|
||||
args: this.getDomain(),
|
||||
operator: "ilike",
|
||||
limit: 2, // If one result we set directly and if more than one we use normal flow so no need to search more
|
||||
context: this.context,
|
||||
});
|
||||
return results.map((result) => {
|
||||
const [id, displayName] = result;
|
||||
return {
|
||||
id,
|
||||
name: displayName,
|
||||
};
|
||||
});
|
||||
}
|
||||
async onBarcodeScanned(barcode) {
|
||||
const results = await this.search(barcode);
|
||||
const records = results.filter((r) => !!r.id);
|
||||
if (records.length === 1) {
|
||||
this.update([{ id: records[0].id, name: records[0].name }]);
|
||||
} else {
|
||||
const searchInput = this.autocompleteContainerRef.el.querySelector("input");
|
||||
searchInput.value = barcode;
|
||||
searchInput.dispatchEvent(new Event("input"));
|
||||
if (this.env.isSmall) {
|
||||
searchInput.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CodeField.template = xml`
|
||||
<button
|
||||
t-on-click="onBarcodeBtnClick"
|
||||
type="button"
|
||||
class="btn ms-3 o_barcode"
|
||||
tabindex="-1"
|
||||
draggable="false"
|
||||
aria-label="Scan barcode"
|
||||
title="Scan barcode"
|
||||
data-tooltip="Scan barcode"
|
||||
/>
|
||||
`;
|
||||
// CodeField.template = 'sf_machine_connect.CodeField';
|
||||
CodeField.props = standardFieldProps;
|
||||
|
||||
// Add the field to the correct category
|
||||
registry.category("fields").add("code", CodeField);
|
||||
@@ -1,17 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="web.Many2OneField" owl="1">
|
||||
<button
|
||||
t-on-click="onBarcodeBtnClick"
|
||||
type="button"
|
||||
class="btn ms-3 o_barcode"
|
||||
tabindex="-1"
|
||||
draggable="false"
|
||||
aria-label="Scan barcode"
|
||||
title="Scan barcode"
|
||||
data-tooltip="Scan barcode"
|
||||
/>
|
||||
</t>
|
||||
<t t-name="sf_machine_connect.CodeField" owl="1">
|
||||
<div class="o_field_many2one_selection">
|
||||
<button
|
||||
t-on-click="onBarcodeBtnClick"
|
||||
type="button"
|
||||
class="btn ms-3 o_barcode"
|
||||
tabindex="-1"
|
||||
draggable="false"
|
||||
aria-label="Scan barcode"
|
||||
title="Scan barcode"
|
||||
data-tooltip="Scan barcode"
|
||||
/>
|
||||
</div>
|
||||
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
||||
Reference in New Issue
Block a user