Skip to content

Commit

Permalink
T1845 ADD product price on project
Browse files Browse the repository at this point in the history
- This enables setting custom prices for each project
  and avoids that the barometers change when we change
  a product price.
  • Loading branch information
ecino committed Sep 24, 2024
1 parent ee5ca5c commit fa62389
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
7 changes: 3 additions & 4 deletions crowdfunding_compassion/controllers/donation_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions crowdfunding_compassion/models/crowdfunding_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 9 additions & 3 deletions crowdfunding_compassion/models/crowdfunding_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions crowdfunding_compassion/views/crowdfunding_project_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
widget="many2one"
/>
</h3>
<label for="product_price" />
<h3>
<field name="product_price" />
</h3>
</div>
<div class="col">
<label for="product_number_reached" />
Expand Down

0 comments on commit fa62389

Please sign in to comment.