Skip to content

Commit

Permalink
Merge pull request #1403 from CompassionCH/devel
Browse files Browse the repository at this point in the history
Stabilization 1.6
  • Loading branch information
ecino authored Aug 19, 2021
2 parents 6f5a502 + ee9347c commit 1222c45
Show file tree
Hide file tree
Showing 32 changed files with 1,366 additions and 215 deletions.
12 changes: 7 additions & 5 deletions crowdfunding_compassion/controllers/homepage_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

_logger = logging.getLogger(__name__)


def sponsorship_card_content():
return {"type": "sponsorship",
"value": 0,
Expand Down Expand Up @@ -50,6 +51,7 @@ def _compute_homepage_context(self, year, **kwargs):

current_year_projects = project_obj.sudo().get_active_projects(
year=year, limit=8)

active_funds = fund_obj.sudo().search(
[("activate_for_crowdfunding", "=", True)]
)
Expand All @@ -59,7 +61,7 @@ def _compute_homepage_context(self, year, **kwargs):
}

for fund in active_funds:
impact[fund.name] = {
impact[fund.id] = {
"type": "fund",
"value": 0,
"name": fund.crowdfunding_impact_text_active,
Expand All @@ -79,19 +81,19 @@ def _compute_homepage_context(self, year, **kwargs):
for project in current_year_projects:
impact["sponsorship"]["value"] += project.number_sponsorships_reached

project_fund = project.product_id.name
project_fund = project.product_id.id
if project_fund in impact:
impact[project_fund]["value"] += project.product_number_reached

for fund in active_funds:
if impact[fund.name]["value"] > 1:
impact[fund.name]["text"] = fund.crowdfunding_impact_text_passive_plural
if impact[fund.id]["value"] > 1:
impact[fund.id]["text"] = fund.crowdfunding_impact_text_passive_plural

if impact["sponsorship"]["value"] > 1:
impact["sponsorship"]["text"] = _("sponsored children")

return {
"projects": current_year_projects,
"impact": impact,
"impact": {k: v for k, v in impact.items() if v['value']},
"base_url": request.website.domain
}
2 changes: 1 addition & 1 deletion crowdfunding_compassion/models/crowdfunding_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _compute_number_sponsorships_reached(self):
@api.multi
def _compute_website_url(self):
for project in self:
project.website_url = f"/project/{project.id}"
project.website_url = f"{project.website_id.domain}/project/{project.id}"

@api.multi
def _compute_time_left(self):
Expand Down
1 change: 1 addition & 0 deletions mass_mailing_switzerland/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"views/mass_mailing_contact_view.xml",
"views/mass_mailing_settings_view.xml",
"views/generate_link_wizard_view.xml",
"views/account_analytic_line_view.xml",
],
"depends": [
"mail_tracking", # oca_addons/social
Expand Down
4 changes: 4 additions & 0 deletions mass_mailing_switzerland/data/smart_tags.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
FROM recurring_contract c JOIN res_partner p ON c.correspondent_id = p.id
WHERE (now()::date - start_date::date) <= 60 and is_first_sponsorship = true
AND child_id IS NOT NULL
UNION
SELECT id
FROM res_partner
WHERE (now()::date - onboarding_new_donor_start_date::date) <= 60
</field>
</record>
</odoo>
7 changes: 6 additions & 1 deletion mass_mailing_switzerland/models/analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@


class AnalyticAccount(models.Model):

_inherit = "account.analytic.account"

campaign_id = fields.Many2one("utm.campaign", readonly=False)


class AnalyticLine(models.Model):
_inherit = "account.analytic.line"

state = fields.Selection(related='move_id.invoice_id.state', readonly=True)
12 changes: 12 additions & 0 deletions mass_mailing_switzerland/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def _compute_wp_formdata(self):
def create(self, vals):
if vals.get("opt_out"):
vals["date_opt_out"] = fields.Date.today()
contact_rel_to_opt_out = self.env["mail.mass_mailing.list_contact_rel"].search(
[("contact_id.email", "in", self.mapped("email"))]
)
contact_rel_to_opt_out.with_context({"opt_out_from_partner": True}).write({
"opt_out": True
})
return super().create(vals)

@api.multi
Expand All @@ -82,6 +88,12 @@ def write(self, vals):
"""
if vals.get("opt_out"):
vals["date_opt_out"] = fields.Date.today()
contact_rel_to_opt_out = self.env["mail.mass_mailing.list_contact_rel"].search(
[("contact_id.email", "in", self.mapped("email"))]
)
contact_rel_to_opt_out.with_context({"opt_out_from_partner": True}).write({
"opt_out": True
})
elif "opt_out" in vals:
vals["date_opt_out"] = False
for partner in self.filtered(lambda c: c.mass_mailing_contact_ids):
Expand Down
25 changes: 25 additions & 0 deletions mass_mailing_switzerland/models/utm.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,31 @@ class UtmCampaign(models.Model):
compute="_compute_click_count", store=True, readonly=True
)

def open_analytic_lines(self):
return {
"name": _("Analytic Lines"),
"type": "ir.actions.act_window",
"view_type": "form",
"view_mode": "tree",
"res_model": "account.analytic.line",
"views": [(self.env.ref("mass_mailing_switzerland.view_analytic_line_tree_utm").id, "tree")],
"domain": [("account_id.campaign_id", "=", self.id)],
"target": "current",
}

def _compute_total_donation(self):
# Put a nice formatting
for utm in self:
lines = self.env["account.analytic.line"].search(
[("account_id.campaign_id", "=", utm.id)]
)
utm.donation_amount = sum(lines.mapped("amount"))
utm.total_donation = (
"CHF {:,.2f}".format(utm.donation_amount)
.replace(".00", ".-")
.replace(",", "'")
)

def _compute_mass_mailing_id(self):
for campaign in self:
campaign.mailing_campaign_id = self.env[
Expand Down
24 changes: 24 additions & 0 deletions mass_mailing_switzerland/views/account_analytic_line_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<odoo>

<!-- Analytic Line Tree View -->
<record model="ir.ui.view" id="view_analytic_line_tree_utm">
<field name="name">account.analytic.line.utm.tree</field>
<field name="model">account.analytic.line</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="account_id"/>
<field name="general_account_id"/>
<field name="amount" sum="Total amount"/>
<field name="partner_id" />
<field name="user_id" />
<field name="product_id" />
<field name="unit_amount"/>
<field name="state"/>
<field name="date" />
</tree>
</field>
</record>

</odoo>
4 changes: 2 additions & 2 deletions mass_mailing_switzerland/views/utm_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
<button name="open_letters" type="object" icon="fa-pencil" class="oe_stat_button">
<field name="letters_count" string="Letters" widget="statinfo"/>
</button>
<button name="open_invoices" type="object" icon="fa-money" class="oe_stat_button">
<field name="total_donation" string="Donations" widget="statinfo"/>
<button name="open_analytic_lines" type="object" icon="fa-money" class="oe_stat_button">
<field name="total_donation" string="Financials" widget="statinfo"/>
</button>
<button name="open_clicks" type="object" icon="fa-click" class="oe_stat_button">
<field name="click_count" string="Clicks" widget="statinfo"/>
Expand Down
3 changes: 3 additions & 0 deletions partner_communication_switzerland/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"report/onboarding_photo_by_post.xml",
"data/onboarding_process.xml",
"data/onboarding_survey.xml",
"data/onboarding_new_donors_process.xml",
"report/child_picture.xml",
"views/communication_job_view.xml",
"views/download_child_pictures_view.xml",
Expand All @@ -90,8 +91,10 @@
"views/field_office_view.xml",
"views/communication_test_case_view.xml",
"views/notification_settings_view.xml",
"views/onboarding_settings_view.xml",
"wizards/res_partner_create_portal_wizard.xml",
"templates/zoom_registration_form.xml",
"templates/onboarding_unsubscribe.xml"
],
"demo": [],
"installable": True,
Expand Down
1 change: 1 addition & 0 deletions partner_communication_switzerland/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
##############################################################################
from . import b2s_image
from . import zoom_registration
from . import onboarding
51 changes: 51 additions & 0 deletions partner_communication_switzerland/controllers/onboarding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
##############################################################################
#
# Copyright (C) 2021 Compassion CH (http://www.compassion.ch)
# Releasing children from poverty in Jesus' name
# @author: Jonathan Guerne <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################
import logging

from odoo import http, _
from odoo.http import request, Controller

from odoo.addons.cms_form.controllers.main import FormControllerMixin

_logger = logging.getLogger(__name__)


class OnboardingController(Controller, FormControllerMixin):

@http.route(
[
"/onboarding/<string:onboarding_type>/unsubscribe/<string:onboarding_hash>"
],
type="http", auth="public", methods=["GET", "POST"], website=True,
sitemap=False)
def onboarding_unsubscribe(self, onboarding_type, onboarding_hash, confirm_opt_out=False, **kwargs):

if onboarding_type == "new_donors":
return self._new_donors_onboarding_unsubscribe(onboarding_hash, confirm_opt_out)
else:
return http.request.render("website.404")

def _new_donors_onboarding_unsubscribe(self, onboarding_hash, confirm_opt_out):
partner = request.env["res.partner"].sudo().search(
[("onboarding_new_donor_hash", "=", onboarding_hash)]
)

if not partner:
return http.request.render("website.404")

if not confirm_opt_out:
return request.render(
"partner_communication_switzerland.new_donors_onboarding_unsubscribe_template"
)

partner.opt_out = True

return request.render(
"partner_communication_switzerland.confirmation_onboarding_unsubscribe_template")
Loading

0 comments on commit 1222c45

Please sign in to comment.