diff --git a/mass_mailing_switzerland/models/mass_mailing_contact.py b/mass_mailing_switzerland/models/mass_mailing_contact.py index a1005a1f1..d1d69f8b8 100644 --- a/mass_mailing_switzerland/models/mass_mailing_contact.py +++ b/mass_mailing_switzerland/models/mass_mailing_contact.py @@ -315,19 +315,23 @@ def action_update_to_mailchimp(self): # Email field in odoo and mailchimp are now different. # solution : we remove previous link to mailchimp and export # the contact with new mail - if e.args[0] and literal_eval(e.args[0])['status'] == 404: - self.env.clear() - available_mailchimp_lists = self.env['mailchimp.lists'].search([]) - lists = available_mailchimp_lists.mapped('odoo_list_id').ids - contact_to_update.subscription_list_ids.filtered( - lambda x: x.list_id.id in lists).write({"mailchimp_id": False}) - # raise exception if it's any other type - else: - raise e + try: + if e.args[0] and literal_eval(e.args[0])['status'] == 404: + self.env.clear() + available_mailchimp_lists = self.env['mailchimp.lists'].search([]) + lists = available_mailchimp_lists.mapped('odoo_list_id').ids + contact_to_update.subscription_list_ids.filtered( + lambda x: x.list_id.id in lists).write({"mailchimp_id": False}) + # raise exception if it's any other type + else: + raise e - # once link is removed member can again be exported to mailchimp - out = out and super(MassMailingContact, - contact_to_update).action_export_to_mailchimp() + # once link is removed member can again be exported to mailchimp + out = out and super(MassMailingContact, + contact_to_update).action_export_to_mailchimp() + except: + logger.warning("Mailchimp error is not correctly processed.") + raise e return out @api.multi diff --git a/muskathlon/reports/muskathlon_report.py b/muskathlon/reports/muskathlon_report.py index 67feb22d7..9a34955e8 100644 --- a/muskathlon/reports/muskathlon_report.py +++ b/muskathlon/reports/muskathlon_report.py @@ -129,7 +129,7 @@ def init(self): LEFT JOIN crm_event_compassion AS cec ON ail.event_id = cec.id LEFT JOIN event_registration AS mr ON mr.partner_id = rp.id AND mr.event_id = cec.odoo_event_id - WHERE ail.state IN ('draft', 'open', 'paid') + WHERE ail.state = 'paid' AND ail.account_id = 2775 AND ail.user_id IS NOT NULL ) diff --git a/partner_communication_switzerland/models/contracts.py b/partner_communication_switzerland/models/contracts.py index 516722f0c..9e0029d3e 100644 --- a/partner_communication_switzerland/models/contracts.py +++ b/partner_communication_switzerland/models/contracts.py @@ -306,14 +306,15 @@ def _send_reminders_for_birthday_in_1day_or_2months(self): def _send_birthday_reminders(self, sponsorships, communication): communication_jobs = self.env["partner.communication.job"] for sponsorship in sponsorships: - send_to_partner_as_he_paid_the_gift = ( - sponsorship.send_gifts_to == "partner_id" + send_to_payer = ( + sponsorship.send_gifts_to == "partner_id" and sponsorship.partner_id.birthday_reminder ) + send_to_correspondent = sponsorship.correspondent_id.birthday_reminder try: communication_jobs += sponsorship.send_communication( communication, - correspondent=True, - both=send_to_partner_as_he_paid_the_gift, + correspondent=send_to_correspondent, + both=send_to_payer and send_to_correspondent, ) except Exception: # In any case, we don't want to stop email generation! diff --git a/partner_communication_switzerland/views/generate_communication_wizard_view.xml b/partner_communication_switzerland/views/generate_communication_wizard_view.xml index c02acb2af..f9abe366f 100644 --- a/partner_communication_switzerland/views/generate_communication_wizard_view.xml +++ b/partner_communication_switzerland/views/generate_communication_wizard_view.xml @@ -20,14 +20,12 @@ [('model', '=', res_model)] - - - + + + - - - - + + @@ -36,7 +34,7 @@ diff --git a/partner_communication_switzerland/wizards/generate_communication_wizard.py b/partner_communication_switzerland/wizards/generate_communication_wizard.py index b130f57aa..d42a8f6ff 100644 --- a/partner_communication_switzerland/wizards/generate_communication_wizard.py +++ b/partner_communication_switzerland/wizards/generate_communication_wizard.py @@ -29,7 +29,8 @@ class GenerateCommunicationWizard(models.TransientModel): _inherit = "partner.communication.generate.wizard" sponsorship_ids = fields.Many2many( - "recurring.contract", string="Sponsorships", readonly=False + "recurring.contract", string="Sponsorships", + compute="_compute_sponsorships" ) res_model = fields.Selection( [("res.partner", "Partners"), ("recurring.contract", "Sponsorships")], @@ -47,9 +48,8 @@ class GenerateCommunicationWizard(models.TransientModel): default="correspondent_id", required=True, ) - selection_domain = fields.Char(default=lambda s: s._default_domain()) # Remove domain filter and handle it in the view - model_id = fields.Many2one(domain=[], readonly=False) + model_id = fields.Many2one(domain=[], readonly=False, required=True) sms_length_estimation = fields.Integer(readonly=True) sms_number_estimation = fields.Integer(readonly=True) sms_cost_estimation = fields.Float(compute="_compute_sms_cost_estimation") @@ -64,15 +64,6 @@ class GenerateCommunicationWizard(models.TransientModel): readonly=False, ) - @api.model - def _default_domain(self): - # Select sponsorships if called from the sponsorship menu - sponsorship_ids = self.env.context.get("default_sponsorship_ids") - if sponsorship_ids: - return f"[('id', 'in', {str(sponsorship_ids[0][2])})]" - else: - return f"[('id', 'in', {self._default_partners()})]" - @api.multi def _compute_progress(self): s_wizards = self.filtered(lambda w: w.res_model == "recurring.contract") @@ -104,8 +95,8 @@ def _compute_currency(self): ########################################################################## # VIEW CALLBACKS # ########################################################################## - @api.onchange("selection_domain") - def onchange_domain(self): + @api.depends("selection_domain", "res_model") + def _compute_partners(self): if self.res_model == "recurring.contract": if self.partner_source == "send_gifts_to": # We assume the payer and the correspondent speak same lang @@ -124,37 +115,13 @@ def onchange_domain(self): partners = self.sponsorship_ids.mapped(partner_source) self.partner_ids = partners else: - super().onchange_domain() - - @api.onchange("sponsorship_ids", "partner_source") - def onchange_sponsorships(self): - # Set partners for generation to work - if self.partner_source == "send_gifts_to": - partners = self.env["res.partner"] - for sponsorship in self.sponsorship_ids: - partners += sponsorship.mapped(sponsorship.send_gifts_to) - else: - partners = self.sponsorship_ids.mapped(self.partner_source) - self.partner_ids = partners - - @api.onchange("partner_ids", "body_html") - def onchange_recipients(self): - if self.partner_ids and self.body_html: - soup = BeautifulSoup(self.body_html) - text_approximation = len(soup.get_text()) - self.sms_length_estimation = text_approximation - self.sms_number_estimation = ceil( - float(text_approximation) // SMS_CHAR_LIMIT - ) * len(self.partner_ids) + super()._compute_partners() - @api.multi - def get_preview(self): - object_ids = self.partner_ids[0].id - if self.res_model == "recurring.contract": - object_ids = self.sponsorship_ids[0].id - return super( - GenerateCommunicationWizard, self.with_context(object_ids=object_ids) - ).get_preview() + @api.depends("selection_domain", "res_model") + def _compute_sponsorships(self): + if self.res_model == "recurring.contract" and self.selection_domain: + self.sponsorship_ids = self.env["recurring.contract"].search( + safe_eval(self.selection_domain)) def generate_communications(self, async_mode=True): """ Create the communication records """ @@ -172,7 +139,6 @@ def generate_communications(self, async_mode=True): "partner_id": partner.id, "object_ids": sponsorship.id, "config_id": self.model_id.id, - "report_id": self.report_id.id or self.model_id.report_id.id, } if self.send_mode: vals.update({ diff --git a/partner_compassion/models/partner_compassion.py b/partner_compassion/models/partner_compassion.py index ee53adcca..663bd4df3 100644 --- a/partner_compassion/models/partner_compassion.py +++ b/partner_compassion/models/partner_compassion.py @@ -261,6 +261,12 @@ class ResPartner(models.Model): help="Have at least one sponsorship for the W&P program", compute="_compute_write_and_pray", ) + address_name = fields.Char( + compute="_compute_address_name", + inverse=lambda p: True, + store=True, + help="Name used for postal sending" + ) ########################################################################## # FIELDS METHODS # @@ -364,6 +370,10 @@ def _compute_prim_sec_segments(self): partner.primary_segment_id = partner.segments_affinity_ids[:1].segment_id partner.secondary_segment_id = partner.segments_affinity_ids[1:2].segment_id + @api.depends("name") + def _compute_address_name(self): + for partner in self: + partner.address_name = (partner.short_address or '').split("
")[0] ########################################################################## # ORM METHODS # ########################################################################## diff --git a/partner_compassion/views/partner_compassion_view.xml b/partner_compassion/views/partner_compassion_view.xml index 917a38d90..189960367 100644 --- a/partner_compassion/views/partner_compassion_view.xml +++ b/partner_compassion/views/partner_compassion_view.xml @@ -13,6 +13,7 @@
+ diff --git a/report_compassion/report/partner_communication.xml b/report_compassion/report/partner_communication.xml index 23f268be2..71a0b46c4 100644 --- a/report_compassion/report/partner_communication.xml +++ b/report_compassion/report/partner_communication.xml @@ -244,7 +244,9 @@
- + +
+
diff --git a/report_compassion/views/generate_communication_wizard_view.xml b/report_compassion/views/generate_communication_wizard_view.xml index 7a2d0a355..dda6be047 100644 --- a/report_compassion/views/generate_communication_wizard_view.xml +++ b/report_compassion/views/generate_communication_wizard_view.xml @@ -5,7 +5,7 @@ - + diff --git a/report_compassion/wizards/print_childpack.py b/report_compassion/wizards/print_childpack.py index 867ffdb3a..e54a4980b 100644 --- a/report_compassion/wizards/print_childpack.py +++ b/report_compassion/wizards/print_childpack.py @@ -88,3 +88,22 @@ def get_report(self): "context": self.env.context, } return report_ref.report_action(children.ids, data=data, config=False) + + @api.multi + def print(self): + """ + Print selected child dossier directly to printer + """ + children = self.env["compassion.child"].browse( + self.env.context.get("active_ids") + ).with_context(lang=self.lang) + data = { + "lang": self.lang, + "doc_ids": children.ids, + "is_pdf": self.pdf, + "type": self.type, + } + report_name = "report_compassion.report_" + self.type.split(".")[1] + report_ref = self.env.ref(report_name).with_context(lang=self.lang) + report_ref.render_qweb_pdf(children.ids, data=data) + return True diff --git a/sponsorship_switzerland/data/completion_rules.xml b/sponsorship_switzerland/data/completion_rules.xml index 6846ff744..0310a6764 100644 --- a/sponsorship_switzerland/data/completion_rules.xml +++ b/sponsorship_switzerland/data/completion_rules.xml @@ -25,6 +25,12 @@ get_from_lsv_dd + + Match wire transfer payment mode custom note + 20 + recurring_contract_wire_transfer_mapping + + Match sponsor name (based on label) 90 diff --git a/sponsorship_switzerland/models/completion_rules.py b/sponsorship_switzerland/models/completion_rules.py index 5fc22934f..3bc7193be 100644 --- a/sponsorship_switzerland/models/completion_rules.py +++ b/sponsorship_switzerland/models/completion_rules.py @@ -51,6 +51,11 @@ class StatementCompletionRule(models.Model): "(based on the BVR reference of the sponsor)", ), ("get_from_lsv_dd", "Compassion: Put LSV DD Credits in 1098"), + ( + "recurring_contract_wire_transfer_mapping", + "Compassion: From custom note on wire transfer" + "(based on the CAMT label)", + ), ( "get_sponsor_name", "Compassion[POST]: From sponsor reference " @@ -131,6 +136,30 @@ def get_from_partner_ref(self, stmts_vals, st_line): ) return res + def recurring_contract_wire_transfer_mapping(self, stmts_val, st_line): + if "name" not in st_line: + return + + name = st_line['name'] + res = dict() + + wire_transfer_mode = self.env['account.payment.mode'].with_context(lang="en_US").search([ + ("name", "=", "wire transfer") + ]) + + if not wire_transfer_mode: + logger.warning("Unable to find wire transfer payment mode") + return res + + recurring_contracts = self.env['recurring.contract'].search([ + ("comment", "ilike", name), + ("payment_mode_id", "=", wire_transfer_mode.id) + ]) + if recurring_contracts: + res['partner_id'] = recurring_contracts[0].partner_id + + return res + def get_from_bvr_ref(self, stmts_vals, st_line): """ If line ref match an invoice BVR Reference, update partner and account diff --git a/theme_compassion/views/footer_it.xml b/theme_compassion/views/footer_it.xml index c5a2a9444..0cd6c88d9 100644 --- a/theme_compassion/views/footer_it.xml +++ b/theme_compassion/views/footer_it.xml @@ -15,7 +15,7 @@
  • - + Sostieni un bambino
  • diff --git a/wordpress_connector/models/request.py b/wordpress_connector/models/request.py index 6ad19ab2f..0d3dcfbc1 100644 --- a/wordpress_connector/models/request.py +++ b/wordpress_connector/models/request.py @@ -65,4 +65,5 @@ def _parse_front_matter(self, fm, values): fm["lang"] = match_obj.match_lang(fm["lang"]) partner = match_obj.match_partner_to_infos(fm, options={"skip_create": True}) - values["partner_id"] = partner.id + if partner: + values["partner_id"] = partner.id