diff --git a/controllers/kalachakra.py b/controllers/kalachakra.py index 5689f75..c6e781f 100644 --- a/controllers/kalachakra.py +++ b/controllers/kalachakra.py @@ -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={} diff --git a/models/__init__.py b/models/__init__.py index 708920d..aa259ac 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -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 \ No newline at end of file +from . import event_media_link diff --git a/models/booking_event_registration.py b/models/booking_event_registration.py index d1a047b..352acb0 100644 --- a/models/booking_event_registration.py +++ b/models/booking_event_registration.py @@ -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: diff --git a/models/event_registration.py b/models/event_registration.py index a923298..355e3f0 100644 --- a/models/event_registration.py +++ b/models/event_registration.py @@ -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)]) diff --git a/models/membership.py b/models/membership.py index 60d55c0..6811fb4 100644 --- a/models/membership.py +++ b/models/membership.py @@ -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): diff --git a/models/partner.py b/models/partner.py index c9f2f56..2bd8d1d 100644 --- a/models/partner.py +++ b/models/partner.py @@ -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' diff --git a/static/js/kalachakra.js b/static/js/kalachakra.js index 20891ef..3f7e4f0 100644 --- a/static/js/kalachakra.js +++ b/static/js/kalachakra.js @@ -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'); diff --git a/views/membership.xml b/views/membership.xml index f96fcdc..e0aa737 100644 --- a/views/membership.xml +++ b/views/membership.xml @@ -11,7 +11,7 @@ - + diff --git a/views/website_event_registration.xml b/views/website_event_registration.xml index 707cb2b..ec5aeb7 100644 --- a/views/website_event_registration.xml +++ b/views/website_event_registration.xml @@ -153,7 +153,7 @@

- + The amount of the contribution is : @@ -163,11 +163,13 @@



- -

-

+ - If you want to be a member, click here : + If you want to become a member for one year and pay the participation, +

+ the amount is : +

+



@@ -176,6 +178,9 @@



+ +

+



@@ -189,7 +194,7 @@ - +