Skip to content

Commit

Permalink
Merge pull request #1530 from CompassionCH/devel
Browse files Browse the repository at this point in the history
2022.11
  • Loading branch information
ecino authored Jun 16, 2022
2 parents e95e22f + 10b7867 commit b3500fc
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 74 deletions.
28 changes: 16 additions & 12 deletions mass_mailing_switzerland/models/mass_mailing_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion muskathlon/reports/muskathlon_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
9 changes: 5 additions & 4 deletions partner_communication_switzerland/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
<attribute name="domain">[('model', '=', res_model)]</attribute>
</field>
<field name="force_language" position="after">
<field name="sms_provider_id" attrs="{'invisible': [('send_mode', '!=', 'sms')]}"/>
<field name="sms_length_estimation" attrs="{'invisible': [('send_mode', '!=', 'sms')]}"/>
<field name="sms_number_estimation" attrs="{'invisible': [('send_mode', '!=', 'sms')]}"/>
<field name="sms_provider_id" attrs="{'invisible': ['|', ('customize_template', '=', False),('send_mode', '!=', 'sms')]}"/>
<field name="sms_length_estimation" attrs="{'invisible': ['|', ('customize_template', '=', False),('send_mode', '!=', 'sms')]}"/>
<field name="sms_number_estimation" attrs="{'invisible': ['|', ('customize_template', '=', False),('send_mode', '!=', 'sms')]}"/>
<field name="currency_id" invisible="1"/>
<field name="sms_cost_estimation" attrs="{'invisible': [('send_mode', '!=', 'sms')]}" widget="monetary" options="{'currency_field': 'currency_id'}"/>
</field>
<field name="report_id" position="after">
<field name="campaign_id" attrs="{'invisible': [('send_mode', '!=', 'sms')]}"/>
<field name="sms_cost_estimation" attrs="{'invisible': ['|', ('customize_template', '=', False),('send_mode', '!=', 'sms')]}" widget="monetary" options="{'currency_field': 'currency_id'}"/>
<field name="campaign_id" attrs="{'invisible': ['|', ('customize_template', '=', False),('send_mode', '!=', 'sms')]}"/>
</field>
</field>
</record>
Expand All @@ -36,7 +34,7 @@
<act_window id="action_generate_communication" key2="client_action_multi" name="Generate Communications"
res_model="partner.communication.generate.wizard" src_model="recurring.contract"
view_mode="form" target="new" view_type="form"
context="{'default_res_model': 'recurring.contract', 'default_sponsorship_ids': [(6, 0, active_ids)]}"
context="{'default_res_model': 'recurring.contract', 'default_selection_domain': [('id', 'in', active_ids)]}"

/>
</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -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")],
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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 """
Expand All @@ -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({
Expand Down
10 changes: 10 additions & 0 deletions partner_compassion/models/partner_compassion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down Expand Up @@ -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("<br/>")[0]
##########################################################################
# ORM METHODS #
##########################################################################
Expand Down
1 change: 1 addition & 0 deletions partner_compassion/views/partner_compassion_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</field>
<field name="firstname" position="after">
<field name="preferred_name"/>
<field name="address_name"/>
</field>
<xpath expr="//field[@name='child_ids']/form//field[@name='lastname']" position="before">
<field name="title"/>
Expand Down
4 changes: 3 additions & 1 deletion report_compassion/report/partner_communication.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@
</div>
<hr/>
</div>
<span t-raw="partner.short_address"/>
<span t-raw="partner.address_name"/>
<br/>
<span t-raw="'&lt;br/&gt;'.join((partner.short_address or '&lt;br/&gt;').split('&lt;br/&gt;')[1:])"/>
<div id="date" t-if="print_header" t-attf-style="margin-top: #{'20' if display_pp else '25'}mm;">
<span t-raw="partner.date_communication"/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="inherit_id" ref="thankyou_letters.generate_communication_wizard_thanks_form"/>
<field name="arch" type="xml">
<field name="print_subject" position="before">
<field name="product_id" attrs="{'invisible': [('send_mode', '=', 'digital')]}"/>
<field name="product_id" attrs="{'invisible': ['|', ('customize_template', '=', False), ('send_mode', '=', 'digital')]}"/>
</field>
</field>
</record>
Expand Down
19 changes: 19 additions & 0 deletions report_compassion/wizards/print_childpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions sponsorship_switzerland/data/completion_rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<field name="function_to_call">get_from_lsv_dd</field>
</record>

<record id="bank_statement_completion_rule_recurring_contract_wire_transfer_mapping" model="account.statement.completion.rule">
<field name="name">Match wire transfer payment mode custom note</field>
<field name="sequence">20</field>
<field name="function_to_call">recurring_contract_wire_transfer_mapping</field>
</record>

<record id="bank_statement_completion_rule_sponsor_name" model="account.statement.completion.rule">
<field name="name">Match sponsor name (based on label)</field>
<field name="sequence">90</field>
Expand Down
29 changes: 29 additions & 0 deletions sponsorship_switzerland/models/completion_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion theme_compassion/views/footer_it.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</a>
<ul>
<li>
<a t-att-href="'https://' + + wordpress.sponsorship_url">
<a t-att-href="'https://' + wordpress.host + wordpress.sponsorship_url">
Sostieni un bambino
</a>
</li>
Expand Down
3 changes: 2 additions & 1 deletion wordpress_connector/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b3500fc

Please sign in to comment.