diff --git a/__manifest__.py b/__manifest__.py index 5fa002f..30d7652 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -42,6 +42,7 @@ 'views/membership.xml', 'views/website_event_registration.xml', 'views/event_templates_page_registration.xml', + 'views/event_registration.xml', 'views/booking_product.xml', 'views/booking_event.xml', diff --git a/controllers/kalachakra.py b/controllers/kalachakra.py index 0058ba9..0e68c10 100644 --- a/controllers/kalachakra.py +++ b/controllers/kalachakra.py @@ -190,7 +190,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): data['status']=partner.member_status if data['status']=='not member':data['status']='standard' - #prix + request.session['status']=data['status'] @@ -201,7 +201,10 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): data={} event=request.env['event.event'].sudo().search([('id','=',request.session['event_id'])]) data['event']=event - data['online']=post.get('online') + data['online']=False + if post.get('online')=='yes':data['online']=True + + data['status']=request.session['status'] data['price']='' @@ -209,14 +212,47 @@ 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) + request.session['res_id']=res.id return http.request.render('kalachakra.registration_step2',data) - + @http.route(['/kalachakra/onthespotpayment'], type='http', auth='public', website=True, sitemap=False,csrf=False) + def onthespotparticipation(self,type=None,**post): + res=request.env['event.registration'].sudo().search([('id','=',request.session['res_id'])]) + + res.onthespot_payment=True + + return http.request.render('kalachakra.onthespotpayment') + @http.route(['/kalachakra/participation'], type='http', auth='public', 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'])]) + 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) + return request.redirect(url) + + + + if type=='donation': request.session['kalachakra_transaction']='donation' data['kalachakra_transaction']='donation' diff --git a/models/__init__.py b/models/__init__.py index bff1c60..74a32cf 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -8,6 +8,7 @@ from . import product from . import membership from . import payment_transaction from . import partner +from . import event_registration from . import booking_product from . import booking_event from . import booking_location diff --git a/models/booking_event_registration.py b/models/booking_event_registration.py index 80fdcf4..2184390 100644 --- a/models/booking_event_registration.py +++ b/models/booking_event_registration.py @@ -81,7 +81,7 @@ class EventRegistration(models.Model): balance_invoice_state=fields.Selection(related='balance_invoice_id.state') - invoice_id=fields.Many2one('account.move') + invoice_id=fields.Many2one('account.move', readonly=True) #invoice_state=fields.Selection(related='invoice_id.state') down_payment_invoice_id=fields.Many2one('account.move') #down_payment_invoice_state=fields.Selection(related='down_payment_order_id.state') diff --git a/models/event.py b/models/event.py index 5d7ed80..2e0f161 100644 --- a/models/event.py +++ b/models/event.py @@ -1,4 +1,4 @@ -from odoo import models, fields, api +from odoo import models, fields, api,_ from odoo.exceptions import UserError, ValidationError,Warning from psycopg2 import sql, DatabaseError from pytz import timezone @@ -47,6 +47,86 @@ class KalachakraEvent(models.Model): online_id=fields.Char('id') online_password=fields.Char('password') duration=fields.Integer('duration', compute="_compute_duration") + frequency=fields.Selection(string='Frequency',selection=[('daily', 'Daily'), ('weekly', 'Weekly')]) + weekly_day=fields.Selection(string='Weekly day',selection=[('monday', 'Monday'),('tuesday', 'Tuesday'),('wednesday', 'Wednesday'),('thursday', 'Thursday'),('friday', 'Friday'),('saturday', 'Saturday'),('sunday', 'Sunday') ]) + end_generation_date=fields.Datetime('End generation date') + generated_events=fields.Boolean('generated_ events', compute='_compute_generated_events') + #for event generated from a parent event + parent_event_id=fields.Many2one('event.event',string='parent event', readonly=True) + + def _compute_generated_events(self): + for rec in self: + rec.generated_events=False + evt=rec.env['event.event'].search([('parent_event_id','=', int(rec.id))]) + if evt:rec.generated_events=True + + def remove_generated_events(self): + evt=self.env['event.event'].search([('parent_event_id','=', int(self.id))]) + if evt: + for e in evt: + e.remove_event_from_google_agenda() + e.unlink() + + + + def generate_events(self): + for rec in self: + if rec.duration>1 :raise Warning('action cancelled: the duration f the event is more than 1 days !') + + if rec.end_generation_date100:raise Warning('action cancelled: the duration f the event is more than 100 days !') + + if rec.frequency=='daily':d=1 + if rec.frequency=='weekly':d=7 + + start_date_event=rec.date_begin+timedelta(days=d) + end_date_event=rec.date_end+timedelta(days=d) + + while start_date_event<=rec.end_generation_date: + + #avant de dupliquer l'événement on regarde si celui-ci n'a pas déjà été crée ! + evt=self.env['event.event'].search([('date_begin','=',start_date_event),('parent_event_id','=', int(self.id))]) + if evt: raise Warning('action cancelled: event already generated with this date :'+ str(start_date_event)) + + dup=self._create_event(rec,start_date_event,end_date_event) + + dup.add_event_to_google_agenda() + + end_date_event=end_date_event+timedelta(days=d) + start_date_event=start_date_event+timedelta(days=d) + + + + + + + def _create_event(self,rec,start_date_event,end_date_event): + vals={} + vals['name']=rec.name + vals['date_begin']=start_date_event + vals['date_end']=end_date_event + vals['description']=rec.description + vals['tag_ids']=rec.tag_ids + vals['is_published']=True + vals['free_participation']=rec.free_participation + vals['participation_product_id']=rec.participation_product_id + vals['participation_standard_price']=rec.participation_standard_price + vals['participation_member_price']=rec.participation_member_price + vals['participation_super_member_price']=rec.participation_super_member_price + vals['subscription_product_id']=rec.subscription_product_id + vals['subscription_standard_price']=rec.subscription_standard_price + vals['subscription_member_price']=rec.subscription_member_price + vals['subscription_super_member_price']=rec.subscription_super_member_price + vals['recurring_event']=rec.recurring_event + vals['recurring_event_newsletter_id']=rec.recurring_event_newsletter_id + vals['online_event']=rec.online_event + vals['online_link']=rec.online_link + vals['online_id']=rec.online_id + vals['online_password']=rec.online_password + vals['parent_event_id']=rec.id + + return self.env['event.event'].create(vals) def _compute_duration(self): for rec in self: @@ -124,9 +204,6 @@ class KalachakraEvent(models.Model): credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES) delegated_credentials = credentials.with_subject(SUBJECT) service = build('calendar', 'v3', credentials=delegated_credentials) - - - start=self.date_begin.astimezone(timezone('Europe/Paris')) end=self.date_end.astimezone(timezone('Europe/Paris')) @@ -151,17 +228,19 @@ class KalachakraEvent(models.Model): } #recherche de l'id calendar lié à l'étiquette de l'événément + calendar_find=False for tag in self.tag_ids: if tag.category_id.calendar_id: - calendar_id=tag.category_id.calendar_id - if calendar_id: - event = service.events().insert(calendarId=calendar_id, body=body).execute() + + calendar_find=True + event = service.events().insert(calendarId=tag.category_id.calendar_id, body=body).execute() + self.calendar_event_id=event['id'] + self.calendar_id=tag.category_id.calendar_id - self.calendar_event_id=event['id'] - self.calendar_id=calendar_id + if not calendar_find: raise Warning('operation cancelled: no calendar id find, please selected a label wih category with a calendar_id') - def remove_event_to_google_agenda(self): + def remove_event_from_google_agenda(self): credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES) delegated_credentials = credentials.with_subject(SUBJECT) service = build('calendar', 'v3', credentials=delegated_credentials) diff --git a/models/event_registration.py b/models/event_registration.py new file mode 100644 index 0000000..a923298 --- /dev/null +++ b/models/event_registration.py @@ -0,0 +1,94 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError, ValidationError, Warning +from psycopg2 import sql, DatabaseError +from dateutil.relativedelta import relativedelta +from datetime import datetime +from werkzeug import utils +import json + +class EventRegistration(models.Model): + _inherit = 'event.registration' + + online=fields.Boolean(string='Online participation') + onthespot_payment=fields.Boolean(string='On the spot payment') + free_participation=fields.Boolean(related='event_id.free_participation') + + def action_generate_participation_invoice(self,id_registration=None,payment_mode=None): + + if not id_registration:id_registration=int(self.id) + reg=self.env['event.registration'].search([('id','=',id_registration)]) + event=self.env['event.event'].search([('id','=',int(reg.event_id))]) + + #Prix à appliquer au produit en fonction du statut de l'inscrit + status=reg.partner_id.member_status + + if status=='not member':product_price=event.participation_standard_price + if status=='member':product_price=event.participation_member_price + if status=='super member':product_price=event.participation_super_member_price + product_id=event.participation_product_id + + + #création de la facture + vals={} + + vals['partner_id']=int(reg.partner_id) + vals['invoice_date']=datetime.now() + + #mode de paiement CB + if payment_mode=='CB': + electronic_method=self.env['account.payment.method'].search([('code','=','electronic')],limit=1) + if electronic_method: + cb_mode=self.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['move_type']='out_invoice' + vals['state']='draft' + #vals['currency_id']=self.currency_id.id + #raise Warning(json.dumps(vals,indent = 4)) + invoice=self.env['account.move'].create(vals) + + invoice.state='posted' + invoice.name='REC'+str(invoice.id) + invoice.payment_reference=invoice.name + + vals={} + account_credit=self.env['account.account'].search([('code','=','707100')]) + account_debit=self.env['account.account'].search([('code','=','411100')]) + + vals['move_id']=invoice.id + vals['product_id']=int(event.participation_product_id) + vals['quantity']=1 + vals['price_unit']=product_price + vals['name']=event.participation_product_id.name + + vals['account_id']=int(account_credit.id) + + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).create(vals) + + + # #debit_line + vals_d={} + vals_d['move_id']=invoice.id + vals_d['debit']=product_price + vals_d['credit']=0 + vals_d['date']=datetime.now() + vals_d['partner_id']=int(reg.partner_id) + vals_d['product_id']=int(event.participation_product_id) + vals_d['name']=event.participation_product_id.name + vals_d['account_id']=int(account_debit.id) + vals_d['quantity']=1 + vals_d['price_unit']=product_price + vals_d['exclude_from_invoice_tab']=True + + + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).create(vals_d) + l=self.env['account.move.line'].search([('move_id','=',invoice.id),('balance','<',0)]) + l.partner_id=int(reg.partner_id) + reg.invoice_id=invoice.id + + return invoice.id + + \ No newline at end of file diff --git a/static/js/kalachakra.js b/static/js/kalachakra.js index 79719a7..6d47ba2 100644 --- a/static/js/kalachakra.js +++ b/static/js/kalachakra.js @@ -7,6 +7,22 @@ odoo.define('kalachakra.main', function (require) { }); + $( "#pay_now_btn" ).click(function() { + + $('#form').attr('action', '/kalachakra/participation?type=participation'); + $( "#form" ).submit(); + }); + + $( "#pay_on_the_spot_btn" ).click(function() { + + $('#form').attr('action', '/kalachakra/onthespotpayment'); + + + $( "#form" ).submit(); + + }); + + $( "#btn_payment_choice" ).click(function() { //validation de l'adresse mail diff --git a/views/booking_event_registration.xml b/views/booking_event_registration.xml index 0bc21ce..c368d57 100644 --- a/views/booking_event_registration.xml +++ b/views/booking_event_registration.xml @@ -51,44 +51,47 @@ - - event.type.view.form.inherit.booking + + booking.event.type.view.form.inherit.booking event.registration - - - - - - - - - + + + + + + + + + + + + + - + - + + @@ -96,8 +99,8 @@ - - + + @@ -140,7 +143,8 @@ - + + diff --git a/views/booking_website_registration.xml b/views/booking_website_registration.xml index 5909bb5..6c55154 100644 --- a/views/booking_website_registration.xml +++ b/views/booking_website_registration.xml @@ -3,7 +3,7 @@ diff --git a/views/event.xml b/views/event.xml index b71ebe5..590968c 100644 --- a/views/event.xml +++ b/views/event.xml @@ -22,17 +22,31 @@ + + + + + + + + + + + kalachakra.event.registration.tree.inherit + event.registration + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/views/website_event_registration.xml b/views/website_event_registration.xml index b885500..7b7f17b 100644 --- a/views/website_event_registration.xml +++ b/views/website_event_registration.xml @@ -1,4 +1,13 @@ + + + + + + \ No newline at end of file