Browse Source

paiement de l'adhesion lors de l'inscription

dev-rcn
root 3 years ago
parent
commit
7f76584fbc
9 changed files with 119 additions and 26 deletions
  1. +69
    -4
      controllers/kalachakra.py
  2. +1
    -1
      models/__init__.py
  3. +0
    -3
      models/booking_event_registration.py
  4. +16
    -10
      models/event_registration.py
  5. +13
    -0
      models/membership.py
  6. +1
    -1
      models/partner.py
  7. +7
    -0
      static/js/kalachakra.js
  8. +1
    -1
      views/membership.xml
  9. +11
    -6
      views/website_event_registration.xml

+ 69
- 4
controllers/kalachakra.py View File

@ -212,6 +212,11 @@ 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)
membership_product=request.env['product.product'].sudo().search([('membership_product','=',True)],limit=1)
if not membership_product: raise UserError(_('No membership product, please add one'))
data['membership_amount']=membership_product.list_price
data['membership_and_participation_amount']=data['membership_amount']+data['participation_amount']
#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
@ -227,7 +232,8 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
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')
membership=False
invoice_id=request.env['event.registration'].sudo().action_generate_participation_invoice(int(res.id),'CB',membership)
request.session['res_id']=res.id
@ -266,18 +272,50 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
return http.request.render('kalachakra.onthespotpayment')
@http.route(['/kalachakra/participation'], type='http', auth='user', website=True, sitemap=False,csrf=False)
@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'])])
invoice_id=res.invoice_id
invoice=request.env['account.move'].sudo().search([('id','=',int(invoice_id))]).unlink()
invoice.state='posted'
#redirection sur la page de paiement de la facture :
url="/my/invoices/"+str(int(res.invoice_id))
return request.redirect(url)
if type=='membership_and_participation':
res=request.env['event.registration'].sudo().search([('id','=',request.session['res_id'])])
#suppression de la facture sans adhésion
invoice_id=res.invoice_id
res.invoice_id=False
request.env['account.move'].sudo().search([('id','=',int(invoice_id))]).unlink()
#creation de la facture avec adhésion
membership=True
invoice_id=request.env['event.registration'].sudo().action_generate_participation_invoice(int(res.id),'CB',membership)
invoice=request.env['account.move'].sudo().search([('id','=',int(invoice_id))])
res.invoice_id=invoice.id
res.with_membership=True
invoice.state='posted'
#création de l'adhésion à régler
#ajout de l'adhésion
membership_product=request.env['product.product'].sudo().search([('membership_product','=',True)],limit=1)
if not membership_product: raise UserError(_('No membership product, please add one'))
vals={}
vals['invoice_id']=int(invoice.id)
vals['partner_id']=int(res.partner_id)
vals['product_id']=int(membership_product.id)
vals['start_date']=datetime.now()
vals['end_date']=datetime.now()+relativedelta(years=1)
vals['amount']=membership_product.list_price
membership=request.env['kalachakra.membership'].sudo().create(vals)
#redirection sur la page de paiement de la facture :
url="/my/invoices/"+str(int(res.invoice_id))#+"?access_token="+str(invoice.access_token)
url="/my/invoices/"+str(int(res.invoice_id))
return request.redirect(url)
@ -398,9 +436,23 @@ 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)
#création du compte utilisateur
user=request.env['res.users'].sudo().search([('email','=',partner.email)])
group_portal=request.env.ref('base.group_portal')
if not user:
request.env['res.users'].sudo().create({
'name': partner.name,
'login': partner.email,
'email': partner.email,
'partner_id':partner.id,
'groups_id': [(4, group_portal.id)]
})
user.sudo().action_reset_password()
#si le contact existe :
#on met à jour ses informations
else:
vals={}
vals['name']=post.get('name')
@ -412,6 +464,19 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
vals['country_id']=int(post.get('country_id'))
vals['phone']=post.get('phone')
partner.sudo().write(vals)
user=request.env['res.users'].sudo().search([('email','=',partner.email)])
group_portal=request.env.ref('base.group_portal')
#création du compte utilisateur
if not user:
request.env['res.users'].sudo().create({
'name': partner.name,
'login': partner.email,
'email': partner.email,
'partner_id':partner.id,
'groups_id': [(4, group_portal.id)]
})
user.sudo().action_reset_password()
#on vérifie qu'il n'est pas déjà adhérent si demande d'adhésion
if partner.member_status in ('member','super member') and request.session['kalachakra_transaction']=='membership':
data={}


+ 1
- 1
models/__init__.py View File

@ -17,4 +17,4 @@ from . import booking_questionnaire
from . import booking_event_registration
from . import booking_donation
from . import booking_sale_order
from . import event_media_link
from . import event_media_link

+ 0
- 3
models/booking_event_registration.py View File

