Commit 27dab6a3 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Use price definiton from sale supply rather them the line

parent 7171eb27
......@@ -3,20 +3,14 @@ if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
current_invoice = context.getCausalityValue()
if current_invoice is None:
if target_language == "zh": # Wechat payment
invoice_template_path = portal.portal_preferences.getPreferredZhPrePaymentSubscriptionInvoiceTemplate()
else:
invoice_template_path = portal.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate()
invoice_template = portal.restrictedTraverse(invoice_template_path)
invoice_template = portal.restrictedTraverse(template)
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
context.edit(causality_value=current_invoice)
payment_transaction = invoice_template = portal.restrictedTraverse(payment)
payment_transaction = portal.restrictedTraverse(payment)
current_invoice.edit(
title="Reservation Fee",
destination_value=context.getDestinationSection(),
......@@ -25,9 +19,8 @@ if current_invoice is None:
start_date=payment_transaction.getStartDate(),
stop_date=payment_transaction.getStopDate(),
)
if not amount:
# this is supposed to be free, so turn price free.
current_invoice["1"].setPrice(0.0)
current_invoice["1"].setPrice(price)
current_invoice["1"].setQuantity(context.getQuantity())
comment = "Validation invoice for subscription request %s" % context.getRelativeUrl()
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>amount, tag, payment, target_language, REQUEST=None</string> </value>
<value> <string>price, tag, payment, template, REQUEST=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
......
......@@ -10,10 +10,12 @@ current_payment = None
if current_invoice is None:
if target_language == "zh": # Wechat payment, reservation fee is 188 CNY
payment_template = portal.restrictedTraverse(portal.portal_preferences.getPreferredZhPrePaymentTemplate())
invoice_template = portal.restrictedTraverse(portal.portal_preferences.getPreferredZhPrePaymentSubscriptionInvoiceTemplate())
else: # Payzen payment, reservation fee is 25 EUR
payment_template = portal.restrictedTraverse(portal.portal_preferences.getPreferredDefaultPrePaymentTemplate())
current_payment = payment_template.Base_createCloneDocument(batch_mode=1)
invoice_template = portal.restrictedTraverse(portal.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate())
current_payment = payment_template.Base_createCloneDocument(batch_mode=1)
current_payment.edit(
title="Payment for Reservation Fee",
destination_value=context.getDestinationSection(),
......@@ -26,12 +28,28 @@ if current_invoice is None:
amount = context.getQuantity()
if context.SubscriptionRequest_testSkippedReservationFree(contract):
# Reservation is Free
amount = 0
price = 0
tax = 0
else:
invoice_line = invoice_template["1"].asContext()
price = invoice_line.getResourceValue().getPrice(
context=invoice_line)
# We need to provide Price to pay right the way, so we need to include
# taxation at this point it is most liketly to quickly forecast price
# with taxes, but for now it is hardcoded.
tax = 0
if 'base_amount/invoicing/taxable' in invoice_line.getBaseContributionList():
tax = 0.2
for line in current_payment.contentValues():
if line.getSource() in ["account_module/payment_to_encash", "account_module/receivable"]:
quantity = int(amount) * line.getQuantity()
line.setQuantity(quantity)
if line.getSource() == "account_module/payment_to_encash":
total = round((-int(amount) * price)+(-int(amount) * price*tax), 2)
line.setQuantity(total)
elif line.getSource() == "account_module/receivable":
total = round((int(amount) * price)+(int(amount) * price*tax), 2)
line.setQuantity(total)
# Accelarate job of alarms before proceed to payment.
comment = "Validation payment for subscription request %s" % context.getRelativeUrl()
......@@ -46,6 +64,6 @@ if current_invoice is None:
context.reindexObject(activate_kw={'tag': tag})
context.activate(tag=tag).SubscriptionRequest_createRelatedSaleInvoiceTransaction(
amount, tag, current_payment.getRelativeUrl(), target_language)
price, tag, current_payment.getRelativeUrl(), invoice_template.getRelativeUrl())
return current_payment
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment