Skip to content

Commit d29e26e

Browse files
committed
[FIX] Fix access right issues when using actions
1 parent c83eb45 commit d29e26e

File tree

10 files changed

+43
-66
lines changed

10 files changed

+43
-66
lines changed

account_invoice_download/models/account_invoice_download_config.py

+9-16
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,8 @@ def run_button(self):
160160
credentials = self.prepare_credentials()
161161
invoice_ids, log_id = self.run(credentials)
162162
if invoice_ids:
163-
action = (
164-
self.env.ref("account.action_move_in_invoice_type").sudo().read()[0]
165-
)
163+
xmlid = "account.action_move_in_invoice_type"
164+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
166165
action.update(
167166
{
168167
"views": False,
@@ -171,13 +170,8 @@ def run_button(self):
171170
}
172171
)
173172
else:
174-
action = (
175-
self.env.ref(
176-
"account_invoice_download.account_invoice_download_log_action"
177-
)
178-
.sudo()
179-
.read()[0]
180-
)
173+
xmlid = "account_invoice_download.account_invoice_download_log_action"
174+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
181175
action.update(
182176
{
183177
"res_id": log_id,
@@ -187,12 +181,11 @@ def run_button(self):
187181
)
188182
return action
189183
else:
190-
credentials_wiz_action = (
191-
self.env.ref(
192-
"account_invoice_download.account_invoice_download_credentials_action"
193-
)
194-
.sudo()
195-
.read()[0]
184+
xmlid = (
185+
"account_invoice_download.account_invoice_download_credentials_action"
186+
)
187+
credentials_wiz_action = self.env["ir.actions.act_window"]._for_xml_id(
188+
xmlid
196189
)
197190
return credentials_wiz_action
198191

account_invoice_download/wizard/account_invoice_download_credentials.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ def run(self):
7676
"""The real work is made in create(), not here!"""
7777
self.ensure_one()
7878
if self.invoice_ids_str:
79-
action = (
80-
self.env.ref("account.action_move_in_invoice_type").sudo().read()[0]
81-
)
79+
xmlid = "account.action_move_in_invoice_type"
80+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
8281
action.update(
8382
{
8483
"views": False,
@@ -87,13 +86,8 @@ def run(self):
8786
}
8887
)
8988
else:
90-
action = (
91-
self.env.ref(
92-
"account_invoice_download.account_invoice_download_log_action"
93-
)
94-
.sudo()
95-
.read()[0]
96-
)
89+
xmlid = "account_invoice_download.account_invoice_download_log_action"
90+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
9791
action.update(
9892
{
9993
"res_id": self.log_id.id,

account_invoice_download_ovh/wizard/ovh_api_credentials.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ def default_get(self, fields_list):
6363

6464
def action_continue_wizard(self):
6565
self.ensure_one()
66-
action = (
67-
self.env.ref("account_invoice_download_ovh.ovh_api_credentials_action")
68-
.sudo()
69-
.read()[0]
70-
)
66+
xmlid = "account_invoice_download_ovh.ovh_api_credentials_action"
67+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
7168
action["res_id"] = self.id
7269
return action
7370

account_invoice_import/models/res_partner.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ def _compute_invoice_import_count(self):
3434

3535
def show_account_invoice_import_config(self):
3636
self.ensure_one()
37-
action = (
38-
self.env.ref("account_invoice_import.account_invoice_import_config_action")
39-
.sudo()
40-
.read()[0]
41-
)
37+
xmlid = "account_invoice_import.account_invoice_import_config_action"
38+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
4239
action["context"] = {
4340
"default_name": self.name,
4441
"default_partner_id": self.id,

account_invoice_import/wizard/account_invoice_import.py

+10-17
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,8 @@ def goto_partner_not_found(self, parsed_inv, error_message):
561561
if country:
562562
vals["partner_country_id"] = country.id
563563
self.write(vals)
564-
action = (
565-
self.env.ref("account_invoice_import.account_invoice_import_action")
566-
.sudo()
567-
.read()[0]
568-
)
564+
xmlid = "account_invoice_import.account_invoice_import_action"
565+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
569566
action["res_id"] = self.id
570567
return action
571568

@@ -747,11 +744,8 @@ def import_invoice(self):
747744

748745
if not wiz_vals.get("import_config_id"):
749746
wiz_vals["state"] = "config"
750-
action = (
751-
self.env.ref("account_invoice_import.account_invoice_import_action")
752-
.sudo()
753-
.read()[0]
754-
)
747+
xmlid = "account_invoice_import.account_invoice_import_action"
748+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
755749
action["res_id"] = self.id
756750
else:
757751
draft_same_supplier_invs = amo.search(
@@ -766,11 +760,8 @@ def import_invoice(self):
766760
wiz_vals["state"] = "update"
767761
if len(draft_same_supplier_invs) == 1:
768762
wiz_vals["invoice_id"] = draft_same_supplier_invs[0].id
769-
action = (
770-
self.env.ref("account_invoice_import.account_invoice_import_action")
771-
.sudo()
772-
.read()[0]
773-
)
763+
xmlid = "account_invoice_import.account_invoice_import_action"
764+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
774765
action["res_id"] = self.id
775766
else:
776767
action = self.create_invoice_action(
@@ -793,7 +784,8 @@ def create_invoice_action(self, parsed_inv=None, import_config=None, origin=None
793784
assert self.import_config_id
794785
import_config = self.import_config_id.convert_to_import_config()
795786
invoice = self.create_invoice(parsed_inv, import_config, origin)
796-
action = self.env.ref("account.action_move_in_invoice_type").sudo().read()[0]
787+
xmlid = "account.action_move_in_invoice_type"
788+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
797789
action.update(
798790
{
799791
"view_mode": "form,tree,kanban",
@@ -1271,7 +1263,8 @@ def update_invoice(self):
12711263
)
12721264
% self.invoice_filename
12731265
)
1274-
action = self.env.ref("account.action_move_in_invoice_type").sudo().read()[0]
1266+
xmlid = "account.action_move_in_invoice_type"
1267+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
12751268
action.update(
12761269
{
12771270
"view_mode": "form,tree,kanban",

edi_backend_partner_oca/models/res_partner.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def _compute_edi_backend_count(self):
1818
rec.edi_backend_count = len(rec.edi_backend_ids)
1919

2020
def action_edi_backend(self):
21-
action = self.env.ref("edi_oca.act_open_edi_backend_view")
22-
result = action.read()[0]
21+
xmlid = "edi_oca.act_open_edi_backend_view"
22+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
2323
backends = self.mapped("edi_backend_ids")
2424
if len(backends) > 1:
25-
result["domain"] = [("id", "in", backends.ids)]
25+
action["domain"] = [("id", "in", backends.ids)]
2626
else:
2727
res = self.env.ref("edi_oca.edi_backend_view_form", False)
28-
result["views"] = [(res and res.id or False, "form")]
29-
result["res_id"] = backends.id
30-
return result
28+
action["views"] = [(res and res.id or False, "form")]
29+
action["res_id"] = backends.id
30+
return action

edi_endpoint_oca/models/edi_backend.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def _compute_endpoints_count(self):
2222
record.endpoints_count = len(record.endpoint_ids)
2323

2424
def action_manage_endpoints(self):
25-
action = self.env.ref("edi_endpoint_oca.edi_endpoint_act_window").read()[0]
25+
xmlid = "edi_endpoint_oca.edi_endpoint_act_window"
26+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
2627
action["domain"] = [
2728
("backend_type_id", "=", self.backend_type_id.id),
2829
"|",

edi_oca/models/edi_exchange_consumer_mixin.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def edi_create_exchange_record(self, exchange_type_id):
133133
)
134134
if backend:
135135
return self._edi_create_exchange_record(exchange_type, backend)
136-
action = self.env.ref("edi_oca.edi_exchange_record_create_act_window").read()[0]
136+
xmlid = "edi_oca.edi_exchange_record_create_act_window"
137+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
137138
action["context"] = {
138139
"default_res_id": self.id,
139140
"default_model": self._name,
@@ -183,7 +184,8 @@ def _compute_exchange_record_count(self):
183184

184185
def action_view_edi_records(self):
185186
self.ensure_one()
186-
action = self.env.ref("edi_oca.act_open_edi_exchange_record_view").read()[0]
187+
xmlid = "edi_oca.act_open_edi_exchange_record_view"
188+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
187189
action["domain"] = [("model", "=", self._name), ("res_id", "=", self.id)]
188190
return action
189191

edi_oca/models/edi_exchange_record.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ def action_open_related_exchanges(self):
290290
self.ensure_one()
291291
if not self.related_exchange_ids:
292292
return {}
293-
action = self.env.ref("edi_oca.act_open_edi_exchange_record_view").read()[0]
293+
xmlid = "edi_oca.act_open_edi_exchange_record_view"
294+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
294295
action["domain"] = [("id", "in", self.related_exchange_ids.ids)]
295296
return action
296297

endpoint_auth_api_key/models/endpoint_mixin.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def _allowed_api_key_ids(self):
3434
return self.auth_api_key_group_ids.auth_api_key_ids.ids
3535

3636
def action_view_api_key_groups(self):
37-
action = self.env.ref(
38-
"auth_api_key_group.auth_api_key_group_act_window"
39-
).read()[0]
37+
xmlid = "auth_api_key_group.auth_api_key_group_act_window"
38+
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
4039
action["domain"] = [("id", "in", self.auth_api_key_group_ids.ids)]
4140
return action

0 commit comments

Comments
 (0)