diff --git a/account_reconcile_compassion/__manifest__.py b/account_reconcile_compassion/__manifest__.py index 9d1eea13d..a5543a4df 100644 --- a/account_reconcile_compassion/__manifest__.py +++ b/account_reconcile_compassion/__manifest__.py @@ -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", diff --git a/account_reconcile_compassion/data/queue_job.xml b/account_reconcile_compassion/data/queue_job.xml new file mode 100644 index 000000000..00f5478fe --- /dev/null +++ b/account_reconcile_compassion/data/queue_job.xml @@ -0,0 +1,14 @@ + + + + reconcile_compassion + + + + + + + _process_reconciliation + + + \ No newline at end of file diff --git a/account_reconcile_compassion/models/bank_statement_line.py b/account_reconcile_compassion/models/bank_statement_line.py index fb5932a7d..b25ec4ba8 100644 --- a/account_reconcile_compassion/models/bank_statement_line.py +++ b/account_reconcile_compassion/models/bank_statement_line.py @@ -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__) @@ -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 ): diff --git a/crowdfunding_compassion/controllers/homepage_controller.py b/crowdfunding_compassion/controllers/homepage_controller.py index 6c561e3b8..dff209990 100644 --- a/crowdfunding_compassion/controllers/homepage_controller.py +++ b/crowdfunding_compassion/controllers/homepage_controller.py @@ -49,26 +49,33 @@ 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 @@ -76,8 +83,13 @@ def _compute_homepage_context(): 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: @@ -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, } diff --git a/crowdfunding_compassion/controllers/project_controller.py b/crowdfunding_compassion/controllers/project_controller.py index f253e4754..39b59b20b 100644 --- a/crowdfunding_compassion/controllers/project_controller.py +++ b/crowdfunding_compassion/controllers/project_controller.py @@ -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): diff --git a/crowdfunding_compassion/forms/project_creation_form.py b/crowdfunding_compassion/forms/project_creation_form.py index b3213ff3e..f0e7526b2 100644 --- a/crowdfunding_compassion/forms/project_creation_form.py +++ b/crowdfunding_compassion/forms/project_creation_form.py @@ -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): diff --git a/crowdfunding_compassion/models/crowdfunding_project.py b/crowdfunding_compassion/models/crowdfunding_project.py index 106e20854..c231d24e1 100644 --- a/crowdfunding_compassion/models/crowdfunding_project.py +++ b/crowdfunding_compassion/models/crowdfunding_project.py @@ -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( @@ -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) diff --git a/crowdfunding_compassion/models/product_template.py b/crowdfunding_compassion/models/product_template.py index 4cf0c0765..d3eae01ff 100644 --- a/crowdfunding_compassion/models/product_template.py +++ b/crowdfunding_compassion/models/product_template.py @@ -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 diff --git a/crowdfunding_compassion/templates/crowdfunding_components.xml b/crowdfunding_compassion/templates/crowdfunding_components.xml index fb66c43d8..4105dbce0 100644 --- a/crowdfunding_compassion/templates/crowdfunding_components.xml +++ b/crowdfunding_compassion/templates/crowdfunding_components.xml @@ -7,15 +7,21 @@
+ + + +
- - out of - - + + + out of + + +
@@ -50,12 +56,14 @@ + sponsorship - + + @@ -120,10 +128,12 @@ + sponsorship - + + @@ -315,19 +325,19 @@