@ -20,19 +20,24 @@ class ResPartner(models.Model):
force_send = False , send_after_commit = True , user_signature = True ) :
force_send = False , send_after_commit = True , user_signature = True ) :
""" Override to delegate domain generation. """
""" Override to delegate domain generation. """
# notify_by_email
# notify_by_email
email_domain = self . _get_notify_by_email_domain ( message )
email_domain = self . _get_notify_by_email_domain (
message , force_send = force_send )
# `sudo` from original odoo method
# `sudo` from original odoo method
# the reason should be that anybody can write messages to a partner
# the reason should be that anybody can write messages to a partner
# and you really want to find all ppl to be notified
# and you really want to find all ppl to be notified
partners = self . sudo ( ) . search ( email_domain )
partners = self . sudo ( ) . search ( email_domain )
super ( ResPartner , partners ) . _notify (
super ( ResPartner , partners ) . _notify (
message , force_send = force_send ,
message , force_send = force_send ,
send_after_commit = send_after_commit ,
user_signature = user_signature )
# notify_by_digest
digest_domain = self . _get_notify_by_email_domain ( message , digest = True )
partners = self . sudo ( ) . search ( digest_domain )
partners . _notify_by_digest ( message )
send_after_commit = send_after_commit , user_signature = user_signature )
if not force_send :
# notify_by_digest
digest_domain = self . _get_notify_by_email_domain (
message , force_send = force_send , digest = True )
partners = self . sudo ( ) . search ( digest_domain )
partners . _notify_by_digest ( message )
# notify_by_chat
self . _notify_by_chat ( message )
return True
return True
def _digest_enabled_message_types ( self ) :
def _digest_enabled_message_types ( self ) :
@ -55,10 +60,12 @@ class ResPartner(models.Model):
self . env [ ' mail.digest ' ] . sudo ( ) . create_or_update ( self , message )
self . env [ ' mail.digest ' ] . sudo ( ) . create_or_update ( self , message )
@api.model
@api.model
def _get_notify_by_email_domain ( self , message , digest = False ) :
def _get_notify_by_email_domain ( self , message ,
force_send = False , digest = False ) :
""" Return domain to collect partners to be notified by email.
""" Return domain to collect partners to be notified by email.
: param message : instance of mail . message
: param message : instance of mail . message
: param force_send : whether the message should be sent immediately
: param digest : include / exclude digest enabled partners
: param digest : include / exclude digest enabled partners
NOTE : since mail . mail inherits from mail.message
NOTE : since mail . mail inherits from mail.message
@ -83,6 +90,8 @@ class ResPartner(models.Model):
( ' channel_ids ' , ' in ' , channels . ids ) ,
( ' channel_ids ' , ' in ' , channels . ids ) ,
( ' email ' , ' != ' , email ) ,
( ' email ' , ' != ' , email ) ,
]
]
if force_send :
return common_domain
# A bit hacky but we need to exclude / include partners
# A bit hacky but we need to exclude / include partners
# that do not have any user and as such, they have no email settings.
# that do not have any user and as such, they have no email settings.
# NOTE: using the following domain does not work,
# NOTE: using the following domain does not work,