Skip to content

Commit

Permalink
CO-3965 Schedule activity when a sponsorship is validated and the par…
Browse files Browse the repository at this point in the history
…tner has "don't inform" as a communication setting (#1522)

* payment_mode might be False

* notify SDS when partner with no communication has new sponsorship

Retrieve the SDS user ID based on partner language and notify him of the new sponsorship and stuff

* translatable activity

* add migration and rename

* linter add new line

* Update partner_communication_switzerland/migrations/12.0.1.1.4/post-migration.py

Co-authored-by: ecino <[email protected]>

* Update partner_communication_switzerland/models/contracts.py

Co-authored-by: ecino <[email protected]>

* Update partner_communication_switzerland/models/contracts.py

Co-authored-by: ecino <[email protected]>

Co-authored-by: ecino <[email protected]>
  • Loading branch information
ovesco and ecino authored May 12, 2022
1 parent 488bf18 commit 0ecf0f2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions partner_communication_switzerland/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"data": [
"security/ir.model.access.csv",
"security/access_rules.xml",
"data/activity_data.xml",
"data/major_revision_emails.xml",
"data/child_letter_emails.xml",
"data/lifecycle_emails.xml",
Expand Down
9 changes: 9 additions & 0 deletions partner_communication_switzerland/data/activity_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Activity to inform partners with no communications settings of new sponsorships -->
<record id="activity_check_partner_no_communication" model="mail.activity.type">
<field name="name">Notify sponsor of new sponsorship</field>
<field name="icon">fa-tasks</field>
<field name="res_model_id" ref="base.model_res_partner"/>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import logging
from openupgradelib import openupgrade

_logger = logging.getLogger(__name__)


@openupgrade.migrate(use_env=True)
def migrate(env, installed_version):
if not installed_version:
return

# Add activities "for dont inform" sponsors
sponsorships = env["recurring.contract"].search([
('correspondent_id.global_communication_delivery_preference', '=', 'none'),
('state', 'in', ['waiting','active']),
('correspondent_id.ref', '!=', '1502623')])

for sponsorship in sponsorships:
# Add the activity
sponsorship.notify_sds_new_sponsorship()
27 changes: 26 additions & 1 deletion partner_communication_switzerland/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##############################################################################
import base64
import logging
from datetime import datetime, date
from datetime import datetime, date, timedelta

from dateutil.relativedelta import relativedelta

Expand Down Expand Up @@ -483,6 +483,25 @@ def contract_waiting_mandate(self):

return res

def notify_sds_new_sponsorship(self):
self.ensure_one()
config_settings = self.env["res.config.settings"].sudo()
sds_partner_id = config_settings.get_sponsorship_de_id()
if self.correspondent_id.lang == 'fr_CH':
sds_partner_id = config_settings.get_sponsorship_fr_id()
if self.correspondent_id.lang == 'it_IT':
sds_partner_id = config_settings.get_sponsorship_it_id()
sds_user = self.env['res.users'].sudo().search([('partner_id', '=', int(sds_partner_id))])

if sds_user.id:
self.correspondent_id.activity_schedule(
'partner_communication_switzerland.activity_check_partner_no_communication',
date_deadline=datetime.date(datetime.today() + timedelta(weeks=1)),
summary=_("Notify partner of new sponsorship"),
note=_("A sponsorship was added to a partner with the communication settings set to \"don't " +
"inform\", please notify him of it"),
user_id=sds_user.id
)
@api.multi
def contract_waiting(self):
mandates_valid = self.filtered(lambda c: c.state == "mandate")
Expand All @@ -494,6 +513,12 @@ def contract_waiting(self):
and c.start_date < contract.start_date)
contract.is_first_sponsorship = not old_sponsorships

# Notify SDS when partner has "don't inform" as comm setting
if contract.correspondent_id.global_communication_delivery_preference == "none":
# Notify the same SDS partner as the one notified when a sponsorship is created from the website
# so that we can manage partner language
self.notify_sds_new_sponsorship()

self.filtered(
lambda c: "S" in c.type
and not c.is_active
Expand Down
3 changes: 2 additions & 1 deletion sponsorship_switzerland/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def contract_waiting(self):
for contract in sponsorships:
payment_mode = contract.payment_mode_id.name
if (
contract.type in ["S", "SC", "SWP"]
payment_mode is not False
and contract.type in ["S", "SC", "SWP"]
and ("LSV" in payment_mode or "Postfinance" in payment_mode)
and contract.total_amount != 0
and not contract.partner_id.valid_mandate_id
Expand Down

0 comments on commit 0ecf0f2

Please sign in to comment.