Browse Source

generation des evenements recurrents

dev-rcn
root 3 years ago
parent
commit
950e4e2648
12 changed files with 362 additions and 45 deletions
  1. +1
    -0
      __manifest__.py
  2. +39
    -3
      controllers/kalachakra.py
  3. +1
    -0
      models/__init__.py
  4. +1
    -1
      models/booking_event_registration.py
  5. +89
    -10
      models/event.py
  6. +94
    -0
      models/event_registration.py
  7. +16
    -0
      static/js/kalachakra.js
  8. +25
    -21
      views/booking_event_registration.xml
  9. +1
    -1
      views/booking_website_registration.xml
  10. +20
    -6
      views/event.xml
  11. +46
    -0
      views/event_registration.xml
  12. +29
    -3
      views/website_event_registration.xml

+ 1
- 0
__manifest__.py View File

@ -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',


+ 39
- 3
controllers/kalachakra.py View File

@ -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'


+ 1
- 0
models/__init__.py View File

@ -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


+ 1
- 1
models/booking_event_registration.py View File

@ -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')


+ 89
- 10
models/event.py View File

@ -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_date<datetime.now() :raise Warning('action cancelled: the end generation date must be in the future !')
delta=rec.end_generation_date-rec.date_begin
if delta.days>100: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)


+ 94
- 0
models/event_registration.py View File

@ -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

+ 16
- 0
static/js/kalachakra.js View File

@ -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


+ 25
- 21
views/booking_event_registration.xml View File

@ -51,44 +51,47 @@
</field>
</record>
<record id="event_registration_view_form" model="ir.ui.view">
<field name="name">event.type.view.form.inherit.booking</field>
<record id="booking_event_registration_view_form" model="ir.ui.view">
<field name="name">booking.event.type.view.form.inherit.booking</field>
<field name="model">event.registration</field>
<field name="inherit_id" ref="event.view_event_registration_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='attendee']" position="inside">
<field name="gender"/>
<field name="age"/>
<field name="medical_concern"/>
<field name="medical_information"/>
<field name="medical_contact_name"/>
<field name="medical_contact_phone"/>
<field name="room_id"/>
<field name="down_payment"/>
<field name="gender" attrs="{'invisible':[('booking_event','!=',True)]}"/>
<field name="age" attrs="{'invisible':[('booking_event','!=',True)]}"/>
<field name="medical_concern" attrs="{'invisible':[('booking_event','!=',True)]}"/>
<field name="medical_information" attrs="{'invisible':[('booking_event','!=',True)]}"/>
<field name="medical_contact_name" attrs="{'invisible':[('booking_event','!=',True)]}"/>
<field name="medical_contact_phone" attrs="{'invisible':[('booking_event','!=',True)]}"/>
<field name="room_id" attrs="{'invisible':[('booking_event','!=',True)]}"/>
<field name="down_payment" attrs="{'invisible':[('booking_event','!=',True)]}"/>
</xpath>
<xpath expr="//div[@name='button_box']" position="inside">
<t t-if="booking_event" >
<button name="%(action_view_event_registration_questionnaire)d" type="action"
class="oe_stat_button" icon="fa-question" string="Questionnaire">
class="oe_stat_button" icon="fa-question" string="Questionnaire" attrs="{'invisible':[('booking_event','!=',True)]}">
</button>
</t>
</xpath>
<xpath expr="//div[@name='button_box']" position="inside">
<t t-if="booking_event" >
<button name="%(action_view_event_registration_option)d" type="action"
class="oe_stat_button" icon="fa-bed" string="Options">
class="oe_stat_button" icon="fa-bed" string="Options" attrs="{'invisible':[('booking_event','!=',True)]}">
</button>
</t>
</xpath>
<xpath expr="//button[@name='action_cancel']" position="after">
<!-- <button name="action_event_registration_generate_order" type="object"
states="open" string="Generate quotation(s)">
</button> -->
<button name="action_event_registration_generate_invoice" type="object"
states="open" string="Generate invoice(s)">
string="Generate invoice(s)" attrs="{'invisible':[('booking_event','!=',True)]}">
</button>
<field name='booking_event' invisible="1"/>
</xpath>
@ -96,8 +99,8 @@
<xpath expr="//group[@name='event']" position="after">
<group string="Payments" name="payments">
<field name="invoice_id"/>
<field name="down_payment_invoice_id"/>
<field name="balance_invoice_id"/>
<field name="down_payment_invoice_id" attrs="{'invisible':[('booking_event','!=',True)]}"/>
<field name="balance_invoice_id" attrs="{'invisible':[('booking_event','!=',True)]}"/>
</group>
</xpath>
@ -140,7 +143,8 @@
<field name="inherit_id" ref="event.event_registration_view_kanban"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='email']" position="after">
<field name="room_id" />
<field name="room_id" attrs="{'invisible':[('booking_event','!=',True)]}" />
<field name='booking_event' invisible="1"/>
</xpath>
<xpath expr="//field[@name='event_ticket_id']" position="after">
<field name="kanban_color" />


