|
@ -2,6 +2,7 @@ |
|
|
from odoo import http |
|
|
from odoo import http |
|
|
from odoo.http import request |
|
|
from odoo.http import request |
|
|
import werkzeug |
|
|
import werkzeug |
|
|
|
|
|
from datetime import datetime |
|
|
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 |
|
@ -191,27 +192,58 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
payment_tokens |= partner.commercial_partner_id.sudo().payment_token_ids |
|
|
payment_tokens |= partner.commercial_partner_id.sudo().payment_token_ids |
|
|
|
|
|
|
|
|
data['payment_tokens']=payment_tokens |
|
|
data['payment_tokens']=payment_tokens |
|
|
|
|
|
|
|
|
#create sale order |
|
|
|
|
|
vals={} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#create donation |
|
|
|
|
|
vals={} |
|
|
vals['partner_id']=partner.id |
|
|
vals['partner_id']=partner.id |
|
|
order_draft=request.env['sale.order'].sudo().create(vals) |
|
|
|
|
|
data['order_id']=order_draft.id |
|
|
|
|
|
#création des lignes de devis |
|
|
|
|
|
|
|
|
vals['donation_date']=datetime.now() |
|
|
|
|
|
vals['tax_receipt_option']='annual' |
|
|
|
|
|
#mode de paiement CB |
|
|
|
|
|
electronic_method=request.env['account.payment.method'].search([('code','=','electronic')],limit=1) |
|
|
|
|
|
if electronic_method: |
|
|
|
|
|
cb_mode=request.env['account.payment.mode'].search([('payment_method_id','=',int(electronic_method.id))],limit=1) |
|
|
|
|
|
if cb_mode: |
|
|
|
|
|
vals['payment_mode_id']=cb_mode.id |
|
|
|
|
|
else: |
|
|
|
|
|
raise Warning('please configure credit card mode') |
|
|
|
|
|
vals['state']='draft' |
|
|
|
|
|
vals['payment_ref']='internet' |
|
|
|
|
|
donation_draft=request.env['donation.donation'].sudo().create(vals) |
|
|
vals={} |
|
|
vals={} |
|
|
vals['order_id']=order_draft.id |
|
|
|
|
|
#ajout du produit |
|
|
|
|
|
|
|
|
#create line donation |
|
|
|
|
|
vals['donation_id']=donation_draft.id |
|
|
|
|
|
product=request.env['product.product'].search([('id','=',int(post.get('product_id')))]) |
|
|
vals['product_id']=int(post.get('product_id')) |
|
|
vals['product_id']=int(post.get('product_id')) |
|
|
vals['product_uom_qty']=1 |
|
|
|
|
|
vals['price_unit']=post.get('amount') |
|
|
|
|
|
|
|
|
vals['display_name']=product.name |
|
|
|
|
|
vals['quantity']=1 |
|
|
|
|
|
vals['unit_price']=post.get('amount') |
|
|
|
|
|
vals['tax_receipt_ok']=product.tax_receipt_ok |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
donation_line=request.env['donation.line'].sudo().create(vals) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
product=request.env['product.product'].search([('id','=',int(post.get('product_id')))]) |
|
|
|
|
|
vals['name']=product.name |
|
|
|
|
|
|
|
|
#create sale order |
|
|
|
|
|
# vals={} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# vals['partner_id']=partner.id |
|
|
|
|
|
# order_draft=request.env['sale.order'].sudo().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('product_id')) |
|
|
|
|
|
# vals['product_uom_qty']=1 |
|
|
|
|
|
# vals['price_unit']=post.get('amount') |
|
|
|
|
|
|
|
|
|
|
|
# product=request.env['product.product'].search([('id','=',int(post.get('product_id')))]) |
|
|
|
|
|
# vals['name']=product.name |
|
|
|
|
|
|
|
|
order_line=request.env['sale.order.line'].sudo().create(vals) |
|
|
|
|
|
|
|
|
# order_line=request.env['sale.order.line'].sudo().create(vals) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data['order_id']=donation_draft.id |
|
|
|
|
|
|
|
|
return http.request.render('kalachakra.payment_choice_form',data) |
|
|
return http.request.render('kalachakra.payment_choice_form',data) |
|
|
|
|
|
|
|
@ -229,7 +261,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
user is redirected to the checkout page |
|
|
user is redirected to the checkout page |
|
|
""" |
|
|
""" |
|
|
# Ensure a payment acquirer is selected |
|
|
# Ensure a payment acquirer is selected |
|
|
|
|
|
|
|
|
|
|
|
donation_id=order_id |
|
|
if not acquirer_id: |
|
|
if not acquirer_id: |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
@ -239,23 +271,15 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
return False |
|
|
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() |
|
|
|
|
|
|
|
|
# Retrieve the donation |
|
|
|
|
|
donation=request.env['donation.donation'].search([('id','=',int(donation_id))], limit=1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Ensure there is something to proceed |
|
|
# Ensure there is something to proceed |
|
|
if not order or (order and not order.order_line): |
|
|
|
|
|
|
|
|
if not donation or (donation and not donation.line_ids): |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
assert order.partner_id.id != request.website.partner_id.id |
|
|
|
|
|
|
|
|
assert donation.partner_id.id != request.website.partner_id.id |
|
|
|
|
|
|
|
|
# Create transaction |
|
|
# Create transaction |
|
|
vals = {'acquirer_id': acquirer_id, |
|
|
vals = {'acquirer_id': acquirer_id, |
|
@ -266,7 +290,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
if token: |
|
|
if token: |
|
|
vals['payment_token_id'] = int(token) |
|
|
vals['payment_token_id'] = int(token) |
|
|
|
|
|
|
|
|
transaction = order._create_payment_transaction(vals) |
|
|
|
|
|
|
|
|
transaction = donation._create_payment_transaction(vals) |
|
|
|
|
|
|
|
|
# store the new transaction into the transaction list and if there's an old one, we remove it |
|
|
# 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 |
|
|
# until the day the ecommerce supports multiple orders at the same time |
|
@ -276,7 +300,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
PaymentProcessing.remove_payment_transaction(last_tx) |
|
|
PaymentProcessing.remove_payment_transaction(last_tx) |
|
|
PaymentProcessing.add_payment_transaction(transaction) |
|
|
PaymentProcessing.add_payment_transaction(transaction) |
|
|
request.session['__website_sale_last_tx_id'] = transaction.id |
|
|
request.session['__website_sale_last_tx_id'] = transaction.id |
|
|
return transaction.render_sale_button(order) |
|
|
|
|
|
|
|
|
return transaction.render_donation_button(donation) |
|
|
|
|
|
|
|
|
http.route('/kalachakra/payment/token', type='http', auth='public', website=True, sitemap=False) |
|
|
http.route('/kalachakra/payment/token', type='http', auth='public', website=True, sitemap=False) |
|
|
def kalachakra_payment_token(self, pm_id=None, **kwargs): |
|
|
def kalachakra_payment_token(self, pm_id=None, **kwargs): |
|
@ -285,14 +309,6 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
:param int pm_id: id of the payment.token that we want to use to pay. |
|
|
: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: |
|
|
try: |
|
|
pm_id = int(pm_id) |
|
|
pm_id = int(pm_id) |
|
|
except ValueError: |
|
|
except ValueError: |
|
@ -305,7 +321,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
# Create transaction |
|
|
# Create transaction |
|
|
vals = {'payment_token_id': pm_id, 'return_url': '/kalachakra/payment/validate'} |
|
|
vals = {'payment_token_id': pm_id, 'return_url': '/kalachakra/payment/validate'} |
|
|
|
|
|
|
|
|
tx = order._create_payment_transaction(vals) |
|
|
|
|
|
|
|
|
tx = donation._create_payment_transaction(vals) |
|
|
PaymentProcessing.add_payment_transaction(tx) |
|
|
PaymentProcessing.add_payment_transaction(tx) |
|
|
return request.redirect('kalachakra/payment/process') |
|
|
return request.redirect('kalachakra/payment/process') |
|
|
|
|
|
|
|
|