feat: restrict default payment and register journal selection to user-allowed journals
This commit is contained in:
parent
4505c7c486
commit
da8fb0a861
@ -1,2 +1,5 @@
|
|||||||
from . import res_users
|
from . import res_users
|
||||||
from . import account_journal
|
from . import account_journal
|
||||||
|
from . import account_payment
|
||||||
|
from . import account_payment_register
|
||||||
|
|
||||||
|
|||||||
32
models/account_payment.py
Normal file
32
models/account_payment.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from odoo import models, api
|
||||||
|
|
||||||
|
class AccountPayment(models.Model):
|
||||||
|
_inherit = 'account.payment'
|
||||||
|
|
||||||
|
@api.depends('company_id', 'partner_id')
|
||||||
|
def _compute_journal_id(self):
|
||||||
|
# Call the parent method first to compute standard default journal
|
||||||
|
super(AccountPayment, self)._compute_journal_id()
|
||||||
|
|
||||||
|
# Override default journal if the user has specific allowed journals
|
||||||
|
user = self.env.user
|
||||||
|
allowed_journals = user.sudo().allowed_journal_ids
|
||||||
|
if allowed_journals:
|
||||||
|
for payment in self:
|
||||||
|
# If the currently selected journal is not in user's allowed journals
|
||||||
|
if not payment.journal_id or payment.journal_id not in allowed_journals:
|
||||||
|
# Try to select from intersection of allowed journals and available journals
|
||||||
|
allowed_available = allowed_journals & payment.available_journal_ids
|
||||||
|
if allowed_available:
|
||||||
|
payment.journal_id = allowed_available[0]
|
||||||
|
else:
|
||||||
|
# Fallback to the first allowed journal matching payment company
|
||||||
|
company = payment.company_id or self.env.company
|
||||||
|
company_journals = allowed_journals.filtered(
|
||||||
|
lambda j: j.company_id.id in [company.id, False] or j.company_id in company.parent_ids or j.company_id in company.child_ids
|
||||||
|
)
|
||||||
|
if company_journals:
|
||||||
|
payment.journal_id = company_journals[0]
|
||||||
|
else:
|
||||||
|
payment.journal_id = allowed_journals[0]
|
||||||
32
models/account_payment_register.py
Normal file
32
models/account_payment_register.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from odoo import models, api
|
||||||
|
|
||||||
|
class AccountPaymentRegister(models.TransientModel):
|
||||||
|
_inherit = 'account.payment.register'
|
||||||
|
|
||||||
|
@api.depends('available_journal_ids')
|
||||||
|
def _compute_journal_id(self):
|
||||||
|
# Call the parent method first to compute standard default journal
|
||||||
|
super(AccountPaymentRegister, self)._compute_journal_id()
|
||||||
|
|
||||||
|
# Override default journal if the user has specific allowed journals
|
||||||
|
user = self.env.user
|
||||||
|
allowed_journals = user.sudo().allowed_journal_ids
|
||||||
|
if allowed_journals:
|
||||||
|
for wizard in self:
|
||||||
|
# If the currently selected journal is not in user's allowed journals
|
||||||
|
if not wizard.journal_id or wizard.journal_id not in allowed_journals:
|
||||||
|
# Try to select from intersection of allowed journals and available journals
|
||||||
|
allowed_available = allowed_journals & wizard.available_journal_ids
|
||||||
|
if allowed_available:
|
||||||
|
wizard.journal_id = allowed_available[0]
|
||||||
|
else:
|
||||||
|
# Fallback to the first allowed journal matching wizard company
|
||||||
|
company = wizard.company_id or self.env.company
|
||||||
|
company_journals = allowed_journals.filtered(
|
||||||
|
lambda j: j.company_id.id in [company.id, False] or j.company_id in company.parent_ids or j.company_id in company.child_ids
|
||||||
|
)
|
||||||
|
if company_journals:
|
||||||
|
wizard.journal_id = company_journals[0]
|
||||||
|
else:
|
||||||
|
wizard.journal_id = allowed_journals[0]
|
||||||
Loading…
Reference in New Issue
Block a user