fix
This commit is contained in:
parent
1434c49a21
commit
42843ca389
|
|
@ -24,17 +24,34 @@ class AccountPayment(models.Model):
|
||||||
def action_notify_payment(self, payment):
|
def action_notify_payment(self, payment):
|
||||||
# Check authorization before sending notification
|
# Check authorization before sending notification
|
||||||
if not self._is_authorized_to_notify():
|
if not self._is_authorized_to_notify():
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Prepare notification content
|
||||||
subject = _('Payment Notification') + ' - {}'.format(payment.partner_id.name)
|
subject = _('Payment Notification') + ' - {}'.format(payment.partner_id.name)
|
||||||
message = '{} '.format(payment.partner_id.name) + _('is successfully paid.') + '\n' + _(
|
message = '{} '.format(payment.partner_id.name) + _('is successfully paid.') + '\n' + _(
|
||||||
'Payment Amount: ') + '{}'.format(payment.amount) + '\n' + _('Ref: ') + '{}'.format(payment.ref) + '\n' + _(
|
'Payment Amount: ') + '{}'.format(payment.amount) + '\n' + _('Ref: ') + '{}'.format(payment.ref) + '\n' + _(
|
||||||
'On Date: ') + '{}'.format(payment.date)
|
'On Date: ') + '{}'.format(payment.date)
|
||||||
group = 'purchase_requisition_custom.group_receive_payment_notification'
|
|
||||||
# author_id = payment.create_uid.partner_id.id or None
|
# Get recipients from the notification group, excluding purchase managers
|
||||||
author_id = self.env.user.partner_id.id or None
|
recipient_group = self.env.ref('purchase_requisition_custom.group_receive_payment_notification')
|
||||||
self.env.user.partner_id.send_notification_message(subject=subject, body=message, author_id=author_id,
|
excluded_group = self.env.ref('purchase.group_purchase_manager')
|
||||||
group=group)
|
|
||||||
|
# Filter out users who belong to the excluded group
|
||||||
|
partner_ids = recipient_group.users.filtered(
|
||||||
|
lambda u: u not in excluded_group.users
|
||||||
|
).mapped('partner_id').ids
|
||||||
|
|
||||||
|
# Send notification only to filtered recipients
|
||||||
|
if partner_ids:
|
||||||
|
author_id = self.env.user.partner_id.id or None
|
||||||
|
self.env.user.partner_id.message_post(
|
||||||
|
type="notification",
|
||||||
|
subject=subject,
|
||||||
|
body=message,
|
||||||
|
author_id=author_id,
|
||||||
|
partner_ids=partner_ids,
|
||||||
|
subtype_xmlid="mail.mt_comment"
|
||||||
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class AccountPayment(models.Model):
|
||||||
authorized_groups = [
|
authorized_groups = [
|
||||||
'account.group_account_manager', # Account Manager
|
'account.group_account_manager', # Account Manager
|
||||||
'account.group_account_invoice', # Billing/Invoicing
|
'account.group_account_invoice', # Billing/Invoicing
|
||||||
'purchase.group_purchase_manager', # Purchase Manager
|
# 'purchase.group_purchase_manager', # Purchase Manager - Excluded
|
||||||
]
|
]
|
||||||
|
|
||||||
# Check if user belongs to any authorized group
|
# Check if user belongs to any authorized group
|
||||||
|
|
@ -31,18 +31,32 @@ class AccountPayment(models.Model):
|
||||||
def action_notify_payment(self, payment):
|
def action_notify_payment(self, payment):
|
||||||
# Check authorization before sending notification
|
# Check authorization before sending notification
|
||||||
if not self._is_authorized_to_notify():
|
if not self._is_authorized_to_notify():
|
||||||
# Unauthorized user - don't send notification
|
|
||||||
# You can optionally log this attempt
|
|
||||||
# _logger.warning('Unauthorized payment notification attempt by user: %s', self.env.user.name)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Send Notifications (only if authorized)
|
# Prepare notification content
|
||||||
subject = _('Payment Notification') + ' - {}'.format(payment.partner_id.name)
|
subject = _('Payment Notification') + ' - {}'.format(payment.partner_id.name)
|
||||||
message = '{} '.format(payment.partner_id.name) + _('is successfully paid.') + '\n' + _('Payment Amount: ') + '{}'.format(payment.amount) + '\n' + _('Ref: ') + '{}'.format(payment.ref) + '\n' + _('On Date: ') + '{}'.format(payment.date)
|
message = '{} '.format(payment.partner_id.name) + _('is successfully paid.') + '\n' + _('Payment Amount: ') + '{}'.format(payment.amount) + '\n' + _('Ref: ') + '{}'.format(payment.ref) + '\n' + _('On Date: ') + '{}'.format(payment.date)
|
||||||
group = 'purchase_requisition_custom.group_receive_payment_notification'
|
|
||||||
# author_id = payment.create_uid.partner_id.id or None
|
# Get recipients from the notification group, excluding purchase managers
|
||||||
author_id = self.env.user.partner_id.id or None
|
recipient_group = self.env.ref('purchase_requisition_custom.group_receive_payment_notification')
|
||||||
self.env.user.partner_id.send_notification_message(subject=subject, body=message, author_id=author_id, group=group)
|
excluded_group = self.env.ref('purchase.group_purchase_manager')
|
||||||
|
|
||||||
|
# Filter out users who belong to the excluded group
|
||||||
|
partner_ids = recipient_group.users.filtered(
|
||||||
|
lambda u: u not in excluded_group.users
|
||||||
|
).mapped('partner_id').ids
|
||||||
|
|
||||||
|
# Send notification only to filtered recipients
|
||||||
|
if partner_ids:
|
||||||
|
author_id = self.env.user.partner_id.id or None
|
||||||
|
self.env.user.partner_id.message_post(
|
||||||
|
type="notification",
|
||||||
|
subject=subject,
|
||||||
|
body=message,
|
||||||
|
author_id=author_id,
|
||||||
|
partner_ids=partner_ids,
|
||||||
|
subtype_xmlid="mail.mt_comment"
|
||||||
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue