[FIX] account_operating_unit: use sudo() in OU onchange#835
[FIX] account_operating_unit: use sudo() in OU onchange#835
Conversation
Users without journal read permission get AccessError when the _onchange_operating_unit triggers. Use sudo() to safely read journal.operating_unit_id and journal.type. Port of BITVAX fix from 16.0-fix-journal-access-denied branch.
|
can you explain how to reproduce the issue? |
|
@AaronHForgeFlow Sure, here's how to reproduce: Steps to reproduce
Expected behaviorThe Actual behavior (without this fix)
This was originally fixed in our 16.0 fork (BITVAX/operating-unit |
There was a problem hiding this comment.
Maybe we can achieve the same result by deriving the journal type from the move_type (which is always accessible) and moving the OU logic directly into the search domain (code not tested)
def _onchange_operating_unit(self):
if not self.operating_unit_id:
return
j_type = 'sale' if self.move_type in ('out_invoice', 'out_refund') else 'purchase'
if self.move_type == 'entry':
j_type = 'general'
new_journal = self.env["account.journal"].search([
("type", "=", j_type),
("operating_unit_id", "=", self.operating_unit_id.id)
], limit=1)
if new_journal:
self.journal_id = new_journal
if self.line_ids:
self.line_ids.operating_unit_id = self.operating_unit_id
Summary
.sudo()when readingjournal_id.operating_unit_idandjournal_id.typein_onchange_operating_unitto preventAccessErrorfor users without journal read permission.Test plan