|
|
@ -212,16 +212,50 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
if data['status']=='member':data['participation_amount']=int(event.participation_member_price) |
|
|
|
if data['status']=='super member':data['participation_amount']=int(event.participation_super_member_price) |
|
|
|
|
|
|
|
#enregistrement de l'inscription |
|
|
|
vals={} |
|
|
|
vals['event_id']=request.session['event_id'] |
|
|
|
vals['partner_id']=request.session['partner_id'] |
|
|
|
vals['online']=post.get('online') |
|
|
|
vals['state']='open' |
|
|
|
|
|
|
|
res=request.env['event.registration'].sudo().create(vals) |
|
|
|
#enregistrement de l'inscription si pas déjà inscrit : |
|
|
|
res=request.env['event.registration'].sudo().search([('event_id','=',int(request.session['event_id'])),('partner_id','=',int(request.session['partner_id']))],limit=1) |
|
|
|
data['already_registered']=True |
|
|
|
data['payment_status']=res.payment_status |
|
|
|
|
|
|
|
if not res: |
|
|
|
data['already_registered']=False |
|
|
|
vals={} |
|
|
|
vals['event_id']=request.session['event_id'] |
|
|
|
vals['partner_id']=request.session['partner_id'] |
|
|
|
vals['online']=post.get('online') |
|
|
|
vals['state']='open' |
|
|
|
|
|
|
|
res=request.env['event.registration'].sudo().create(vals) |
|
|
|
#création de la facture à régler |
|
|
|
invoice_id=request.env['event.registration'].sudo().action_generate_participation_invoice(int(res.id),'CB') |
|
|
|
|
|
|
|
request.session['res_id']=res.id |
|
|
|
|
|
|
|
#inscription à la newsletter attachée à l'événement |
|
|
|
partner=request.env['res.partner'].sudo().search([('id','=',int(request.session['partner_id']))]) |
|
|
|
mailing_contact=request.env['mailing.contact'].sudo().search([('email','=',partner.email)]) |
|
|
|
if not mailing_contact: |
|
|
|
vals={} |
|
|
|
vals['email']=partner.email |
|
|
|
vals['name']=partner.name+' '+str(partner.firstname) |
|
|
|
vals['title_id']=partner.title |
|
|
|
vals['country_id']=int(partner.country_id) |
|
|
|
vals['list_ids']=[(4,int(event.recurring_event_newsletter_id))] |
|
|
|
mailing_contact=request.env['mailing.contact'].sudo().create(vals) |
|
|
|
|
|
|
|
if event.recurring_event_newsletter_id: |
|
|
|
if not event.recurring_event_newsletter_id in mailing_contact.list_ids: |
|
|
|
mailing_contact.sudo().write({'list_ids':[(4,int(event.recurring_event_newsletter_id))]}) |
|
|
|
|
|
|
|
#inscription à la newsletter générale |
|
|
|
mailing_list=request.env['mailing.list'].sudo().search([('name','=','Newsletter '+request.env.company.name)]) |
|
|
|
if mailing_list: |
|
|
|
if not mailing_list in mailing_contact.list_ids: |
|
|
|
mailing_contact.sudo().write({'list_ids':[(4,int(mailing_list.id))]}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return http.request.render('kalachakra.registration_step2',data) |
|
|
|
|
|
|
|
@http.route(['/kalachakra/onthespotpayment'], type='http', auth='public', website=True, sitemap=False,csrf=False) |
|
|
@ -232,22 +266,18 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
|
|
|
|
return http.request.render('kalachakra.onthespotpayment') |
|
|
|
|
|
|
|
@http.route(['/kalachakra/participation'], type='http', auth='public', website=True, sitemap=False,csrf=False) |
|
|
|
@http.route(['/kalachakra/participation'], type='http', auth='user', website=True, sitemap=False,csrf=False) |
|
|
|
def participation(self,type=None,**post): |
|
|
|
data={} |
|
|
|
request.session['kalachakra_transaction']='' |
|
|
|
|
|
|
|
if type=='participation': |
|
|
|
event=request.env['event.event'].search([('id','=',request.session['event_id'])]) |
|
|
|
#event=request.env['event.event'].search([('id','=',request.session['event_id'])]) |
|
|
|
res=request.env['event.registration'].sudo().search([('id','=',request.session['res_id'])]) |
|
|
|
|
|
|
|
#création de la facture à régler |
|
|
|
|
|
|
|
invoice_id=request.env['event.registration'].sudo().action_generate_participation_invoice(request.session['res_id'],'CB') |
|
|
|
|
|
|
|
|
|
|
|
#redirection sur la page de paiement de la facture : |
|
|
|
url="/my/invoices/"+str(invoice_id)#+"?access_token="+str(invoice.access_token) |
|
|
|
url="/my/invoices/"+str(int(res.invoice_id))#+"?access_token="+str(invoice.access_token) |
|
|
|
return request.redirect(url) |
|
|
|
|
|
|
|
|
|
|
@ -259,12 +289,14 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
data['title']='make donation' |
|
|
|
data['amount']=10 |
|
|
|
#donation product |
|
|
|
data['products']=request.env['product.product'].search([('donation','=',True)]) |
|
|
|
data['products']=request.env['product.product'].sudo().search([('donation','=',True)]) |
|
|
|
|
|
|
|
|
|
|
|
if type=='membership': |
|
|
|
request.session['kalachakra_transaction']='membership' |
|
|
|
data['kalachakra_transaction']='membership' |
|
|
|
data['title']='Become a member' |
|
|
|
p=request.env['product.product'].search([('membership_product','=',True)]) |
|
|
|
p=request.env['product.product'].sudo().search([('membership_product','=',True)],limit=1) |
|
|
|
if not p: raise UserError(_('No membership product, please add one')) |
|
|
|
data['amount']=p.list_price |
|
|
|
|
|
|
@ -282,7 +314,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
|
|
|
|
|
|
|
|
if userid: |
|
|
|
user=request.env['res.users'].search([('id','=',int(userid))]) |
|
|
|
user=request.env['res.users'].sudo().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 |
|
|
@ -321,12 +353,14 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
#gestion du retour page précédente depuis page de paiement : on supprime les éléments générés ( don , adhésion) |
|
|
|
if not post.get('product_id'): |
|
|
|
if request.session['kalachakra_transaction']=='donation': |
|
|
|
request.env['donation.donation'].search([('id','=',int(request.session['donation_id']))]).unlink() |
|
|
|
request.env['donation.donation'].sudo().search([('id','=',int(request.session['donation_id']))]).unlink() |
|
|
|
if request.session['kalachakra_transaction']=='membership': |
|
|
|
request.env['kalachakra.membership'].search([('id','=',int(request.session['membership_id']))]).unlink() |
|
|
|
request.env['kalachakra.membership'].sudo().search([('id','=',int(request.session['membership_id']))]).unlink() |
|
|
|
|
|
|
|
return request.redirect('/kalachakra/participation?type='+request.session['kalachakra_transaction']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userid=request.env.context.get('uid') |
|
|
|
if userid: |
|
|
@ -335,7 +369,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
request.session['partner_id']=int(partner.id) |
|
|
|
else: |
|
|
|
|
|
|
|
#si pas connecté on chercher le contact indiqué par l'email |
|
|
|
#si pas connecté on cherche le contact indiqué par l'email |
|
|
|
partner=request.env['res.partner'].sudo().search([('email','=',post.get('email'))],limit=1) |
|
|
|
#si pas de contact on le créé dans la base |
|
|
|
if not partner: |
|
|
@ -350,6 +384,14 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
vals['country_id']=int(post.get('country_id')) |
|
|
|
vals['phone']=post.get('phone') |
|
|
|
partner=request.env['res.partner'].sudo().create(vals) |
|
|
|
#si le contact existe, on vérifie qu'il n'est pas déjà adhérent |
|
|
|
else: |
|
|
|
if partner.member_status in ('member','super member'): |
|
|
|
data={} |
|
|
|
data['email']==post.get('email') |
|
|
|
return http.request.render('kalachakra.already_member',data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data={} |
|
|
@ -362,14 +404,14 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
data['error_url']='/kalachakra/payment/error' |
|
|
|
|
|
|
|
if request.session['kalachakra_transaction'] in ['donation','membership']: |
|
|
|
data['acquirers'] = list(request.env['payment.acquirer'].search([ |
|
|
|
data['acquirers'] = list(request.env['payment.acquirer'].sudo().search([ |
|
|
|
('state', 'in', ['enabled', 'test']), |
|
|
|
('company_id', '=', request.env.company.id), |
|
|
|
('provider', '!=', 'transfer') |
|
|
|
|
|
|
|
])) |
|
|
|
else: |
|
|
|
data['acquirers'] = list(request.env['payment.acquirer'].search([ |
|
|
|
data['acquirers'] = list(request.env['payment.acquirer'].sudo().search([ |
|
|
|
('state', 'in', ['enabled', 'test']), |
|
|
|
('company_id', '=', request.env.company.id) |
|
|
|
])) |
|
|
@ -388,9 +430,9 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
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) |
|
|
|
electronic_method=request.env['account.payment.method'].sudo().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) |
|
|
|
cb_mode=request.env['account.payment.mode'].sudo().search([('payment_method_id','=',int(electronic_method.id))],limit=1) |
|
|
|
if cb_mode: |
|
|
|
vals['payment_mode_id']=cb_mode.id |
|
|
|
else: |
|
|
@ -401,7 +443,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
vals={} |
|
|
|
#create line donation |
|
|
|
vals['donation_id']=donation_draft.id |
|
|
|
product=request.env['product.template'].search([('id','=',int(post.get('product_id')))]) |
|
|
|
product=request.env['product.template'].sudo().search([('id','=',int(post.get('product_id')))]) |
|
|
|
vals['product_id']=int(post.get('product_id')) |
|
|
|
vals['display_name']=product.name |
|
|
|
vals['quantity']=1 |
|
|
@ -452,19 +494,19 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
acquirer_id = int(acquirer_id) |
|
|
|
except: |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
if request.session['kalachakra_transaction'] in ['donation']: |
|
|
|
# Retrieve the donation |
|
|
|
donation_id=order_id |
|
|
|
donation=request.env['donation.donation'].search([('id','=',int(donation_id))], limit=1) |
|
|
|
|
|
|
|
donation=request.env['donation.donation'].sudo().search([('id','=',int(donation_id))], limit=1) |
|
|
|
|
|
|
|
|
|
|
|
# Ensure there is something to proceed |
|
|
|
if not donation or (donation and not donation.line_ids): |
|
|
|
return False |
|
|
|
|
|
|
|
assert donation.partner_id.id != request.website.partner_id.id |
|
|
|
|
|
|
|
|
|
|
|
# Create transaction |
|
|
|
vals = {'acquirer_id': acquirer_id, |
|
|
|
'return_url': '/kalachakra/payment/validate'} |
|
|
@ -474,8 +516,8 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
if token: |
|
|
|
vals['payment_token_id'] = int(token) |
|
|
|
|
|
|
|
transaction = donation._create_payment_transaction(vals) |
|
|
|
|
|
|
|
transaction = donation.sudo()._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') |
|
|
@ -490,7 +532,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
|
|
|
|
# Retrieve the membeship |
|
|
|
membership_id=order_id |
|
|
|
membership=request.env['kalachakra.membership'].search([('id','=',int(membership_id))], limit=1) |
|
|
|
membership=request.env['kalachakra.membership'].sudo().search([('id','=',int(membership_id))], limit=1) |
|
|
|
|
|
|
|
|
|
|
|
# Ensure there is something to proceed |
|
|
@ -508,7 +550,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
if token: |
|
|
|
vals['payment_token_id'] = int(token) |
|
|
|
|
|
|
|
transaction = membership._create_payment_transaction(vals) |
|
|
|
transaction = membership.sudo()._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 |
|
|
@ -518,7 +560,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
PaymentProcessing.remove_payment_transaction(last_tx) |
|
|
|
PaymentProcessing.add_payment_transaction(transaction) |
|
|
|
request.session['__website_sale_last_tx_id'] = transaction.id |
|
|
|
return transaction.render_membership_button(membership) |
|
|
|
return transaction.sudo().render_membership_button(membership) |
|
|
|
|
|
|
|
http.route('/kalachakra/payment/token', type='http', auth='public', website=True, sitemap=False) |
|
|
|
def kalachakra_payment_token(self, pm_id=None, **kwargs): |
|
|
@ -540,10 +582,10 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
vals = {'payment_token_id': pm_id, 'return_url': '/kalachakra/payment/validate'} |
|
|
|
|
|
|
|
if request.session['kalachakra_transaction'] in ['donation']: |
|
|
|
tx = donation._create_payment_transaction(vals) |
|
|
|
tx = donation.sudo()._create_payment_transaction(vals) |
|
|
|
|
|
|
|
if request.session['kalachakra_transaction'] in ['membership']: |
|
|
|
tx = membership._create_payment_transaction(vals) |
|
|
|
tx = membership.sudo()._create_payment_transaction(vals) |
|
|
|
|
|
|
|
request.session['transaction_id']=tx.id |
|
|
|
PaymentProcessing.add_payment_transaction(tx) |
|
|
@ -572,14 +614,14 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): |
|
|
|
|
|
|
|
donation_id=int(request.session['donation_id']) |
|
|
|
#validation du don car la tranasction est ok |
|
|
|
donation=request.env['donation.donation'].search([('id','=',donation_id)]) |
|
|
|
donation=request.env['donation.donation'].sudo().search([('id','=',donation_id)]) |
|
|
|
donation.state='done' |
|
|
|
request.session['donation_id']=None |
|
|
|
|
|
|
|
if request.session['kalachakra_transaction'] in ['membership']: |
|
|
|
membership_id=int(request.session['membership_id']) |
|
|
|
#validation du don car la tranasction est ok |
|
|
|
membership=request.env['kalachakra.membership'].search([('id','=',membership_id)]) |
|
|
|
membership=request.env['kalachakra.membership'].sudo().search([('id','=',membership_id)]) |
|
|
|
membership.state='done' |
|
|
|
request.session['membership_id']=None |
|
|
|
|
|
|
|