Browse Source

divers

dev-rcn
root 3 years ago
parent
commit
38f64e361f
12 changed files with 211 additions and 83 deletions
  1. +81
    -39
      controllers/kalachakra.py
  2. +2
    -1
      models/__init__.py
  3. +4
    -4
      models/booking_event_registration.py
  4. +4
    -2
      models/donation.py
  5. +14
    -1
      models/event.py
  6. +12
    -0
      models/event_media_link.py
  7. +7
    -2
      models/partner.py
  8. +4
    -0
      security/ir.model.access.csv
  9. +12
    -0
      views/event.xml
  10. +1
    -1
      views/event_templates_list.xml
  11. +13
    -0
      views/event_templates_page_registration.xml
  12. +57
    -33
      views/website_event_registration.xml

+ 81
- 39
controllers/kalachakra.py View File

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


+ 2
- 1
models/__init__.py View File

@ -16,4 +16,5 @@ from . import booking_room
from . import booking_questionnaire
from . import booking_event_registration
from . import booking_donation
from . import booking_sale_order
from . import booking_sale_order
from . import event_media_link

+ 4
- 4
models/booking_event_registration.py View File

@ -75,11 +75,11 @@ class EventRegistration(models.Model):
mobile=fields.Char('Mobile')
kanban_color=fields.Char('kanban color',compute='_compute_kanban_color')
invoice_state=fields.Selection(related='invoice_id.state')
invoice_state=fields.Selection(related='invoice_id.payment_state')
down_payment_invoice_state=fields.Selection(related='down_payment_invoice_id.state')
down_payment_invoice_state=fields.Selection(related='down_payment_invoice_id.payment_state')
balance_invoice_state=fields.Selection(related='balance_invoice_id.state')
balance_invoice_state=fields.Selection(related='balance_invoice_id.payment_state')
invoice_id=fields.Many2one('account.move', readonly=True)
#invoice_state=fields.Selection(related='invoice_id.state')
@ -94,7 +94,7 @@ class EventRegistration(models.Model):
def _compute_payment_status(self):
for rec in self:
rec.payment_status='undefined'
rec.payment_status='not paid'
if rec.invoice_id:
if rec.invoice_state not in ('paid'):rec.payment_status='not paid'
if rec.invoice_state=='paid':rec.payment_status='paid'


+ 4
- 2
models/donation.py View File

@ -94,9 +94,11 @@ class DonationDonation(models.Model):
'donation_ids': [(6, 0, self.ids)],
'type': self[0]._get_payment_type(vals.get('type')=='form_save'),
})
transaction = self.env['payment.transaction'].create(vals)
# Process directly if payment_token
if transaction.payment_token_id:
transaction.s2s_do_transaction()


+ 14
- 1
models/event.py View File

@ -108,6 +108,7 @@ class KalachakraEvent(models.Model):
vals['date_end']=end_date_event
vals['description']=rec.description
vals['tag_ids']=rec.tag_ids
vals['event_logo']=rec.event_logo
vals['is_published']=True
vals['free_participation']=rec.free_participation
vals['participation_product_id']=rec.participation_product_id
@ -125,8 +126,14 @@ class KalachakraEvent(models.Model):
vals['online_id']=rec.online_id
vals['online_password']=rec.online_password
vals['parent_event_id']=rec.id
vals['cover_properties']=rec.cover_properties
ev=self.env['event.event'].create(vals)
return self.env['event.event'].create(vals)
return ev
def _compute_duration(self):
for rec in self:
@ -196,6 +203,12 @@ class KalachakraEvent(models.Model):
ondelete='restrict',
default=_default_currency
)
media_link_ids=fields.One2many(
'event.media.link',
'event_id',
string='Media links'
)
def add_event_to_google_agenda(self):


+ 12
- 0
models/event_media_link.py View File

@ -0,0 +1,12 @@
from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError,Warning
class event_media_link(models.Model):
_name = 'event.media.link'
_description = 'event media link'
media_link = fields.Char('Media link')
event_id=fields.Many2one('event.event')

+ 7
- 2
models/partner.py View File

@ -5,7 +5,7 @@ from datetime import datetime
from werkzeug import utils
class partner(models.Model):
class ResPartner(models.Model):
_inherit = 'res.partner'
external_id=fields.Char('id')
statut_contact=fields.Selection([('adherent', 'Adhérent'), ('bienfaiteur', 'Bienfaiteur'),('contact', 'Contact'), ('soutien','Soutien') ],'Statut', index=True)
@ -79,4 +79,9 @@ class partner(models.Model):
self._compute_member_status()
@api.model
def create(self, values):
res = super(ResPartner, self).create(values)
country_france=self.env['res.country'].sudo().search([('name','=','France')])
if not res.country_id:res.country_id=country_france.id
return res

+ 4
- 0
security/ir.model.access.csv View File