+ 1
- 1
views/booking_website_registration.xml View File

@ -3,7 +3,7 @@
<template id="assets_frontend" name="booking assets" inherit_id="web.assets_frontend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/booking/static/js/booking.js"></script>
<script type="text/javascript" src="/kalachakra/static/js/booking.js"></script>
</xpath>
</template>


+ 20
- 6
views/event.xml View File

@ -22,17 +22,31 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='stage_id']" position="before">
<button name="add_event_to_google_agenda" type="object" attrs="{'invisible':[('calendar_event_id','!=',False)]}" string="Add event to google agenda" class="btn btn-warning"/>
<button name="remove_event_to_google_agenda" attrs="{'invisible':[('calendar_event_id','=',False)]}" type="object" string="Remove event from google agenda" class="btn btn-danger"/>
<field name="calendar_event_id" invisible="1"/>
<button name="remove_event_from_google_agenda" attrs="{'invisible':[('calendar_event_id','=',False)]}" type="object" string="Remove event from google agenda" class="btn btn-danger"/>
<button name="generate_events" attrs="{'invisible':['|',('generated_events','=',True),'|','|',('frequency','=',False),('end_generation_date','=',False),('parent_event_id','!=',False)]}" type="object" string="generate the events" class="btn btn-primary"/>
<button name="remove_generated_events" attrs="{'invisible':['|',('generated_events','=',False),'|','|',('frequency','=',False),('end_generation_date','=',False),('parent_event_id','!=',False)]}" type="object" string="remove generated events" class="btn btn-danger"/>
<field name="calendar_event_id" invisible="1"/>
<field name="parent_event_id" invisible="1"/>
<field name="frequency" invisible="1"/>
<field name="end_generation_date" invisible="1"/>
<field name="generated_events" invisible="1"/>
</xpath>
<xpath expr="//field[@name='tag_ids']" position="after">
<field name="online_event" attrs="{'invisible':[('booking_event','=',True)]}"/>
<field name="free_participation" attrs="{'invisible':[('booking_event','=',True)]}"/>
<field name="recurring_event" attrs="{'invisible':[('booking_event','=',True)]}"/>
<field name="recurring_event_newsletter_id" attrs="{'invisible':[('recurring_event','=',False),('booking_event','=',True)]}"/>
<field name="frequency" attrs="{'invisible':['|',('booking_event','=',True),('recurring_event','=',False)]}"/>
<field name="weekly_day" attrs="{'invisible':[('frequency','!=','weekly')]}"/>
<field name="end_generation_date" attrs="{'invisible':['|',('booking_event','=',True),('recurring_event','=',False)]}"/>
<field name="parent_event_id" attrs="{'invisible':['|',('booking_event','=',True),('recurring_event','=',False)]}"/>
<field name="recurring_event_newsletter_id" attrs="{'invisible':['|',('booking_event','=',True),('recurring_event','=',False)]}"/>
</xpath>
@ -42,8 +56,8 @@
<page string="Participations" name="Participations" attrs="{'invisible':['|',('free_participation','=',True),('booking_event','=',True)]}">
<group style="width:40%%">
<field name="participation_product_id" attrs="{'required': [('free_participation','=', False)]}"/>
<field name="booking_event" invisible="1"/>
<field name="participation_product_id" attrs="{'required': [('free_participation','!=',True),('booking_event','!=',True)]}"/>
<field name="participation_standard_price" attrs="{'required': [('free_participation','=', False)]}"/>
<field name="participation_member_price" attrs="{'required': [('free_participation','=', False)]}"/>
<field name="participation_super_member_price" attrs="{'required': [('free_participation','=', False)]}"/>


