|
@ -5,6 +5,7 @@ import werkzeug |
|
|
from odoo.tools import format_datetime, format_date, is_html_empty |
|
|
from odoo.tools import format_datetime, format_date, is_html_empty |
|
|
from odoo.exceptions import UserError |
|
|
from odoo.exceptions import UserError |
|
|
from odoo.addons.website_event.controllers.main import WebsiteEventController |
|
|
from odoo.addons.website_event.controllers.main import WebsiteEventController |
|
|
|
|
|
from odoo.osv import expression |
|
|
|
|
|
|
|
|
class kalachakra_event(WebsiteEventController): |
|
|
class kalachakra_event(WebsiteEventController): |
|
|
|
|
|
|
|
@ -38,3 +39,152 @@ class kalachakra_event(WebsiteEventController): |
|
|
return http.request.redirect('https://www.dropbox.com/s/ijsd6n82oyp0gw8/programme_Paris.pdf?dl=0') |
|
|
return http.request.redirect('https://www.dropbox.com/s/ijsd6n82oyp0gw8/programme_Paris.pdf?dl=0') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@http.route(['/kalachakra/makedonation'], type='http', auth='public', website=True, sitemap=False,csrf=False) |
|
|
|
|
|
def makedonation(self,**post): |
|
|
|
|
|
data={} |
|
|
|
|
|
|
|
|
|
|
|
userid=request.env.context.get('uid') |
|
|
|
|
|
#title options |
|
|
|
|
|
title=request.env['res.partner.title'].sudo().search([]) |
|
|
|
|
|
data['titles']=title |
|
|
|
|
|
title_male=request.env['res.partner.title'].sudo().search([('name','=','Monsieur')]) |
|
|
|
|
|
#country options |
|
|
|
|
|
country=request.env['res.country'].sudo().search([]) |
|
|
|
|
|
data['countries']=country |
|
|
|
|
|
country_france=request.env['res.country'].sudo().search([('name','=','France')]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if userid: |
|
|
|
|
|
user=request.env['res.users'].search([('id','=',int(userid))]) |
|
|
|
|
|
partner=request.env['res.partner'].sudo().search([('id','=',int(user.partner_id))]) |
|
|
|
|
|
request.session['partner_id']=int(partner.id) |
|
|
|
|
|
data['partner']=partner |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
partner=request.env['res.partner'] |
|
|
|
|
|
partner.email='' |
|
|
|
|
|
partner.title=title_male.id |
|
|
|
|
|
partner.country_id=country_france.id |
|
|
|
|
|
|
|
|
|
|
|
partner.firstname='' |
|
|
|
|
|
partner.name='' |
|
|
|
|
|
partner.street='' |
|
|
|
|
|
partner.street2='' |
|
|
|
|
|
partner.zip='' |
|
|
|
|
|
|
|
|
|
|
|
data['partner']=partner |
|
|
|
|
|
|
|
|
|
|
|
data['amount']=10 |
|
|
|
|
|
|
|
|
|
|
|
data['acquirers'] = list(request.env['payment.acquirer'].search([ |
|
|
|
|
|
('state', 'in', ['enabled', 'test']),('company_id', '=', request.env.company.id) |
|
|
|
|
|
])) |
|
|
|
|
|
|
|
|
|
|
|
#récupération du jeton de paiement |
|
|
|
|
|
# data['tokens'] = request.env['payment.token'].search([ |
|
|
|
|
|
# ('acquirer_id', 'in', acquirers.ids),('partner_id', '=', partner.id)]]) |
|
|
|
|
|
payment_tokens = partner.payment_token_ids |
|
|
|
|
|
payment_tokens |= partner.commercial_partner_id.sudo().payment_token_ids |
|
|
|
|
|
|
|
|
|
|
|
data['payment_tokens']=payment_tokens |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return http.request.render('kalachakra.makedonation_form',data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
http.route('/kalachakra/payment/token', type='http', auth='public', website=True, sitemap=False) |
|
|
|
|
|
def payment_token(self, pm_id=None, **kwargs): |
|
|
|
|
|
""" Method that handles payment using saved tokens |
|
|
|
|
|
|
|
|
|
|
|
:param int pm_id: id of the payment.token that we want to use to pay. |
|
|
|
|
|
""" |
|
|
|
|
|
order = request.website.sale_get_order() |
|
|
|
|
|
# do not crash if the user has already paid and try to pay again |
|
|
|
|
|
if not order: |
|
|
|
|
|
return request.redirect('/shop/?error=no_order') |
|
|
|
|
|
|
|
|
|
|
|
assert order.partner_id.id != request.website.partner_id.id |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
pm_id = int(pm_id) |
|
|
|
|
|
except ValueError: |
|
|
|
|
|
return request.redirect('/shop/?error=invalid_token_id') |
|
|
|
|
|
|
|
|
|
|
|
# We retrieve the token the user want to use to pay |
|
|
|
|
|
if not request.env['payment.token'].sudo().search_count([('id', '=', pm_id)]): |
|
|
|
|
|
return request.redirect('/shop/?error=token_not_found') |
|
|
|
|
|
|
|
|
|
|
|
# Create transaction |
|
|
|
|
|
vals = {'payment_token_id': pm_id, 'return_url': '/shop/payment/validate'} |
|
|
|
|
|
|
|
|
|
|
|
tx = order._create_payment_transaction(vals) |
|
|
|
|
|
PaymentProcessing.add_payment_transaction(tx) |
|
|
|
|
|
return request.redirect('/payment/process') |
|
|
|
|
|
|
|
|
|
|
|
@http.route(['/kalachakra/payment/process'], type="http", auth="public", website=True, sitemap=False) |
|
|
|
|
|
def payment_status_page(self, **kwargs): |
|
|
|
|
|
# When the customer is redirect to this website page, |
|
|
|
|
|
# we retrieve the payment transaction list from his session |
|
|
|
|
|
tx_ids_list = self.get_payment_transaction_ids() |
|
|
|
|
|
payment_transaction_ids = request.env['payment.transaction'].sudo().browse(tx_ids_list).exists() |
|
|
|
|
|
|
|
|
|
|
|
render_ctx = { |
|
|
|
|
|
'payment_tx_ids': payment_transaction_ids.ids, |
|
|
|
|
|
} |
|
|
|
|
|
return request.render("payment.payment_process_page", render_ctx) |
|
|
|
|
|
|
|
|
|
|
|
@http.route('/shop/payment/validate', type='http', auth="public", website=True, sitemap=False) |
|
|
|
|
|
def payment_validate(self, transaction_id=None, sale_order_id=None, **post): |
|
|
|
|
|
""" Method that should be called by the server when receiving an update |
|
|
|
|
|
for a transaction. State at this point : |
|
|
|
|
|
|
|
|
|
|
|
- UDPATE ME |
|
|
|
|
|
""" |
|
|
|
|
|
if sale_order_id is None: |
|
|
|
|
|
order = request.website.sale_get_order() |
|
|
|
|
|
else: |
|
|
|
|
|
order = request.env['sale.order'].sudo().browse(sale_order_id) |
|
|
|
|
|
assert order.id == request.session.get('sale_last_order_id') |
|
|
|
|
|
|
|
|
|
|
|
if transaction_id: |
|
|
|
|
|
tx = request.env['payment.transaction'].sudo().browse(transaction_id) |
|
|
|
|
|
assert tx in order.transaction_ids() |
|
|
|
|
|
elif order: |
|
|
|
|
|
tx = order.get_portal_last_transaction() |
|
|
|
|
|
else: |
|
|
|
|
|
tx = None |
|
|
|
|
|
|
|
|
|
|
|
if not order or (order.amount_total and not tx): |
|
|
|
|
|
return request.redirect('/shop') |
|
|
|
|
|
|
|
|
|
|
|
if order and not order.amount_total and not tx: |
|
|
|
|
|
order.with_context(send_email=True).action_confirm() |
|
|
|
|
|
return request.redirect(order.get_portal_url()) |
|
|
|
|
|
|
|
|
|
|
|
# clean context and session, then redirect to the confirmation page |
|
|
|
|
|
request.website.sale_reset() |
|
|
|
|
|
if tx and tx.state == 'draft': |
|
|
|
|
|
return request.redirect('/shop') |
|
|
|
|
|
|
|
|
|
|
|
PaymentProcessing.remove_payment_transaction(tx) |
|
|
|
|
|
return request.redirect('/shop/confirmation') |
|
|
|
|
|
|
|
|
|
|
|
@http.route(['/shop/confirmation'], type='http', auth="public", website=True, sitemap=False) |
|
|
|
|
|
def payment_confirmation(self, **post): |
|
|
|
|
|
""" End of checkout process controller. Confirmation is basically seing |
|
|
|
|
|
the status of a sale.order. State at this point : |
|
|
|
|
|
|
|
|
|
|
|
- should not have any context / session info: clean them |
|
|
|
|
|
- take a sale.order id, because we request a sale.order and are not |
|
|
|
|
|
session dependant anymore |
|
|
|
|
|
""" |
|
|
|
|
|
sale_order_id = request.session.get('sale_last_order_id') |
|
|
|
|
|
if sale_order_id: |
|
|
|
|
|
order = request.env['sale.order'].sudo().browse(sale_order_id) |
|
|
|
|
|
return request.render("website_sale.confirmation", {'order': order}) |
|
|
|
|
|
else: |
|
|
|
|
|
return request.redirect('/shop') |