@ -106,9 +106,6 @@ class EventRegistration(models.Model):
if rec.down_payment_invoice_state=='paid' and rec.balance_payment_invoice_state=='paid' :rec.payment_status='paid'
if rec.down_payment_invoice_state=='paid' and rec.balance_payment_invoice_state!='paid':rec.payment_status='down payment paid'
def _compute_kanban_color(self):
for rec in self:


+ 16
- 10
models/event_registration.py View File

@ -12,13 +12,18 @@ class EventRegistration(models.Model):
online=fields.Boolean(string='Online participation')
onthespot_payment=fields.Boolean(string='On the spot payment')
free_participation=fields.Boolean(related='event_id.free_participation')
with_membership=fields.Boolean('with membership')
def action_generate_participation_invoice(self,id_registration=None,payment_mode=None):
def action_generate_participation_invoice(self,id_registration=None,payment_mode=None,membership=False):
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))])
if membership:
membership_product=self.env['product.product'].search([('membership_product','=',True)],limit=1)
if not membership_product: raise UserError(_('No membership product, please add one'))
#Prix à appliquer au produit en fonction du statut de l'inscrit
status=reg.partner_id.member_status
@ -46,14 +51,17 @@ class EventRegistration(models.Model):
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.state='posted'
invoice.name='REC'+str(invoice.id)
invoice.payment_reference=invoice.name
#creation des écritures comptable
name=event.participation_product_id.name
if membership and status=='not member':
product_price=product_price+membership_product.list_price
name=event.participation_product_id.name+"+"+membership_product.name
vals={}
account_credit=self.env['account.account'].search([('code','=','707100')])
account_debit=self.env['account.account'].search([('code','=','411100')])
@ -62,13 +70,12 @@ class EventRegistration(models.Model):
vals['product_id']=int(event.participation_product_id)
vals['quantity']=1
vals['price_unit']=product_price
vals['name']=event.participation_product_id.name
vals['name']=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
@ -77,12 +84,11 @@ class EventRegistration(models.Model):
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['name']=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)])


+ 13
- 0
models/membership.py View File

@ -17,6 +17,19 @@ class kalachakra_membership(models.Model):
)
product_id=fields.Many2one('product.product',required=True,string='membership product',domain="[('membership_product','=',True)]")
start_date=fields.Date('start date',required=True,default=lambda self: fields.Date.today())
invoice_id=fields.Many2one('account.move','invoice')
payment_state=fields.Selection(string='payment_state',selection=[('paid', 'paid'), ('not paid', 'not paid')],compute='_compute_payment_state')
def _compute_payment_state(self):
for rec in self:
rec.payment_state='not paid'
#adhesion via page d'ahésion
if rec.state=='done':rec.payment_state='paid'
#adhésion via isncription à l'événement
if rec.invoice_id:
if rec.invoice_id.payment_state=='paid':
rec.payment_state='paid'
rec.state='done'
def _default_end_date(self):


+ 1
- 1
models/partner.py View File

@ -63,7 +63,7 @@ class ResPartner(models.Model):
def _compute_member_status(self):
for rec in self:
member=rec.env['kalachakra.membership'].search([('partner_id','=',rec.id),('end_date','>=',datetime.now()),('state','=','done')])
member=rec.env['kalachakra.membership'].search([('partner_id','=',rec.id),('end_date','>=',datetime.now()),('payment_state','=','paid')])
if member : rec.member_status='member'
else :rec.member_status='not member'
if rec.super_member: rec.member_status='super member'


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

@ -25,6 +25,13 @@ odoo.define('kalachakra.main', function (require) {
$( "#form" ).submit();
});
$( "#pay_membership_btn" ).click(function() {
$('#form').attr('action', '/kalachakra/participation?type=membership_and_participation');
$( "#form" ).submit();
});
$( "#pay_on_the_spot_btn" ).click(function() {
$('#form').attr('action', '/kalachakra/onthespotpayment');


+ 1
- 1
views/membership.xml View File

@ -11,7 +11,7 @@
<field name="partner_id"/>
<field name="product_id"/>
<field name="amount"/>
<field name="state"/>
<field name="payment_state"/>
<field name="start_date"/>
<field name="end_date"/>
</tree>


+ 11
- 6
views/website_event_registration.xml View File

@ -153,7 +153,7 @@
<br></br>
</t>
</t>
<t t-if="payment_status!='paid'">
<!-- <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>
@ -163,11 +163,13 @@
<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>
<h7> If you want to become a member for one year and pay the participation,</h7>
<br></br>
<h7>the amount is : </h7><b><h7 t-esc="membership_and_participation_amount"></h7><h7></h7></b>
<br></br>
<button type="submit" id="pay_membership_btn" class="btn btn-primary" >Become a member and pay</button>
<br></br>
<br></br>
</t>
@ -176,6 +178,9 @@
<br></br>
<br></br>
</t>
<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>
<br></br>
@ -189,7 +194,7 @@
</div>
</div>
</t>
</t>
<!-- </t> -->
<br></br>
<br></br>
</form>


Loading…
Cancel
Save