@ -17,3 +17,7 @@ access_event_registration_questionnaire,event.registration_questionnaire,model_e
access_event_registration_option,event.registration_option,model_event_registration_option,base.group_user,1,1,1,1
access_event_partner_category,event.partner_category,model_event_partner_category,base.group_user,1,1,1,1
access_event_membership_product,event.membership_product,model_event_membership_product,base.group_user,1,1,1,1
access_event_media_link,event_media_link,model_event_media_link,base.group_user,1,1,1,1
access_event_media_link_public,event_media_link_public,model_event_media_link,base.group_public,1,0,0,0
access_event_media_link_portal,event_media_link_portal,model_event_media_link,base.group_portal,1,0,0,0

+ 12
- 0
views/event.xml View File

@ -86,6 +86,18 @@
</group>
</page>
<page string="Media links" name="Media links">
<group style="width:80%%">
<field name="media_link_ids">
<tree editable="bottom">
<field name="media_link"/>
</tree>
</field>
</group>
</page>
</xpath>


+ 1
- 1
views/event_templates_list.xml View File

@ -37,7 +37,7 @@
<a t-if="tag.color"
t-att-href="'/event?tags='+tag.name"
t-attf-class="dropdown-item d-flex align-items-center justify-content-between #{'active' if tag in search_tags else ''}">
<t t-esc="tag.name"/>
<t t-esc="category.name+':'+tag.name"/>
</a>
</t>
</t>


+ 13
- 0
views/event_templates_page_registration.xml View File

@ -31,4 +31,17 @@
</xpath>
</template>
<template id="kalachakra.event_description_full" inherit_id="website_event.event_description_full">
<xpath expr="//span[@itemprop='description']" position="before">
<t t-if="event.media_link_ids">
<h6>Media links :</h6>
<t t-foreach="event.media_link_ids" t-as="media">
<a t-attf-href="media.media_link"><span t-esc="media.media_link" /></a>
<br></br>
</t>
</t>
</xpath>
</template>
</odoo>

+ 57
- 33
views/website_event_registration.xml View File

@ -101,9 +101,18 @@
</h7>
<br></br>
<br></br>
<t t-if="not already_registered">
<h7>your registration is taken into account !</h7>
<br></br>
<h7>You will soon receive a confirmation email.</h7>
</t>
<t t-if="already_registered">
<h7>You are already registered</h7>
<t t-if="payment_status=='paid'">
<br></br>
<h7>You have already paid</h7>
</t>
</t>
<br></br>
<br></br>
<t t-if="event.online_event">
@ -144,41 +153,43 @@
<br></br>
</t>
</t>
<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" id="pay_now_btn" class="btn btn-primary" >I pay the participation now</button>
<br></br>
<br></br>
<button type="submit" id="pay_on_the_spot_btn" class="btn btn-primary" >I will pay the participation on the spot</button>
<br></br>
<t t-if="payment_status!='paid'">
<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" id="pay_now_btn" class="btn btn-primary" >I pay the participation now</button>
<br></br>
<br></br>
<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'">
<h7>If you want to be a member, click here : </h7><button type="submit" class="btn btn-primary" >Become a member</button>
<br></br>
<br></br>
</t>
<t t-if="status=='member'">
<h7>If you want to be a super member, click here : </h7><button type="submit" class="btn btn-primary" >Become a super member</button>
<br></br>
<br></br>
</t>
</t>
</t>
<br></br>
<t t-if="status=='standard'">
<h7>If you want to be a member, click here : </h7><button type="submit" class="btn btn-primary" >Become a member</button>
<br></br>
<br></br>
</t>
<t t-if="status=='member'">
<h7>If you want to be a super member, click here : </h7><button type="submit" class="btn btn-primary" >Become a super member</button>
<br></br>
<br></br>
</t>
</t>
<t t-if="status in ('standard')">
<div class="row s_col_no_resize s_col_no_bgcolor">
<label class=" col-sm-auto s_website_form_label " for="pm84usjk8cf">
<span class="s_website_form_label_content">To stay informed I subscribe to the newsletter of the center</span>
</label>
<div class="col-sm">
<input type="checkbox" value="Yes" checked="checked" class="s_website_form_input" name="newsletter" required="1" id="pm84usjk8cf"/>
</div>
</div>
</t>
</t>
<br></br>
<t t-if="status in ('standard')">
<div class="row s_col_no_resize s_col_no_bgcolor">
<label class=" col-sm-auto s_website_form_label " for="pm84usjk8cf">
<span class="s_website_form_label_content">To stay informed I subscribe to the newsletter of the center</span>
</label>
<div class="col-sm">
<input type="checkbox" value="Yes" checked="checked" class="s_website_form_input" name="newsletter" required="1" id="pm84usjk8cf"/>
</div>
</div>
</t>
<br></br>
<br></br>
</form>
@ -201,4 +212,17 @@
</template>
<template id="kalachakra.already_member" name="alreadymember">
<t t-call="website.layout">
<div class="container-fluid">
<h6>You are already a member with this email adress : <span t-esc="email"/></h6>
<a href="/" class="ml-4 btn btn-secondary">back Home</a>
</div>
</t>
</template>
</odoo>

Loading…
Cancel
Save