Skip to content

Commit

Permalink
Merge pull request #1514 from CompassionCH/devel
Browse files Browse the repository at this point in the history
2022.07
  • Loading branch information
ecino authored Apr 21, 2022
2 parents 6326e7c + 9f516fc commit f3fdb0d
Show file tree
Hide file tree
Showing 60 changed files with 314 additions and 321 deletions.
1 change: 1 addition & 0 deletions account_reconcile_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
]},
"data": [
"data/statement_operation.xml",
"data/queue_job.xml",
"views/account_reconcile_compassion.xml",
"views/reconcile_fund_wizard_view.xml",
"views/reconcile_split_payment_wizard_view.xml",
Expand Down
14 changes: 14 additions & 0 deletions account_reconcile_compassion/data/queue_job.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo>
<!-- Channels -->
<record id="channel_reconcile" model="queue.job.channel">
<field name="name">reconcile_compassion</field>
<field name="parent_id" ref="queue_job.channel_root"/>
</record>

<!-- Job functions -->
<record id="process_reconcile_job" model="queue.job.function">
<field name="model_id" ref="model_account_bank_statement_line"/>
<field name="method">_process_reconciliation</field>
<field name="channel_id" ref="channel_reconcile"/>
</record>
</odoo>
2 changes: 0 additions & 2 deletions account_reconcile_compassion/models/bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from odoo.exceptions import UserError
from odoo.tools import mod10r
from functools import reduce
from odoo.addons.queue_job.job import job

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -61,7 +60,6 @@ def get_statement_line_for_reconciliation_widget(self):
##########################################################################

@api.multi
@job(default_channel="root.bank_reconciliation")
def _process_reconciliation(
self, counterpart_aml_dicts=None, payment_aml_rec=None, new_aml_dicts=None
):
Expand Down
27 changes: 20 additions & 7 deletions crowdfunding_compassion/controllers/homepage_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,47 @@ def _compute_homepage_context():
year = datetime.now().year
project_obj = request.env["crowdfunding.project"].sudo()
current_year_projects = project_obj.get_active_projects(year=year)
active_funds = current_year_projects.mapped("product_id")
funds_used = current_year_projects.mapped("product_id")
active_funds = funds_used.search([("activate_for_crowdfunding", "=", True)])
active_funds_data = []
impact = {
"sponsorship": sponsorship_card_content()
}
for fund in active_funds:
for fund in funds_used:
impact[fund.name] = {
"type": "fund",
"value": 0,
"name": fund.crowdfunding_impact_text_active,
# "name": fund.crowdfunding_impact_text_active,
"text": fund.crowdfunding_impact_text_passive_singular,
"description": fund.crowdfunding_description,
"icon_image": fund.image_medium or SPONSOR_ICON,
}
for fund in active_funds:
active_funds_data.append({
"name": fund.crowdfunding_impact_text_active,
"description": fund.crowdfunding_description,
"icon_image": fund.image_medium or SPONSOR_ICON,
# the header is a small image so we can compress it to save space
"header_image":
compress_big_images(
fund.image_large,
max_width=400
) if fund.image_large else SPONSOR_HEADER,

}
})

for project in current_year_projects:
impact["sponsorship"]["value"] += project.number_sponsorships_reached
project_fund = project.product_id.name
if project_fund in impact:
impact[project_fund]["value"] += project.product_number_reached

for fund in active_funds:
if impact[fund.name]["value"] > 1:
for fund in funds_used:
impact_val = impact[fund.name]["value"]
large_impact = fund.impact_type == "large"
if large_impact and impact_val > 100:
impact[fund.name]["text"] = fund.crowdfunding_impact_text_passive_plural
impact[fund.name]["value"] = int(impact_val / 100)
elif not large_impact and impact_val > 1:
impact[fund.name]["text"] = fund.crowdfunding_impact_text_passive_plural

if impact["sponsorship"]["value"] > 1:
Expand All @@ -88,6 +100,7 @@ def _compute_homepage_context():
return {
"projects": current_year_projects[:8],
"impact": {k: v for k, v in impact.items() if v['value']},
"active_funds": active_funds_data,
"base_url": request.website.domain,
"subheading": subheading,
}
28 changes: 15 additions & 13 deletions crowdfunding_compassion/controllers/project_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,27 @@ def get_sponsorships_and_donations(self, sponsorship_ids, invoice_line_ids):
for sponsorship in sponsorship_ids
]

