Skip to content

Commit

Permalink
Merge pull request #1353 from CompassionCH/devel
Browse files Browse the repository at this point in the history
2021-06-10 Release
  • Loading branch information
ecino authored Jun 10, 2021
2 parents 1f51e9f + 220da19 commit bc8a73a
Show file tree
Hide file tree
Showing 42 changed files with 699 additions and 265 deletions.
1 change: 1 addition & 0 deletions crowdfunding_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"crm_compassion", # compassion-modules
"event", # odoo base modules
"wordpress_configuration", # compassion-modules
"mass_mailing_switzerland",
],
"data": [
"security/ir.model.access.csv",
Expand Down
10 changes: 5 additions & 5 deletions crowdfunding_compassion/forms/project_creation_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def _form_fieldsets(self):
"partner_title",
"partner_firstname",
"partner_lastname",
"partner_birthdate",
"partner_birthdate_date",
"partner_street",
"partner_zip",
"partner_city",
Expand Down Expand Up @@ -370,7 +370,7 @@ def _form_fieldsets(self):

def form_get_widget(self, fname, field, **kw):
"""Retrieve and initialize widget."""
if fname == "partner_birthdate":
if fname == "partner_birthdate_date":
if kw is None:
kw = {}
kw["max_date"] = datetime.now().isoformat()
Expand All @@ -383,7 +383,7 @@ def form_widgets(self):
res = super().form_widgets
res.update({
"partner_image": "cms_form_compassion.form.widget.simple.image",
"partner_birthdate": "cms.form.widget.date.ch",
"partner_birthdate_date": "cms.form.widget.date.ch",
})
return res

Expand All @@ -401,8 +401,8 @@ def _load_partner_field(self, fname, **req_values):
#################
def form_before_create_or_update(self, values, extra_values):
# Put a default spoken language
if "partner_birthdate" in extra_values and \
extra_values["partner_birthdate"] > datetime.now().date():
if "partner_birthdate_date" in extra_values and \
extra_values["partner_birthdate_date"] > datetime.now().date():
raise InvalidDateException
for key in ["participant_facebook_url",
"participant_twitter_url",
Expand Down
2 changes: 1 addition & 1 deletion crowdfunding_compassion/models/account_invoice_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
state = fields.Selection(index=True)
campaign_id = fields.Many2one("utm.campaign", index=True)
campaign_id = fields.Many2one("utm.campaign", index=True, readonly=True, related="account_analytic_id.campaign_id")
crowdfunding_participant_id = fields.Many2one(
"crowdfunding.participant", "Crowdfunding participant",
domain=[("project_id.state", "=", "active"),
Expand Down
2 changes: 1 addition & 1 deletion mass_mailing_switzerland/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# pylint: disable=C8101
{
"name": "Mass Mailing Switzerland",
"version": "12.0.2.0.1",
"version": "12.0.2.1.0",
"category": "Mailing",
"author": "Emanuel Cino",
"license": "AGPL-3",
Expand Down
22 changes: 22 additions & 0 deletions mass_mailing_switzerland/migrations/12.0.2.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


def migrate(cr, version):
if not version:
return

cr.execute("""
INSERT INTO mass_mailing_contact_partner_rel
SELECT partner_id, id AS mass_mailing_contact_id
FROM mail_mass_mailing_contact
WHERE partner_id IS NOT NULL;
""")

# Attach other existing partners with same email
cr.execute("""
INSERT INTO mass_mailing_contact_partner_rel
SELECT p.id AS partner_id, m.id AS mass_mailing_contact_id
FROM res_partner p JOIN mail_mass_mailing_contact m
ON p.email = m.email AND p.id != m.partner_id
WHERE p.contact_type = 'standalone'
AND p.email IS NOT NULL
""")
1 change: 1 addition & 0 deletions mass_mailing_switzerland/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
from . import mass_mailing_subscription
from . import mailchimp_lists
from . import res_partner_category
from . import mailchimp_merge_fields
9 changes: 8 additions & 1 deletion mass_mailing_switzerland/models/mailchimp_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ def process_member_from_stored_response(self, pending_record):
# Avoid loops in mailchimp sync
return super(MailchimpLists,
self.with_context(import_from_mailchimp=True)
).process_member_from_stored_response(pending_record)
).process_member_from_stored_response(pending_record)

@api.multi
def get_mapped_merge_field(self):
res = super().get_mapped_merge_field()
res.extend([
"lastname", "firstname", "number_sponsorships", "opt_out", "category_id"])
return res
34 changes: 34 additions & 0 deletions mass_mailing_switzerland/models/mailchimp_merge_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
##############################################################################
#
# Copyright (C) 2021 Compassion CH (http://www.compassion.ch)
# Releasing children from poverty in Jesus' name
# @author: Emanuel Cino <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################
from odoo import fields, models


class MailchimpMergeFields(models.Model):
_inherit = "mailchimp.merge.fields"

# Allows to use fields from mail.mass_mailing.contact records in merge fields
field_id = fields.Many2one(domain=[
('model_id.model', 'in', ['res.partner', 'mail.mass_mailing.contact']),
('ttype', 'not in', ['one2many', 'many2one', 'many2many'])]
)

def get_value(self, mailing_contact):
contact_fields = self.filtered(
lambda f: f.field_id.model == "mail.mass_mailing.contact")
partner_fields = self - contact_fields
res = super(MailchimpMergeFields, partner_fields).get_value(mailing_contact)
for custom_field in contact_fields:
if custom_field.field_id and hasattr(
self, custom_field.field_id.name):
value = getattr(self, custom_field.field_id.name)
else:
value = ''
res.update({custom_field.tag: value or ''})
return res
Loading

0 comments on commit bc8a73a

Please sign in to comment.