Skip to content

Commit c00439a

Browse files
committed
[ADD] server_action_mass_edit_onchange: extension to support playing onchange
1 parent a885871 commit c00439a

17 files changed

+767
-55
lines changed

server_action_mass_edit/wizard/mass_editing_wizard.py

+8-55
Original file line numberDiff line numberDiff line change
@@ -69,53 +69,6 @@ def default_get(self, fields):
6969

7070
return res
7171

72-
def onchange(self, values, field_names, fields_spec):
73-
first_call = not field_names
74-
if first_call:
75-
field_names = [fname for fname in values if fname != "id"]
76-
missing_names = [fname for fname in fields_spec if fname not in values]
77-
defaults = self.default_get(missing_names)
78-
for field_name in missing_names:
79-
values[field_name] = defaults.get(field_name, False)
80-
if field_name in defaults:
81-
field_names.append(field_name)
82-
83-
server_action_id = self.env.context.get("server_action_id")
84-
server_action = self.env["ir.actions.server"].sudo().browse(server_action_id)
85-
if not server_action:
86-
return super().onchange(values, field_names, fields_spec)
87-
dynamic_fields = {}
88-
89-
for line in server_action.mapped("mass_edit_line_ids"):
90-
values["selection__" + line.field_id.name] = "ignore"
91-
values[line.field_id.name] = False
92-
93-
dynamic_fields["selection__" + line.field_id.name] = fields.Selection(
94-
[], default="ignore"
95-
)
96-
97-
dynamic_fields[line.field_id.name] = fields.Text([()], default=False)
98-
99-
self._fields.update(dynamic_fields)
100-
101-
res = super().onchange(values, field_names, fields_spec)
102-
if not res["value"]:
103-
value = {key: value for key, value in values.items() if value is not False}
104-
res["value"] = value
105-
106-
for field in dynamic_fields:
107-
self._fields.pop(field)
108-
109-
view_temp = (
110-
self.env["ir.ui.view"]
111-
.sudo()
112-
.search([("name", "=", "Temporary Mass Editing Wizard")], limit=1)
113-
)
114-
if view_temp:
115-
view_temp.unlink()
116-
117-
return res
118-
11972
@api.model
12073
def _prepare_fields(self, line, field, field_info):
12174
result = {}
@@ -276,8 +229,7 @@ def _clean_check_company_field_domain(self, TargetModel, field, field_info):
276229
def create(self, vals_list):
277230
server_action_id = self.env.context.get("server_action_id")
278231
server_action = self.env["ir.actions.server"].sudo().browse(server_action_id)
279-
active_ids = self.env.context.get("active_ids", [])
280-
if server_action and active_ids:
232+
if server_action:
281233
for vals in vals_list:
282234
values = {}
283235
for key, val in vals.items():
@@ -308,14 +260,15 @@ def create(self, vals_list):
308260
values.update({split_key: vals.get(split_key, False)})
309261

310262
if values:
311-
for active_id in active_ids:
312-
self.env[server_action.model_id.model].browse(
313-
active_id
314-
).with_context(
315-
mass_edit=True,
316-
).write(values)
263+
self._exec_write(server_action, values)
317264
return super().create([{}])
318265

266+
def _exec_write(self, server_action, vals):
267+
active_ids = self.env.context.get("active_ids", [])
268+
model = self.env[server_action.model_id.model].with_context(mass_edit=True)
269+
records = model.browse(active_ids)
270+
records.write(vals)
271+
319272
def _prepare_create_values(self, vals_list):
320273
return vals_list
321274

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
================================
2+
Server Action Mass Edit Onchange
3+
================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:d4e832e364fe018a3d6bc0ea28ee7e5436ba8799a7741c7e68c4b26ed875c3db
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github
20+
:target: https://github.com/OCA/server-ux/tree/18.0/server_action_mass_edit_onchange
21+
:alt: OCA/server-ux
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/server-ux-18-0/server-ux-18-0-server_action_mass_edit_onchange
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-ux&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module is an extension of module Mass Editing to support playing
32+
onchange before writing.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Usage
40+
=====
41+
42+
43+
44+
Bug Tracker
45+
===========
46+
47+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/issues>`_.
48+
In case of trouble, please check there if your issue has already been reported.
49+
If you spotted it first, help us to smash it by providing a detailed and welcomed
50+
`feedback <https://github.com/OCA/server-ux/issues/new?body=module:%20server_action_mass_edit_onchange%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
51+
52+
Do not contact contributors directly about support or help with technical issues.
53+
54+
Credits
55+
=======
56+
57+
Authors
58+
-------
59+
60+
* Camptocamp
61+
62+
Contributors
63+
------------
64+
65+
- Akim Juillerat akim.juillerat@camptocamp.com
66+
67+
- Tris Doan <tridm@trobz.com>
68+
69+
Maintainers
70+
-----------
71+
72+
This module is maintained by the OCA.
73+
74+
.. image:: https://odoo-community.org/logo.png
75+
:alt: Odoo Community Association
76+
:target: https://odoo-community.org
77+
78+
OCA, or the Odoo Community Association, is a nonprofit organization whose
79+
mission is to support the collaborative development of Odoo features and
80+
promote its widespread use.
81+
82+
This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/18.0/server_action_mass_edit_onchange>`_ project on GitHub.
83+
84+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import wizard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2024 Camptocamp
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Server Action Mass Edit Onchange",
6+
"summary": """Extension of server_action_mass_edit""",
7+
"version": "18.0.1.0.0",
8+
"license": "AGPL-3",
9+
"author": "Camptocamp, Odoo Community Association (OCA)",
10+
"website": "https://github.com/OCA/server-ux",
11+
"depends": ["server_action_mass_edit", "onchange_helper"],
12+
"data": [
13+
"views/ir_actions_server.xml",
14+
],
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import ir_actions_server_mass_edit_line
2+
from . import ir_actions_server
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 Camptocamp
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class IrActionsServer(models.Model):
8+
_inherit = "ir.actions.server"
9+
10+
mass_edit_play_onchanges = fields.Json(
11+
string="Play onchanges from lines",
12+
compute="_compute_mass_edit_play_onchanges",
13+
)
14+
15+
@api.depends("mass_edit_line_ids.apply_onchanges")
16+
def _compute_mass_edit_play_onchanges(self):
17+
for record in self:
18+
record.mass_edit_play_onchanges = {
19+
line.field_id.name: line.apply_onchanges
20+
for line in record.mass_edit_line_ids
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2024 Camptocamp
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class IrActionsServerMassEditLine(models.Model):
8+
_inherit = "ir.actions.server.mass.edit.line"
9+
10+
apply_onchanges = fields.Boolean(help="Play field onchanges before writing value")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* Akim Juillerat <akim.juillerat@camptocamp.com>
2+
- Tris Doan \<<tridm@trobz.com>\>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module is an extension of module Mass Editing to support playing onchange before writing.

server_action_mass_edit_onchange/readme/USAGE.md

Whitespace-only changes.

0 commit comments

Comments
 (0)