donations = [
{
donations = []
for donation in invoice_line_ids.filtered(lambda l: l.state == "paid"):
product = donation.product_id
quantity = donation.quantity
impact_text = product.crowdfunding_impact_text_passive_singular
if product.impact_type == "standard" and int(quantity) > 1:
impact_text = product.crowdfunding_impact_text_passive_plural
elif product.impact_type == "large" and quantity >= 100:
impact_text = product.crowdfunding_impact_text_passive_plural
quantity = int(quantity / 100)
donations.append({
"type": "donation",
"color": "grey",
"text": f"{int(donation.quantity)} "
f"{donation.product_id.crowdfunding_impact_text_passive_plural}"
if int(donation.quantity) > 1 else
f"{int(donation.quantity)} "
f"{donation.product_id.crowdfunding_impact_text_passive_singular}",
"image": donation.product_id.image_medium,
"text": f"{int(quantity)} {impact_text}",
"image": donation.product_id.image_small,
"benefactor": donation.invoice_id.partner_id.firstname,
"date": donation.invoice_id.create_date,
"time_ago": self.get_time_ago(donation.invoice_id.create_date),
"anonymous": donation.is_anonymous,
"quantity": int(donation.quantity)
}
for donation in invoice_line_ids.filtered(
lambda l: l.state == "paid")
]
"quantity": int(quantity)
})
return sponsorships, donations

def get_impact(self, sponsorships, donations):
Expand Down
4 changes: 4 additions & 0 deletions crowdfunding_compassion/forms/project_creation_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ def form_before_create_or_update(self, values, extra_values):

if not product_goal:
values["product_id"] = False
if product_goal and values["product_id"]:
product = self.env["product.product"].sudo().browse(values["product_id"])
if product.impact_type == "large":
extra_values["participant_product_number_goal"] = product_goal * 100
super().form_before_create_or_update(values, extra_values)