+ 46
- 0
views/event_registration.xml View File

@ -0,0 +1,46 @@
<odoo>
<record id="kalachakra_event_registration_view_form" model="ir.ui.view">
<field name="name">event.type.view.form.inherit.booking</field>
<field name="model">event.registration</field>
<field name="inherit_id" ref="event.view_event_registration_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='attendee']" position="inside">
<field name="online" attrs="{'invisible':[('booking_event','=',True)]}" />
<field name="onthespot_payment" attrs="{'invisible':[('booking_event','=',True)]}"/>
</xpath>
<xpath expr="//button[@name='action_cancel']" position="after">
<button name="action_generate_participation_invoice" type="object"
string="Generate participation invoice" attrs="{'invisible':['|','|',('booking_event','=',True),('free_participation','=',True),('state','=','draft')]}">
</button>
<field name='booking_event' invisible="1"/>
<field name='free_participation' invisible="1"/>
</xpath>
</field>
</record>
<record id="kalachakra_event_registration_view_tree" model="ir.ui.view">
<field name="name">kalachakra.event.registration.tree.inherit</field>
<field name="model">event.registration</field>
<field name="inherit_id" ref="event.view_event_registration_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='create_date']" position="after">
<field name="online" attrs="{'invisible':[('booking_event','=',True)]}"/>
<field name="onthespot_payment" attrs="{'invisible':[('booking_event','=',True)]}"/>
<field name="booking_event" invisible="1"/>
</xpath>
</field>
</record>
</odoo>

+ 29
- 3
views/website_event_registration.xml View File

@ -1,4 +1,13 @@
<odoo>
<template id="assets_frontend" name="booking assets" inherit_id="web.assets_frontend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/kalachakra/static/js/kalachakra.js"></script>
</xpath>
</template>
<template id="kalachakra.registration_step1" name="Distancial Event Form">
<t t-call="website.layout">
@ -74,6 +83,7 @@
<div class="container-fluid">
<form id="form" action="#" method="post" class="form js_website_submit_form">
<b><h7 style="display: inline">Registering to : </h7><h7 style="display: inline" t-esc="event.name"></h7></b>
<br></br>
<t t-if="event.duration==0">
@ -97,7 +107,7 @@
<br></br>
<br></br>
<t t-if="event.online_event">
<t t-if="online=='yes'">
<t t-if="online==true">
<font color="blue">
<h7>Here is the information to attend on Zoom :</h7>
<br></br>
@ -137,12 +147,13 @@
<t t-if="not event.free_participation">
<t t-if="status in ('standard','member')">
<h7> The amount of the contribution is : </h7><b><h7 t-esc="participation_amount"></h7><h7></h7></b>
<input type="hidden" name="participation_amount" t-att-value="participation_amount"/>
<br></br>
<br></br>
<button type="submit" class="btn btn-primary" >I pay the participation now</button>
<button type="submit" id="pay_now_btn" class="btn btn-primary" >I pay the participation now</button>
<br></br>
<br></br>
<button type="submit" class="btn btn-primary" >I will pay the participation on the spot</button>
<button type="submit" id="pay_on_the_spot_btn" class="btn btn-primary" >I will pay the participation on the spot</button>
<br></br>
<br></br>
<t t-if="status=='standard'">
@ -170,9 +181,24 @@
</t>
<br></br>
<br></br>
</form>
</div>
</t>
</template>
<template id="kalachakra.onthespotpayment" name="thankyou">
<t t-call="website.layout">
<div class="container-fluid">
<h6>Thank you for your registration !</h6>
<a href="/" class="ml-4 btn btn-secondary">back Home</a>
</div>
</t>
</template>
</odoo>

Loading…
Cancel
Save