diff --git a/crowdfunding_compassion/controllers/donation_controller.py b/crowdfunding_compassion/controllers/donation_controller.py index 025ca71..a873aee 100644 --- a/crowdfunding_compassion/controllers/donation_controller.py +++ b/crowdfunding_compassion/controllers/donation_controller.py @@ -85,15 +85,14 @@ def post_donation_form(self, project, participant, amount, **post): if sale_order.state != "draft": request.session["sale_order_id"] = None sale_order = request.website.sale_get_order(force_create=True).sudo() - product = project.product_id - quantity = float(amount) / product.standard_price - price = product.standard_price + price = project.product_price + quantity = float(amount) / price if not quantity.is_integer(): quantity = 1 price = amount sale_order.add_donation( - product.id, + project.product_id.id, price, qty=quantity, participant_id=participant.id, diff --git a/crowdfunding_compassion/models/crowdfunding_participant.py b/crowdfunding_compassion/models/crowdfunding_participant.py index 261668e..857962b 100644 --- a/crowdfunding_compassion/models/crowdfunding_participant.py +++ b/crowdfunding_compassion/models/crowdfunding_participant.py @@ -122,8 +122,9 @@ def _compute_product_number_reached(self): lambda line: line.payment_state == "paid" ) price_total = sum(invl.mapped("price_total")) - standard_price = participant.project_id.product_id.standard_price or 1 - participant.product_number_reached = round(price_total / standard_price) + participant.product_number_reached = round( + price_total / participant.project_id.product_price + ) def _compute_sponsorships(self): for participant in self: diff --git a/crowdfunding_compassion/models/crowdfunding_project.py b/crowdfunding_compassion/models/crowdfunding_project.py index cb0799d..d230562 100644 --- a/crowdfunding_compassion/models/crowdfunding_project.py +++ b/crowdfunding_compassion/models/crowdfunding_project.py @@ -72,6 +72,9 @@ class CrowdfundingProject(models.Model): "Supported fund", domain=[("activate_for_crowdfunding", "=", True)], ) + product_price = fields.Float( + compute="_compute_product_price", store=True, readonly=False + ) product_number_goal = fields.Integer( "Product goal", compute="_compute_product_number_goal" ) @@ -207,6 +210,11 @@ def _compute_impact_text(self): else product.crowdfunding_impact_text_passive_plural ) + @api.depends("product_id") + def _compute_product_price(self): + for project in self: + project.product_price = project.product_id.standard_price or 1 + @api.model def create(self, vals): res = super().create(vals) @@ -300,9 +308,7 @@ def _compute_product_number_reached(self): for project in self: price_total = results.get(project.id, 0) project.amount_reached = round(price_total) - project.product_number_reached = round( - price_total / (project.product_id.standard_price or 1) - ) + project.product_number_reached = round(price_total / project.product_price) def _compute_number_sponsorships_goal(self): for project in self: diff --git a/crowdfunding_compassion/views/crowdfunding_project_view.xml b/crowdfunding_compassion/views/crowdfunding_project_view.xml index 17f830f..7512670 100644 --- a/crowdfunding_compassion/views/crowdfunding_project_view.xml +++ b/crowdfunding_compassion/views/crowdfunding_project_view.xml @@ -132,6 +132,10 @@ widget="many2one" /> +