Skip to content

Commit

Permalink
[IMP] change tare direction
Browse files Browse the repository at this point in the history
TT47127
  • Loading branch information
chienandalu committed May 31, 2024
1 parent 0ea762d commit 62ad568
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/** @odoo-module **/
import {_t, qweb} from "web.core";
import Dialog from "web.Dialog";
import {RemoteMeasure} from "@web_widget_remote_measure/js/remote_measure_widget.esm";
import fieldRegistry from "web.field_registry";
import {qweb} from "web.core";
import session from "web.session";

export const RemoteMeasureForm = RemoteMeasure.extend({
_template: "weigh_remote_measure.RemoteMeasureForm",
Expand All @@ -21,6 +23,7 @@ export const RemoteMeasureForm = RemoteMeasure.extend({
"focusin div[name='manual_tare'] input": "_onFocusInputTare",
"change div[name='manual_tare'] input": "_onChangeInputTare",
"click div[name='manual_tare'] button": "_onStepTare",
"click div[name='device_selector']": "_onDeviceSelector",
}
),
/**
Expand Down Expand Up @@ -50,7 +53,10 @@ export const RemoteMeasureForm = RemoteMeasure.extend({
*/
_renderEdit() {
const def = this._super(...arguments);
if (!this.remote_device_data) {
if (
!this.remote_device_data ||
this.uom_category !== this.device_uom_category
) {
return def;
}
this.amount = this.input_val;
Expand All @@ -67,6 +73,7 @@ export const RemoteMeasureForm = RemoteMeasure.extend({
this.$el.find("btn[data-tare]").on("click", this._onClickTare.bind(this));
this.$tare_amount = this.$el.find("span[name='tare_amount']");
this.$real_amount = this.$el.find("span[name='real_amount']");
this.$device_selector = this.$el.find("div[name='device_selector']");
const $weight_control = this.$el.find("div[name='weight_control']");
// Tweak the base widget
this.$start_measure.appendTo($weight_control);
Expand Down Expand Up @@ -115,9 +122,56 @@ export const RemoteMeasureForm = RemoteMeasure.extend({
_onClickTare(ev) {
ev.preventDefault();
const tare = parseFloat(ev.currentTarget.dataset.tare);
this.tare = Math.max(0, this.tare + tare);
// This.tare = Math.max(0, this.tare + tare);
this.tare += tare;
this._updateTare();
},
/**
* Simple decive selector, that allows a user to easily swith devices
* @param {Event} ev
*/
_onDeviceSelector(ev) {
ev.preventDefault();
this.measure_stop();
this._rpc({
model: "remote.measure.device",
method: "search_read",
args: [],
}).then((devices) => {
const buttons = devices.map((device) => {
return {
text: device.name,
classes: "btn-dark btn-lg btn-block mb-2",
close: true,
click: () => {
this._rpc({
model: "res.users",
method: "write",
args: [
[session.uid],
{remote_measure_device_id: device.id},
],
}).then(() => {
this.trigger_up("reload");
});
},
};
});
buttons.push({
text: _t("Discard"),
classes: "btn-lg btn-light btn-block",
close: true,
});
new Dialog(this, {
$content: $("<h4>", {
text: _t("Choose a device:"),
}),
size: "small",
buttons: buttons,
renderHeader: false,
}).open();
});
},
/**
* Upgrade the measure counter
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
.o_input_weight {
width: fit-content;
}
div[name="device_selector"] {
cursor: pointer;
}
}
span.o_field_remote_device_start,
span.o_field_remote_device_stop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
class="font-weight-bold text-success"
t-out="amount"
/> <span t-out="uom_name" class="text-success" />
<div class="d-inline float-right text-dark" title="Device info">
<div
class="d-inline float-right text-dark"
title="Device info"
name="device_selector"
role="button"
>
<i class="fa fa-thermometer" /> <span t-out="device_name" />
</div>
</div>
Expand All @@ -37,7 +42,7 @@
<t t-set="color" t-value="colors[tare_index % colors.length]" />
<btn
t-attf-class="btn btn-outline-{{color}}"
t-attf-data-tare="-{{tare.tare}}"
t-att-data-tare="tare.tare"
>
-
</btn>
Expand All @@ -49,7 +54,7 @@
</btn>
<btn
t-attf-class="btn btn-outline-{{color}}"
t-att-data-tare="tare.tare"
t-attf-data-tare="-{{tare.tare}}"
>
+
</btn>
Expand All @@ -66,12 +71,11 @@
aria-label="Minus"
title="Minus"
type="button"
data-mode="minus"
data-mode="plus"
/>
</div>
<input
type="number"
min="0"
step="0.1"
inputmode="decimal"
class="form-control text-center"
Expand All @@ -83,7 +87,7 @@
aria-label="Plus"
title="Plus"
type="button"
data-mode="plus"
data-mode="minus"
/>
<span class="input-group-text" t-out="uom_name" />
</div>
Expand Down
11 changes: 9 additions & 2 deletions stock_weighing_remote_measure/wizards/weighing_wizard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
from odoo import api, fields, models


class WeighingWizard(models.TransientModel):
Expand All @@ -11,4 +11,11 @@ class WeighingWizard(models.TransientModel):
default=lambda self: self.env.user.remote_measure_device_id,
readonly=True,
)
uom_id = fields.Many2one(comodel_name="uom.uom", related="measure_device_id.uom_id")
uom_id = fields.Many2one(comodel_name="uom.uom", compute="_compute_uom_id")

@api.depends("product_id", "selected_move_line_id")
def _compute_uom_id(self):
for wiz in self:
wiz.uom_id = (
wiz.product_id.uom_id or wiz.selected_move_line_id.product_uom_id
)

0 comments on commit 62ad568

Please sign in to comment.