def _form_create(self, values):
Expand Down
10 changes: 9 additions & 1 deletion crowdfunding_compassion/models/crowdfunding_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CrowdfundingProject(models.Model):
number_sponsorships_reached = fields.Integer(
"Sponsorships reached", compute="_compute_number_sponsorships_reached")
product_crowdfunding_impact = fields.Char(
related="product_id.crowdfunding_impact_text_passive_plural")
compute="_compute_impact_text")
color_sponsorship = fields.Char(compute="_compute_color_sponsorship")
color_product = fields.Char(compute="_compute_color_product")
color = fields.Integer(
Expand Down Expand Up @@ -193,6 +193,14 @@ def _compute_number_participants(self):
for project in self:
project.number_participants = len(project.participant_ids)

def _compute_impact_text(self):
for project in self:
product = project.product_id
project.product_crowdfunding_impact = \
product.crowdfunding_impact_text_passive_singular \
if product.impact_type == "large"\
else product.crowdfunding_impact_text_passive_plural

@api.model
def create(self, vals):
res = super().create(vals)
Expand Down
37 changes: 29 additions & 8 deletions crowdfunding_compassion/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,44 @@ class ProductTemplate(models.Model):
_inherit = "product.template"

activate_for_crowdfunding = fields.Boolean()
crowdfunding_description = fields.Text(translate=True)
crowdfunding_quantity_singular = fields.Char(translate=True, help="Ex: toilet")
crowdfunding_quantity_plural = fields.Char(translate=True, help="Ex: toilets")
impact_type = fields.Selection([
("standard", "Standard"),
("large", "Large impact project")
],
help="Use large impact if the project goals should be displayed in terms "
"of percentage.",
default="standard"
)
crowdfunding_description = fields.Text(
translate=True,
help="Description of the fund visible on Homepage"
)
crowdfunding_quantity_singular = fields.Char(
translate=True,
help="Visible when choosing donation quantity 1 or when "
"displaying project goal equivalence for 1 quantity.")
crowdfunding_quantity_plural = fields.Char(
translate=True,
help="Visible when choosing donation quantity or setting project goal "
"for large impact projects.")
crowdfunding_impact_text_active = fields.Char(
translate=True, help="Ex: buildling toilets"
translate=True, help="Fund title on TOGETHER"
)
crowdfunding_impact_text_passive_singular = fields.Char(
translate=True, help="Ex: toilet built"
translate=True,
help="Shown on barometers when impact is 1 or less."
)
crowdfunding_impact_text_passive_plural = fields.Char(
translate=True, help="Ex: toilets built"
translate=True,
help="Shown on barometers when impact is more than 1."
)
fund_selector_pre_description = fields.Char(
translate=True, help="Ex: I want to give access to toilets for"
translate=True,
help="Shown when setting the goal of a project, before the quantity field."
)
fund_selector_post_description = fields.Char(
translate=True, help="Ex: children"
translate=True,
help="Shown when setting the goal of a project, after the quantity field."
)
image_large = fields.Binary(
"Large image", help="Image for header", attachment=True
Expand Down
32 changes: 21 additions & 11 deletions crowdfunding_compassion/templates/crowdfunding_components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
<div class="goal-progress__text-tile">
<img class="goal-progress__icon" t-attf-src="data:image/png;base64, #{ goal_image }" t-if="isinstance(goal_image, bytes)"/>
<img class="goal-progress__icon" t-att-src="goal_image" t-if="isinstance(goal_image, str)"/>
<t t-if="impact_type == 'large' and goal_reached &gt; 100">
<t t-set="goal_reached" t-value="int(goal_reached / 100)"/>
<t t-set="goal_objective" t-value="int(goal_objective / 100)"/>
</t>
<div>
<span class="text--bold">
<t t-esc="goal_reached"/>
<t t-esc="goal_name"/>
</span>
<span class="text--faded">
out of
<t t-esc="goal_objective"/>
</span>
<t t-if="impact_type != 'large'">
<span class="text--faded">
out of
<t t-esc="goal_objective"/>
</span>
</t>
</div>
</div>
<div class="goal-progress__bar mb-3 mt-1">
Expand Down Expand Up @@ -50,12 +56,14 @@
<t t-set="goal_reached" t-value="project.number_sponsorships_reached"/>
<t t-set="goal_objective" t-value="project.number_sponsorships_goal"/>
<t t-set="goal_image" t-value="'/crowdfunding_compassion/static/src/img/icn_children.png'"/>
<t t-set="impact_type">sponsorship</t>
<t t-call="crowdfunding_compassion.goal_progress" t-if="goal_objective"/>
</t>

<!-- Setup data and display the fund progress -->
<t t-if="project.product_id">
<t t-if="project.product_number_reached > 1">
<t t-set="impact_type" t-value="project.product_id.impact_type"/>
<t t-if="(impact_type == 'standard' and project.product_number_reached > 1) or project.product_number_reached > 100">
<t t-set="goal_name" t-value="project.product_id.crowdfunding_impact_text_passive_plural"/>
</t>
<t t-else="">
Expand Down Expand Up @@ -120,10 +128,12 @@
<t t-set="goal_reached" t-value="participant.number_sponsorships_reached"/>
<t t-set="goal_objective" t-value="participant.number_sponsorships_goal"/>
<t t-set="goal_image" t-value="'/crowdfunding_compassion/static/src/img/icn_children.png'"/>
<t t-set="impact_type">sponsorship</t>
<t t-call="crowdfunding_compassion.goal_progress" t-if="goal_objective"/>

<!-- Setup data and display the fund progress -->
<t t-if="project.product_number_reached > 1">
<t t-set="impact_type" t-value="project.product_id.impact_type"/>
<t t-if="(impact_type == 'standard' and project.product_number_reached > 1) or project.product_number_reached > 100">
<t t-set="goal_name" t-value="project.product_id.crowdfunding_impact_text_passive_plural"/>
</t>
<t t-else="">
Expand Down Expand Up @@ -315,19 +325,19 @@
<!-- Displays a card with a possible donation, for example: 1 toilet - 25CHF -->
<template id="fund_amount_example" name="Fund amount example">
<!-- Compute value -->
<t t-set="current_value" t-value="project.product_id.standard_price * current_default_quantity"/>

<t t-set="product" t-value="project.product_id"/>
<t t-set="current_value" t-value="product.standard_price * current_default_quantity"/>
<t t-set="plural" t-values="current_default_quantity > 1 if product.impact_type == 'standard' else current_default_quantity > 100"/>
<div class="col-6 col-lg-6 mb-3">
<label class="h-100 w-100">
<input type="radio" name="amount" t-att-value="current_value" class="card-input-element d-none" />
<div class="card h-100 d-flex justify-content-around align-items-center text-center">
<img class="donation-type__card-icon" t-attf-src="data:image/png;base64, #{ project.product_id.image_medium }" t-if="isinstance(project.product_id.image_medium, bytes)"/>
<img class="donation-type__card-icon" t-attf-src="data:image/png;base64, #{ product.image_medium }" t-if="isinstance(product.image_medium, bytes)"/>
<img class="donation-type__card-icon"
src="/crowdfunding_compassion/static/src/img/icn_children.png" t-else=""/>
<h3 class="blue">
<t t-esc="current_default_quantity"/>
<t t-esc="project.product_id.crowdfunding_quantity_singular" t-if="current_default_quantity == 1" />
<t t-esc="project.product_id.crowdfunding_quantity_plural" t-if="current_default_quantity > 1" />
<t t-esc="product.crowdfunding_quantity_plural if plural else product.crowdfunding_quantity_singular"/>
<br/>
CHF
<t t-esc="str(int(current_value)) + '.-'"/>
Expand Down
10 changes: 5 additions & 5 deletions crowdfunding_compassion/templates/homepage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@

<div class="container mb-5 pb-5">
<div class="row">
<t t-foreach="impact" t-as="fund">
<t t-set="fund_image" t-value="impact[fund]['header_image']"/>
<t t-set="fund_icon" t-value="impact[fund]['icon_image']" />
<t t-set="fund_name" t-value="impact[fund]['name']" />
<t t-set="fund_description" t-value="impact[fund]['description']" />
<t t-foreach="active_funds" t-as="fund">
<t t-set="fund_image" t-value="fund['header_image']"/>
<t t-set="fund_icon" t-value="fund['icon_image']" />
<t t-set="fund_name" t-value="fund['name']" />
<t t-set="fund_description" t-value="fund['description']" />
<div class="col-sm-12 col-md-6 col-lg-4 mb-3">
<t t-call="crowdfunding_compassion.fund_card"/>
</div>
Expand Down
4 changes: 3 additions & 1 deletion crowdfunding_compassion/templates/presentation_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
<t t-set="goal_reached" t-value="participant.number_sponsorships_reached"/>
<t t-set="goal_objective" t-value="participant.number_sponsorships_goal"/>
<t t-set="goal_image" t-value="'/crowdfunding_compassion/static/src/img/icn_children.png'"/>
<t t-set="impact_type">sponsorship</t>
<t t-call="crowdfunding_compassion.goal_progress" t-if="goal_objective"/>

<!-- Setup data and display the fund progress -->
<t t-if="project.product_number_reached > 1">
<t t-set="impact_type" t-value="project.product_id.impact_type"/>
<t t-if="(impact_type == 'standard' and project.product_number_reached > 1) or project.product_number_reached > 100">
<t t-set="goal_name" t-value="project.product_id.crowdfunding_impact_text_passive_plural"/>
</t>
<t t-else="">
Expand Down
4 changes: 2 additions & 2 deletions crowdfunding_compassion/templates/project_creation_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@
</div>
<p class="card-text text-white">
<span class="white">Indicate the amount in the above box. 1</span>
<t t-esc="fund.crowdfunding_quantity_singular" class="white"/>
<t t-esc="fund.crowdfunding_quantity_singular if fund.impact_type == 'standard' else fund.crowdfunding_quantity_plural" class="white"/>
<span class="white">is equivalent to CHF</span>
<t t-esc="int(fund.standard_price)" class="white"/>.-
<t t-esc="int(fund.standard_price) * (1 if fund.impact_type == 'standard' else 100)" class="white"/>.-
</p>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions crowdfunding_compassion/views/product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<field name="activate_for_crowdfunding"/>
</group>
<group attrs="{'invisible': [('activate_for_crowdfunding', '=', False)]}">
<field name="impact_type"/>
<field name="crowdfunding_description"/>
<field name="crowdfunding_quantity_singular"/>
<field name="crowdfunding_quantity_plural"/>
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 @@ -38,6 +38,7 @@
"security/ir.model.access.csv",
"security/access_rules.xml",
"data/smart_tags.xml",
"data/queue_job.xml",
"views/mass_mailing_view.xml",
"views/mail_template_view.xml",
"views/utm_view.xml",
Expand Down
Loading

0 comments on commit f3fdb0d

Please sign in to comment.