Skip to content

Commit

Permalink
[IMP] depend on onchange_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierrick Brun committed Jan 14, 2021
1 parent 0c7d41b commit db0373d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 45 deletions.
4 changes: 0 additions & 4 deletions base_product_mass_addition/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ Example implementations:
- purchase_quick
- stock_picking_quick

This module does not depend on onchange_helper but it is faster when installed.
If not, it will us Form emulation from backend.


**Table of contents**

.. contents::
Expand Down
2 changes: 1 addition & 1 deletion base_product_mass_addition/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"website": "https://github.com/OCA/product-attribute",
"license": "AGPL-3",
"category": "Product",
"depends": ["stock"],
"depends": ["stock", "onchange_helper"],
"data": ["views/product_view.xml"],
"installable": True,
}
44 changes: 9 additions & 35 deletions base_product_mass_addition/models/product_mass_addition.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,13 @@ def _complete_quick_line_vals(self, vals, lines_key=""):
if not lines_key:
raise NotImplementedError
init_keys = ["product_id"]
init_vals = {key: val for key, val in vals.items() if key in init_keys}
update_vals = {key: val for key, val in vals.items() if key not in init_keys}
# Try to use onchange_helper if installed
try:
lines = getattr(self, lines_key)
if "id" in vals:
line = lines.filtered(lambda x: x.id == vals["id"])
return line.play_onchanges(update_vals, list(update_vals.keys()))
else:
line = lines
if len(lines) > 1:
line = lines[0]
return line.play_onchanges(vals, list(vals.keys()))
except AttributeError as e:
from odoo.tests.common import Form

_logger.warning(
"onchange_helper not installed, "
"you may experience slow inputs: {}".format(e.args)
)
form_parent = Form(self)
form_line = False
if vals.get("id"):
for index, line in enumerate(self[lines_key]):
if line.id == vals.get("id"):
form_line = getattr(form_parent, lines_key).edit(index)
del vals["id"]
break
if not form_line:
form_line = getattr(form_parent, lines_key).new()
form_line._values.update(init_vals)
form_line._perform_onchange(init_keys)

form_line._values.update(update_vals)
form_line._perform_onchange(list(update_vals.keys()))
return form_line._values
lines = getattr(self, lines_key)
if "id" in vals:
line = lines.filtered(lambda x: x.id == vals["id"])
return line.play_onchanges(update_vals, list(update_vals.keys()))
else:
line = lines
if len(lines) > 1:
line = lines[0]
return line.play_onchanges(vals, list(vals.keys()))
6 changes: 1 addition & 5 deletions base_product_mass_addition/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
The module uses Form emulation from backend.
Once onchange_helper is stabilized, we should switch to it
because it is more robust and has better perfs.

Also adding new implementations would be great:
Adding new implementations would be great:
on sale.order or on stock.picking.batch for instance.

0 comments on commit db0373d

Please sign in to comment.