diff --git a/partner_communication_switzerland/__manifest__.py b/partner_communication_switzerland/__manifest__.py index cd8078c06..8efb721b5 100644 --- a/partner_communication_switzerland/__manifest__.py +++ b/partner_communication_switzerland/__manifest__.py @@ -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", diff --git a/partner_communication_switzerland/data/activity_data.xml b/partner_communication_switzerland/data/activity_data.xml new file mode 100644 index 000000000..6a37d7004 --- /dev/null +++ b/partner_communication_switzerland/data/activity_data.xml @@ -0,0 +1,9 @@ + + + + + Notify sponsor of new sponsorship + fa-tasks + + + diff --git a/partner_communication_switzerland/migrations/12.0.1.1.4/post-migration.py b/partner_communication_switzerland/migrations/12.0.1.1.4/post-migration.py new file mode 100644 index 000000000..705aef1be --- /dev/null +++ b/partner_communication_switzerland/migrations/12.0.1.1.4/post-migration.py @@ -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() diff --git a/partner_communication_switzerland/models/contracts.py b/partner_communication_switzerland/models/contracts.py index 51d50fe82..516722f0c 100644 --- a/partner_communication_switzerland/models/contracts.py +++ b/partner_communication_switzerland/models/contracts.py @@ -9,7 +9,7 @@ ############################################################################## import base64 import logging -from datetime import datetime, date +from datetime import datetime, date, timedelta from dateutil.relativedelta import relativedelta @@ -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") @@ -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 diff --git a/sponsorship_switzerland/models/contracts.py b/sponsorship_switzerland/models/contracts.py index bf6723f50..d893101cf 100644 --- a/sponsorship_switzerland/models/contracts.py +++ b/sponsorship_switzerland/models/contracts.py @@ -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