Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions my_compassion/controllers/my2_donations.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def my2_gifts_thank_you_page(self, **kwargs):
def _extract_donation_order_line_fields(product_template, post):
# Compute quantity
price = 0
amount = post.get("suggested_amount")
if amount == "custom":
amount_type = post.get("suggested_amount")
if amount_type == "custom":
try:
price = float(post.get("custom_amount"))
except (ValueError, TypeError) as e:
Expand All @@ -333,15 +333,15 @@ def _extract_donation_order_line_fields(product_template, post):
if price <= 0:
raise BadRequest()
else:
quantities = {
"low": product_template.my_compassion_donation_quantity_low,
"medium": product_template.my_compassion_donation_quantity_medium,
"high": product_template.my_compassion_donation_quantity_high,
amounts = {
"low": product_template.my_compassion_donation_amount_low,
"medium": product_template.my_compassion_donation_amount_medium,
"high": product_template.my_compassion_donation_amount_high,
}
quantity = quantities.get(amount)
if not quantity:
price = amounts.get(amount_type)

if price is None or price <= 0:
raise BadRequest()
price = quantity * product_template.list_price

# Get frequency
frequency = post.get("frequency")
Expand All @@ -350,6 +350,7 @@ def _extract_donation_order_line_fields(product_template, post):
order_line_fields = {
"product_id": product.id,
"price_unit": price,
"product_uom_qty": 1.0,
"frequency": frequency,
}
if product_template.my_compassion_donation_type == "gift":
Expand Down
21 changes: 15 additions & 6 deletions my_compassion/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,25 @@ class ProductTemplate(models.Model):
)

# Donation suggestions
my_compassion_donation_quantity_low = fields.Integer(
default=1, help="Lowest quantity suggestion when making a donation"
my_compassion_donation_amount_low = fields.Monetary(
string="Lowest Amount",
currency_field="currency_id",
default=15.0,
help="Lowest price suggestion when making a donation",
)

my_compassion_donation_quantity_medium = fields.Integer(
default=3, help="Medium quantity suggestion when making a donation"
my_compassion_donation_amount_medium = fields.Monetary(
string="Medium Amount",
currency_field="currency_id",
default=50.0,
help="Medium price suggestion when making a donation",
)

my_compassion_donation_quantity_high = fields.Integer(
default=5, help="Highest quantity suggestion when making a donation"
my_compassion_donation_amount_high = fields.Monetary(
string="Highest Amount",
currency_field="currency_id",
default=100.0,
help="Highest price suggestion when making a donation",
)

def get_donation_limits(self, company, partner, sponsorship_id=None):
Expand Down
15 changes: 3 additions & 12 deletions my_compassion/templates/components/my2_donation_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@
class="suggested-amount"
/>
<label class="mb-0 w-100" t-attf-for="#{base_name}-suggested-low">
<t
t-set="price"
t-value="product.my_compassion_donation_quantity_low * product.list_price"
/>
<t t-set="price" t-value="product.my_compassion_donation_amount_low" />
<t t-esc="product.currency_id.name" />
<t t-if="price % 1 == 0" t-esc="int(price)" />
<t t-else="" t-esc="'{0:.2f}'.format(price)" />
Expand All @@ -137,10 +134,7 @@
class="suggested-amount"
/>
<label class="mb-0 w-100" t-attf-for="#{base_name}-suggested-medium">
<t
t-set="price"
t-value="product.my_compassion_donation_quantity_medium * product.list_price"
/>
<t t-set="price" t-value="product.my_compassion_donation_amount_medium" />
<t t-esc="product.currency_id.name" />
<t t-if="price % 1 == 0" t-esc="int(price)" />
<t t-else="" t-esc="'{0:.2f}'.format(price)" />
Expand All @@ -156,10 +150,7 @@
class="suggested-amount"
/>
<label class="mb-0 w-100" t-attf-for="#{base_name}-suggested-high">
<t
t-set="price"
t-value="product.my_compassion_donation_quantity_high * product.list_price"
/>
<t t-set="price" t-value="product.my_compassion_donation_amount_high" />
<t t-esc="product.currency_id.name" />
<t t-if="price % 1 == 0" t-esc="int(price)" />
<t t-else="" t-esc="'{0:.2f}'.format(price)" />
Expand Down
5 changes: 1 addition & 4 deletions my_compassion/templates/components/my2_donation_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@
From
<span class="body-small bold">
<t t-esc="currency_name" />
<t
t-set="price"
t-value="product.my_compassion_donation_quantity_low * product.list_price"
/>
<t t-set="price" t-value="product.my_compassion_donation_amount_low" />
<t t-if="price % 1 == 0" t-set="price" t-value="'{0}.-'.format(int(price))" />
<t t-else="" t-set="price" t-value="'{0:.2f}'.format(price)" />
<t t-esc="price" />
Expand Down
6 changes: 3 additions & 3 deletions my_compassion/views/product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@
string="Suggested Donations"
attrs="{'invisible': [('activate_for_my_compassion', '=', False)]}"
>
<field name="my_compassion_donation_quantity_low" string="Lowest suggested quantity" />
<field name="my_compassion_donation_quantity_medium" string="Medium suggested quantity" />
<field name="my_compassion_donation_quantity_high" string="High suggested quantity" />
<field name="my_compassion_donation_amount_low" string="Lowest suggested amount" />
<field name="my_compassion_donation_amount_medium" string="Medium suggested amount" />
<field name="my_compassion_donation_amount_high" string="High suggested amount" />
</group>
</page>
</xpath>
Expand Down