Skip to content

Commit

Permalink
[IMP] stock_barcodes: Avoid NewId environment calling method on_barco…
Browse files Browse the repository at this point in the history
…de_scanned instead of onchange

Onchange limits documented in method:
It is not possible for a ``one2many`` or ``many2many`` field to modify
itself via onchange. This is a webclient limitation - see `#2693 <https://github.com/odoo/odoo/issues/2693>`_.

This causes refresh problems when creating or modifying records, and it is also not ideal to create records in "onchange mode"

Backported from 725221c#diff-dcdad8cf227ac6f9016ad537c1aca9cacab5576bfd5e246507cc5e096a238008L497
  • Loading branch information
CarlosRoca13 committed Dec 10, 2024
1 parent 413b1e1 commit 57e1685
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions stock_barcodes/static/src/js/form_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ odoo.define("stock_barcodes.FormView", function (require) {
"use strict";

var FormView = require("web.FormView");
var FormController = require("web.FormController");

FormView.include({
/**
Expand All @@ -21,4 +22,14 @@ odoo.define("stock_barcodes.FormView", function (require) {
return params;
},
});

FormController.include({
_barcodeActiveScanned: function () {
this._super(...arguments);
var record = this.model.get(this.handle);
if (record.model.includes("wiz.stock.barcodes.read")) {
$("#dummy_on_barcode_scanned").click();
}
},
});
});
5 changes: 4 additions & 1 deletion stock_barcodes/wizard/stock_barcodes_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ def _clean_barcode_scanned(self, barcode):

def on_barcode_scanned(self, barcode):
self.barcode = self._clean_barcode_scanned(barcode)
self.process_barcode(barcode)

def dummy_on_barcode_scanned(self):
"""To avoid execute operations in onchange environment"""
self.process_barcode(self.barcode)

def check_location_contidion(self):
if not self.location_id:
Expand Down
11 changes: 11 additions & 0 deletions stock_barcodes/wizard/stock_barcodes_read_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@
</div>
<!-- HACK: To avoid inheritance crash -->
<button name="action_manual_entry" invisible="1" />
<!-- Hide button in view to allow do onclick in JS. Use d-none instead of
invisible attribute to be allocated by jquery selector
-->
<button
name="dummy_on_barcode_scanned"
id="dummy_on_barcode_scanned"
type="object"
data-hotkey="99"
invisible="0"
class="d-none"
/>
<!-- // -->
<button
name="action_clean_values"
Expand Down

0 comments on commit 57e1685

Please sign in to comment.