Skip to content

Commit

Permalink
T1826 T1845 FIX barometers regardless of quantity
Browse files Browse the repository at this point in the history
- Base barometers only on donation amount and not on quantity.
- This functions better with the new way to display the cart with quantities adjusted to 1 when giving a custom amount.
  • Loading branch information
ecino committed Sep 24, 2024
1 parent 1631700 commit 59c06db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion crowdfunding_compassion/models/crowdfunding_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def _compute_product_number_reached(self):
invl = participant.invoice_line_ids.filtered(
lambda line: line.payment_state == "paid"
)
participant.product_number_reached = int(sum(invl.mapped("quantity")))
price_total = sum(invl.mapped("price_total"))
standard_price = participant.project_id.product_id.standard_price
participant.product_number_reached = round(price_total / standard_price)

def _compute_sponsorships(self):
for participant in self:
Expand Down
12 changes: 7 additions & 5 deletions crowdfunding_compassion/models/crowdfunding_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _compute_product_number_reached(self):
# Compute with SQL query for good performance
self.env.cr.execute(
"""
SELECT p.id, SUM(il.price_total), SUM(il.quantity)
SELECT p.id, SUM(il.price_total)
FROM account_move_line il
JOIN crowdfunding_participant pa ON pa.id = il.crowdfunding_participant_id
JOIN crowdfunding_project p ON p.id = pa.project_id
Expand All @@ -296,11 +296,13 @@ def _compute_product_number_reached(self):
""",
[self.ids],
)
results = {r[0]: (r[1], r[2]) for r in self.env.cr.fetchall()}
results = {r[0]: r[1] for r in self.env.cr.fetchall()}
for project in self:
res = results.get(project.id, (0, 0))
project.amount_reached = round(res[0])
project.product_number_reached = round(res[1])
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
)

def _compute_number_sponsorships_goal(self):
for project in self:
Expand Down
10 changes: 6 additions & 4 deletions website_event_compassion/models/event_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,27 +634,29 @@ def create_trip_invoice(self):
lambda t: t.product_id.product_tmpl_id == single_room_cost
)
if travel_ticket and not registration.trip_invoice_id:
product = travel_ticket.product_id
invoice_lines = [
(
0,
0,
{
"product_id": travel_ticket.product_id.id,
"account_id": travel_ticket.product_id.property_account_income_id.id,
"product_id": product.id,
"account_id": product.property_account_income_id.id,
"name": travel_ticket.name,
"price_unit": travel_ticket.price,
"quantity": 1,
},
),
]
if registration.single_room and room_ticket:
product = room_ticket.product_id
invoice_lines.append(
(
0,
0,
{
"product_id": room_ticket.product_id.id,
"account_id": room_ticket.product_id.property_account_income_id.id,
"product_id": product.id,
"account_id": product.property_account_income_id.id,
"name": room_ticket.name,
"price_unit": room_ticket.price,
"quantity": 1,
Expand Down

0 comments on commit 59c06db

Please sign in to comment.