|
@ -5,8 +5,9 @@ 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.addons.payment.controllers.portal import PaymentProcessing |
|
|
|
|
|
|
|
|
class kalachakra_event(WebsiteEventController): |
|
|
|
|
|
|
|
|
class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
|
|
|
|
|
def _extract_searched_event_tags(self, searches): |
|
|
def _extract_searched_event_tags(self, searches): |
|
|
tags = request.env['event.tag'] |
|
|
tags = request.env['event.tag'] |
|
@ -38,3 +39,299 @@ 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return http.request.render('kalachakra.makedonation_form',data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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')]) |
|
|
|
|
|
#donation product |
|
|
|
|
|
donation_products=request.env['product.product'].search([('donation','=',True)]) |
|
|
|
|
|
|
|
|
|
|
|
data['donation_products']=donation_products |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return http.request.render('kalachakra.makedonation_form',data) |
|
|
|
|
|
|
|
|
|
|
|
@http.route(['/kalachakra/payment_choice'], type='http', auth='public', website=True, sitemap=False,csrf=False) |
|
|
|
|
|
def payment_choice(self,**post): |
|
|
|
|
|
userid=request.env.context.get('uid') |
|
|
|
|
|
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) |
|
|
|
|
|
else: |
|
|
|
|
|
a=1 |
|
|
|
|
|
#si pas connecté on chercher le contact indiqué par l'email |
|
|
|
|
|
#si pas de contact on le créé dans la base |
|
|
|
|
|
|
|
|
|
|
|
data={} |
|
|
|
|
|
data['success_url']='/kalachakra/payment/success' |
|
|
|
|
|
data['error_url']='/kalachakra/payment/error' |
|
|
|
|
|
|
|
|
|
|
|
data['acquirers'] = list(request.env['payment.acquirer'].search([ |
|
|
|
|
|
('state', 'in', ['enabled', 'test']),('company_id', '=', request.env.company.id) |
|
|
|
|
|
])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
payment_tokens = partner.payment_token_ids |
|
|
|
|
|
payment_tokens |= partner.commercial_partner_id.sudo().payment_token_ids |
|
|
|
|
|
|
|
|
|
|
|
data['payment_tokens']=payment_tokens |
|
|
|
|
|
|
|
|
|
|
|
#create sale order |
|
|
|
|
|
vals={} |
|
|
|
|
|
|
|
|
|
|
|
vals['partner_id']=partner.id |
|
|
|
|
|
order_draft=request.env['sale.order'].create(vals) |
|
|
|
|
|
data['order_id']=order_draft.id |
|
|
|
|
|
#création des lignes de devis |
|
|
|
|
|
vals={} |
|
|
|
|
|
vals['order_id']=order_draft.id |
|
|
|
|
|
#ajout du produit |
|
|
|
|
|
vals['product_id']=int(post.get('donation_product_id')) |
|
|
|
|
|
vals['product_uom_qty']=1 |
|
|
|
|
|
vals['price_unit']=post.get('amount') |
|
|
|
|
|
|
|
|
|
|
|
product=request.env['product.product'].search([('id','=',int(post.get('donation_product_id')))]) |
|
|
|
|
|
vals['name']=product.name |
|
|
|
|
|
|
|
|
|
|
|
order_line=request.env['sale.order.line'].create(vals) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return http.request.render('kalachakra.payment_choice_form',data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@http.route(['/kalachakra/payment/transaction/', |
|
|
|
|
|
'/kalachakra/payment/transaction/<int:so_id>', |
|
|
|
|
|
'/kalachakra/payment/transaction/<int:so_id>/<string:access_token>'], type='json', auth="public", website=True) |
|
|
|
|
|
def kalachakra_payment_transaction(self, acquirer_id,order_id, save_token=False, so_id=None, access_token=None, token=None, **kwargs): |
|
|
|
|
|
""" Json method that creates a payment.transaction, used to create a |
|
|
|
|
|
transaction when the user clicks on 'pay now' button. After having |
|
|
|
|
|
created the transaction, the event continues and the user is redirected |
|
|
|
|
|
to the acquirer website. |
|
|
|
|
|
|
|
|
|
|
|
:param int acquirer_id: id of a payment.acquirer record. If not set the |
|
|
|
|
|
user is redirected to the checkout page |
|
|
|
|
|
""" |
|
|
|
|
|
# Ensure a payment acquirer is selected |
|
|
|
|
|
|
|
|
|
|
|
if not acquirer_id: |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
acquirer_id = int(acquirer_id) |
|
|
|
|
|
except: |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Retrieve the sale order |
|
|
|
|
|
order=request.env['sale.order'].search([('id','=',int(order_id))], limit=1) |
|
|
|
|
|
# if so_id: |
|
|
|
|
|
# env = request.env['sale.order'] |
|
|
|
|
|
# domain = [('id', '=', so_id)] |
|
|
|
|
|
# if access_token: |
|
|
|
|
|
# env = env.sudo() |
|
|
|
|
|
# domain.append(('access_token', '=', access_token)) |
|
|
|
|
|
# order = env.search(domain, limit=1) |
|
|
|
|
|
# else: |
|
|
|
|
|
# order = request.website.sale_get_order() |
|
|
|
|
|
|
|
|
|
|
|
# Ensure there is something to proceed |
|
|
|
|
|
if not order or (order and not order.order_line): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
assert order.partner_id.id != request.website.partner_id.id |
|
|
|
|
|
|
|
|
|
|
|
# Create transaction |
|
|
|
|
|
vals = {'acquirer_id': acquirer_id, |
|
|
|
|
|
'return_url': '/kalachakra/payment/validate'} |
|
|
|
|
|
|
|
|
|
|
|
if save_token: |
|
|
|
|
|
vals['type'] = 'form_save' |
|
|
|
|
|
if token: |
|
|
|
|
|
vals['payment_token_id'] = int(token) |
|
|
|
|
|
|
|
|
|
|
|
transaction = order._create_payment_transaction(vals) |
|
|
|
|
|
|
|
|
|
|
|
# store the new transaction into the transaction list and if there's an old one, we remove it |
|
|
|
|
|
# until the day the ecommerce supports multiple orders at the same time |
|
|
|
|
|
last_tx_id = request.session.get('__website_sale_last_tx_id') |
|
|
|
|
|
last_tx = request.env['payment.transaction'].browse(last_tx_id).sudo().exists() |
|
|
|
|
|
if last_tx: |
|
|
|
|
|
PaymentProcessing.remove_payment_transaction(last_tx) |
|
|
|
|
|
PaymentProcessing.add_payment_transaction(transaction) |
|
|
|
|
|
request.session['__website_sale_last_tx_id'] = transaction.id |
|
|
|
|
|
return transaction.render_sale_button(order) |
|
|
|
|
|
|
|
|
|
|
|
http.route('/kalachakra/payment/token', type='http', auth='public', website=True, sitemap=False) |
|
|
|
|
|
def kalachakra_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': '/kalachakra/payment/validate'} |
|
|
|
|
|
|
|
|
|
|
|
tx = order._create_payment_transaction(vals) |
|
|
|
|
|
PaymentProcessing.add_payment_transaction(tx) |
|
|
|
|
|
return request.redirect('kalachakra/payment/process') |
|
|
|
|
|
|
|
|
|
|
|
@http.route(['/kalachakra/payment/process'], type="http", auth="public", website=True, sitemap=False) |
|
|
|
|
|
def kalachakra_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('/kalachakra/payment/validate', type='http', auth="public", website=True, sitemap=False) |
|
|
|
|
|
def kalachakra_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('/kalachakra/ma') |
|
|
|
|
|
|
|
|
|
|
|
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('/kalachakra/') |
|
|
|
|
|
|
|
|
|
|
|
PaymentProcessing.remove_payment_transaction(tx) |
|
|
|
|
|
return request.redirect('/kalachakra/payment/confirmation') |
|
|
|
|
|
|
|
|
|
|
|
@http.route(['/kalachakra/payment/confirmation'], type='http', auth="public", website=True, sitemap=False) |
|
|
|
|
|
def kalachakra_payment_confirmation(self, **post): |
|
|
|
|
|
|
|
|
|
|
|
return request.redirect('/') |
|
|
|
|
|
|
|
|
|
|
|
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') |