diff --git a/controllers/booking.py b/controllers/booking.py index 1ed9850..c374bc3 100644 --- a/controllers/booking.py +++ b/controllers/booking.py @@ -51,7 +51,7 @@ class booking(WebsiteEventController,AuthSignupHome): if partner.member_status=='not member':data['price']=event.booking_price if partner.member_status=='member':data['price']=event.booking_member_price if partner.member_status=='super member':data['price']=event.booking_super_member_price - + #membership product #membership_product=request.env['event.membership_product'].sudo().search([]) membership_product=request.env['product.product'].sudo().search([('membership_product','=',True)],limit=1) @@ -64,7 +64,10 @@ class booking(WebsiteEventController,AuthSignupHome): if opt.booking_option_id==membership_product.id: if partner.member_status!='member' and partner.member_status!='super member':data['options'].append(opt) - else:data['options'].append(opt) + else: + + + data['options'].append(opt) @@ -198,39 +201,39 @@ class booking(WebsiteEventController,AuthSignupHome): url="/my/invoices/"+str(invoice.id)#+"?access_token="+str(invoice.access_token) return request.redirect(url) - #création du devis pour la transaction - order_id=request.env['event.registration'].sudo().action_event_registration_generate_order(res.id) + # #création du devis pour la transaction + # order_id=request.env['event.registration'].sudo().action_event_registration_generate_order(res.id) - order=request.env['sale.order'].sudo().search([("id","=",int(order_id))]) + # order=request.env['sale.order'].sudo().search([("id","=",int(order_id))]) - data={} - data['submit_txt']='Pay now' + # data={} + # data['submit_txt']='Pay now' - data['success_url']='/booking/payment/success' - data['error_url']='/booking/payment/error' - data['acquirers'] = list(request.env['payment.acquirer'].search([ - ('state', 'in', ['enabled', 'test']), - ('company_id', '=', request.env.company.id) - ])) + # data['success_url']='/booking/payment/success' + # data['error_url']='/booking/payment/error' + # data['acquirers'] = list(request.env['payment.acquirer'].search([ + # ('state', 'in', ['enabled', 'test']), + # ('company_id', '=', request.env.company.id) + # ])) - userid=request.env.context.get('uid') - user=request.env['res.users'].search([('id','=',int(userid))]) - partner=request.env['res.partner'].sudo().search([('id','=',int(user.partner_id))]) - request.session['partner_id']=int(partner.id) + # userid=request.env.context.get('uid') + # user=request.env['res.users'].search([('id','=',int(userid))]) + # partner=request.env['res.partner'].sudo().search([('id','=',int(user.partner_id))]) + # request.session['partner_id']=int(partner.id) - payment_tokens = partner.payment_token_ids - payment_tokens |= partner.commercial_partner_id.sudo().payment_token_ids + # payment_tokens = partner.payment_token_ids + # payment_tokens |= partner.commercial_partner_id.sudo().payment_token_ids - data['payment_tokens']=payment_tokens - data['order_id']=order_id + # data['payment_tokens']=payment_tokens + # data['order_id']=order_id - return http.request.render('kalachakra.booking_payment_choice_form',data) + # return http.request.render('kalachakra.booking_payment_choice_form',data) - #return http.request.redirect(order.access_url) + @http.route(['/booking/payment/transaction/', '/booking/payment/transaction/', diff --git a/controllers/kalachakra.py b/controllers/kalachakra.py index db9c898..dfa27be 100644 --- a/controllers/kalachakra.py +++ b/controllers/kalachakra.py @@ -165,27 +165,26 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): @http.route(['/event/registration/step1'], type='http', auth='user', website=True, sitemap=False,csrf=False) def event_registration_step1(self,event_id,*args,**kw): - + data={} #contact lié à l'utilisateur userid=request.env.context.get('uid') user=request.env['res.users'].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 + #évenement + event=request.env['event.event'].sudo().search([('id','=',int(event_id))]) + request.session['event_id']=int(event_id) + data['event']=event + #si le pays n'est pas renseigné, on le renseigne avec France - #c'est indispensable pour pouvoir régléer le devis if not partner.country_id: country=request.env['res.country'].search([('name','=','France')]) partner.country_id=country.id - data={} - data['partner']=partner - - #évenement - request.session['event_id']=int(event_id) - event=request.env['event.event'].sudo().search([('id','=',int(event_id))]) - data['event']=event - + + + data['status']=partner.member_status if data['status']=='not member':data['status']='non adhérent' if data['status']=='member':data['status']='adhérent' @@ -197,14 +196,22 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): @http.route(['/event/registration/step2'], type='http', auth='user', website=True, sitemap=False,csrf=False) - def event_registration_step2(self,**post): + def event_registration_step2(self,event_id,**post): data={} - partner=request.env['res.partner'].sudo().search([('id','=',int(request.session['partner_id']))]) - event=request.env['event.event'].sudo().search([('id','=',request.session['event_id'])]) + #contact lié à l'utilisateur + userid=request.env.context.get('uid') + user=request.env['res.users'].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 + + #évenement + event=request.env['event.event'].sudo().search([('id','=',int(event_id))]) + request.session['event_id']=int(event_id) data['event']=event data['online']=False - data['partner']=partner + if event.online_event: if post.get('online')=='yes':data['online']=True diff --git a/models/__init__.py b/models/__init__.py index 6fc0c78..ea90c66 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -19,3 +19,5 @@ from . import booking_donation from . import booking_sale_order from . import event_media_link from . import mailing_list +#from . import account + diff --git a/models/booking_event.py b/models/booking_event.py index f3e14c9..bd873a7 100644 --- a/models/booking_event.py +++ b/models/booking_event.py @@ -74,17 +74,35 @@ class EventBookingOptions(models.Model): -# class BookingEvent(models.Model): -# _inherit = "event.event" -# _description = 'Event' - - # booking_event = fields.Boolean(string="Booking event", tracking=True) - # question_ids=fields.One2many( - # 'event.question', - # 'event_id', - # string='Questions' +class BookingEvent(models.Model): + _inherit = "event.event" + _description = 'Event' + questionnaire_id=fields.Many2one('booking.questionnaire','questionnaire') + question_ids=fields.One2many( + 'event.question', + 'event_id', + string='Questions' - # ) + ) + @api.onchange('questionnaire_id') + def onchange_questionnaire(self): + + #on supprime les question existantes: + self.question_ids=False + questions=self.env['booking.question'].search([('questionnaire_id','=',int(self.questionnaire_id))]) + + #on rappatrie les questions + for question in questions: + + vals={} + vals['event_id']=self.id + vals['sequence']=question.sequence + vals['question']=question.question + self.question_ids = [(0, 0, vals)] + + + + # booking_option_ids=fields.One2many('booking.option','event_id','booking options') # @api.model diff --git a/models/booking_event_registration.py b/models/booking_event_registration.py index e991e14..fcd4bcf 100644 --- a/models/booking_event_registration.py +++ b/models/booking_event_registration.py @@ -90,6 +90,7 @@ class EventRegistration(models.Model): payment_status=fields.Char(string='payment status',compute='_compute_payment_status') + payment_adjustement=fields.Monetary('payment adjustement',currency_field='currency_id') def _compute_payment_status(self): @@ -150,7 +151,6 @@ class EventRegistration(models.Model): def create_donation(self,event_registration_id,partner_id,product_id,price_unit): vals={} vals['partner_id']=int(partner_id) - #raise Warning(vals['partner_id']) vals['donation_date']=datetime.now() vals['tax_receipt_option']='annual' @@ -175,6 +175,7 @@ class EventRegistration(models.Model): #create line donation vals['donation_id']=donation_draft.id product=self.env['product.product'].search([('id','=',int(product_id))]) + vals['product_id']=int(product_id) vals['display_name']=product.name vals['quantity']=1 @@ -185,190 +186,37 @@ class EventRegistration(models.Model): donation_line=self.env['donation.line'].sudo().create(vals) donation_draft.state='done' - def action_event_registration_generate_order(self,id_registration=None): - - - #suppression des devis existants - if self.order_id: - self.env['sale.order'].search([('id','=',int(self.order_id))]).unlink() - self.order_id=False - - if self.down_payment_order_id: - self.env['sale.order'].search([('id','=',int(self.down_payment_order_id))]).unlink() - self.down_payment_order_id=False - - if self.balance_order_id: - self.env['sale.order'].search([('id','=',int(self.balance_order_id))]).unlink() - self.balance_order_id=False - - #suppression des dons existants - self.env['donation.donation'].search([('id','in',self.donation_ids)]).unlink() - self.donation_ids=False - - if id_registration:reg=self.env['event.registration'].search([('id','=',int(id_registration))]) - else : reg=self - - event=self.env['event.event'].search([('id','=',int(reg.event_id))]) - selected_registrant_options=self.env['event.registration_option'].search([ - ('event_registration_id','=',int(reg.id))]) - - #controles avant traitement : un produit doit être associé à l'événement - if not event.booking_product_id: raise Warning('product missing for event booking') - - #Prix à appliquer au produit en fonction du statut de l'inscrit - status=reg.partner_id.member_status - product_price=event.booking_price - if status=='not member':product_price=event.booking_price - if status=='member':product_price=event.booking_member_price - if status=='super member':product_price=event.booking_super_member_price - - #Prix à appliquer au produit si paiement de l'adhésion - membership_option=False - membership_product=self.env['event.membership_product'].search([]) - if membership_product: - if selected_registrant_options: - for opt in selected_registrant_options: - if opt.booking_option_id==membership_product.id: - membership_option=True - if status!="super member": - product_price=event.booking_member_price - - #calcul du montant total à régler - - - #création du devis sans accompte - - if not reg.down_payment: - #création du devis - vals={} - - vals['partner_id']=int(reg.partner_id) - order=self.env['sale.order'].create(vals) - #création des lignes de devis - vals={} - vals['order_id']=order.id - #ajout du produit - vals['product_id']=int(event.booking_product_id) - vals['product_uom_qty']=1 - vals['price_unit']=product_price - vals['name']=event.booking_product_id.name - order_line=self.env['sale.order.line'].create(vals) - - #ajout des options - vals={} - if selected_registrant_options: - for option in selected_registrant_options: - - vals['order_id']=order.id - vals['product_id']=int(option.booking_option_id.id) - vals['product_uom_qty']=1 - - prd=self.env['product.product'].search([('id','=',int(option.booking_option_id.id))]) - - - vals['name']=prd.name - - #prix à appliquer aux options en fonction du statut ou de la présence de l'option d'adhesion - event_option=self.env['booking.option'].search(['&',('event_id','=',int(reg.event_id)),('booking_option_id','=',int(option.booking_option_id.id))]) - - if event_option: - if status=="super member":vals['price_unit']=event_option.booking_option_super_member_price - if status=="member":vals['price_unit']=event_option.booking_option_member_price - if status=="not member" and membership_option: vals['price_unit']=event_option.booking_option_member_price - if status=="not member" and not membership_option: vals['price_unit']=event_option.booking_option_price - - order_line=self.env['sale.order.line'].create(vals) - #si l'option est un produit de don on créé un don pour la personne - #if prd.donation: self.create_donation(reg.id,reg.partner_id,vals['product_id'],vals['price_unit']) - - order.message_subscribe(partner_ids=order.partner_id.ids) - order.state='sent' - reg.order_id=order.id - - return order.id - - - #2 devis si paiement avec acompte - else: - #création du 1er devis d'acompte - vals={} - vals['partner_id']=int(reg.partner_id) - order=self.env['sale.order'].create(vals) - #création des lignes de devis - vals={} - vals['order_id']=order.id - #ajout du produit - vals['product_id']=int(event.booking_product_id) - vals['product_uom_qty']=1 - vals['price_unit']=event.booking_down_payment - vals['name']='Acompte '+event.booking_product_id.name - order_line=self.env['sale.order.line'].create(vals) - order.message_subscribe(partner_ids=order.partner_id.ids) - order.state='sent' - reg.down_payment_order_id=order.id - - - #création du 2ème devis de solde + paiement des options - - vals={} - - vals['partner_id']=int(reg.partner_id) - order2=self.env['sale.order'].create(vals) - #création des lignes de devis - vals={} - vals['order_id']=order2.id - #ajout du produit - vals['product_id']=int(event.booking_product_id) - vals['product_uom_qty']=1 - vals['price_unit']=product_price-event.booking_down_payment - vals['name']='solde '+event.booking_product_id.name - order_line=self.env['sale.order.line'].create(vals) - - #ajout des options - vals={} - if selected_registrant_options: - for option in selected_registrant_options: - - vals['order_id']=order2.id - vals['product_id']=int(option.booking_option_id.id) - vals['product_uom_qty']=1 - - prd=self.env['product.product'].search([('id','=',int(option.booking_option_id.id))]) - vals['name']=prd.name - - #prix à appliquer aux options en fonction du statut ou de la présence de l'option d'adhesion - event_option=self.env['booking.option'].search(['&',('event_id','=',int(reg.event_id)),('booking_option_id','=',int(option.booking_option_id.id))]) - - if event_option: - if status=="super member":vals['price_unit']=event_option.booking_option_super_member_price - if status=="member":vals['price_unit']=event_option.booking_option_member_price - if status=="not member" and membership_option: vals['price_unit']=event_option.booking_option_member_price - if status=="not member" and not membership_option: vals['price_unit']=event_option.booking_option_price - - order_line=self.env['sale.order.line'].create(vals) - order2.message_subscribe(partner_ids=order2.partner_id.ids) - order2.state='sent' - reg.balance_order_id=order2.id - return order.id + def action_event_registration_generate_invoice(self,id_registration=None): #suppression des factures existantes - # if self.invoice_id: - # self.env['account.move'].search([('id','=',int(self.invoice_id))]).unlink() - # self.invoice_id=False + if self.invoice_id: + invoice=self.env['account.move'].sudo().search([('id','=',int(self.invoice_id))]) + invoice.state='draft' + + #invoice2=self.env['account.move'].sudo().search([('payment_reference','=',invoice.payment_reference)]) + #invoice2.unlink() + #raise Warning(invoice2) - # if self.down_payment_invoice_id: + if self.down_payment_invoice_id: + invoice=self.env['account.move'].sudo().search([('id','=',int(self.down_payment_invoice_id))]) + invoice.state='draft' # self.env['account.move'].search([('id','=',int(self.down_payment_invoice_id))]).unlink() # self.down_payment_invoice_id=False - # if self.balance_invoice_id: + if self.balance_invoice_id: + invoice=self.env['account.move'].sudo().search([('id','=',int(self.balance_invoice_id))]) + invoice.state='draft' # self.env['account.move'].search([('id','=',int(self.balance_invoice_id))]).unlink() # self.balance_invoice_id=False #suppression des dons existants - self.env['donation.donation'].search([('id','in',self.donation_ids)]).unlink() + donation=self.env['donation.donation'].sudo().search([('id','in',self.donation_ids.ids)]) + for d in donation: + d.state='draft' + self.env['donation.donation'].sudo().search([('id','in',self.donation_ids.ids)]).unlink() self.donation_ids=False if id_registration:reg=self.env['event.registration'].search([('id','=',int(id_registration))]) @@ -378,6 +226,7 @@ class EventRegistration(models.Model): selected_registrant_options=self.env['event.registration_option'].search([ ('event_registration_id','=',int(reg.id))]) + #controles avant traitement : un produit doit être associé à l'événement if not event.booking_product_id: raise Warning('product missing for event booking') @@ -414,9 +263,9 @@ class EventRegistration(models.Model): vals['invoice_date']=datetime.now() #mode de paiement CB par defaut - electronic_method=self.env['account.payment.method'].search([('code','=','electronic')],limit=1) + electronic_method=self.env['account.payment.method'].sudo().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) + cb_mode=self.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: @@ -425,14 +274,14 @@ class EventRegistration(models.Model): vals['move_type']='out_invoice' vals['state']='draft' #vals['currency_id']=self.currency_id.id - invoice=self.env['account.move'].create(vals) + invoice=self.env['account.move'].sudo().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')]) + account_credit=self.env['account.account'].sudo().search([('code','=','707100')]) + account_debit=self.env['account.account'].sudo().search([('code','=','411100')]) vals['move_id']=invoice.id vals['product_id']=int(event.booking_product_id) @@ -442,7 +291,7 @@ class EventRegistration(models.Model): vals['account_id']=int(account_credit.id) - invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).create(vals) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) # #debit_line @@ -460,8 +309,8 @@ class EventRegistration(models.Model): 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)]) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals_d) + l=self.env['account.move.line'].sudo().search([('move_id','=',invoice.id),('balance','<',0)]) l.partner_id=int(reg.partner_id) @@ -470,10 +319,10 @@ class EventRegistration(models.Model): if selected_registrant_options: for option in selected_registrant_options: - prd=self.env['product.product'].search([('id','=',int(option.booking_option_id.id))]) - + prd=self.env['product.product'].sudo().search([('id','=',int(option.booking_option_id.id))]) + #prix à appliquer aux options en fonction du statut ou de la présence de l'option d'adhesion - event_option=self.env['booking.option'].search(['&',('event_id','=',int(reg.event_id)),('booking_option_id','=',int(option.booking_option_id.id))],limit=1) + event_option=self.env['booking.option'].sudo().search(['&',('event_id','=',int(reg.event_id)),('booking_option_id','=',int(option.booking_option_id.id))],limit=1) if event_option: if status=="super member":price_unit=event_option.booking_option_super_member_price @@ -481,15 +330,16 @@ class EventRegistration(models.Model): if status=="not member" and membership_option:price_unit=event_option.booking_option_member_price if status=="not member" and not membership_option:price_unit=event_option.booking_option_price + vals={} vals['move_id']=invoice.id #ajout du produit - vals['product_id']=int(event.booking_product_id) + vals['product_id']=int(option.booking_option_id.id) vals['quantity']=1 vals['price_unit']=price_unit vals['name']=prd.name vals['account_id']=int(account_credit.id) - invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).create(vals) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) #debit_line @@ -506,13 +356,13 @@ class EventRegistration(models.Model): vals_d['price_unit']=price_unit vals_d['exclude_from_invoice_tab']=True - invoice_line=self.env['account.move.line'].with_context(check_move_validity=True).create([vals_d]) - l=self.env['account.move.line'].search([('move_id','=',invoice.id),('balance','<',0)]) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=True).sudo().create([vals_d]) + l=self.env['account.move.line'].sudo().search([('move_id','=',invoice.id),('balance','<',0)]) l.partner_id=int(reg.partner_id) #si l'option est un produit de don on créé un don pour la personne - if prd.donation: self.create_donation(reg.id,reg.partner_id,vals['product_id'],vals['price_unit']) + if prd.donation: self.sudo().create_donation(reg.id,reg.partner_id,vals['product_id'],vals['price_unit']) reg.invoice_id=invoice.id @@ -529,9 +379,9 @@ class EventRegistration(models.Model): vals['invoice_date']=datetime.now() #mode de paiement CB par defaut - electronic_method=self.env['account.payment.method'].search([('code','=','electronic')],limit=1) + electronic_method=self.env['account.payment.method'].sudo().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) + cb_mode=self.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: @@ -540,14 +390,14 @@ class EventRegistration(models.Model): vals['move_type']='out_invoice' vals['state']='draft' #vals['currency_id']=self.currency_id.id - invoice=self.env['account.move'].create(vals) + invoice=self.env['account.move'].sudo().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')]) + account_credit=self.env['account.account'].sudo().search([('code','=','707100')]) + account_debit=self.env['account.account'].sudo().search([('code','=','411100')]) vals['move_id']=invoice.id vals['product_id']=int(event.booking_product_id) @@ -557,7 +407,7 @@ class EventRegistration(models.Model): vals['account_id']=int(account_credit.id) - invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).create(vals) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) # #debit_line @@ -575,8 +425,8 @@ class EventRegistration(models.Model): 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)]) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals_d) + l=self.env['account.move.line'].sudo().search([('move_id','=',invoice.id),('balance','<',0)]) l.partner_id=int(reg.partner_id) reg.down_payment_invoice_id=invoice.id @@ -591,7 +441,7 @@ class EventRegistration(models.Model): vals['move_type']='out_invoice' vals['state']='draft' #vals['currency_id']=self.currency_id.id - invoice=self.env['account.move'].create(vals) + invoice=self.env['account.move'].sudo().create(vals) invoice.state='posted' invoice.name='REC'+str(invoice.id) @@ -607,7 +457,7 @@ class EventRegistration(models.Model): vals['account_id']=int(account_credit.id) - invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).create(vals) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) # #debit_line @@ -625,8 +475,8 @@ class EventRegistration(models.Model): 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)]) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals_d) + l=self.env['account.move.line'].sudo().search([('move_id','=',invoice.id),('balance','<',0)]) l.partner_id=int(reg.partner_id) @@ -634,8 +484,8 @@ class EventRegistration(models.Model): if selected_registrant_options: for option in selected_registrant_options: - prd=self.env['product.product'].search([('id','=',int(option.booking_option_id.id))]) - + prd=self.env['product.product'].sudo().search([('id','=',int(option.booking_option_id.id))]) + #prix à appliquer aux options en fonction du statut ou de la présence de l'option d'adhesion event_option=self.env['booking.option'].search(['&',('event_id','=',int(reg.event_id)),('booking_option_id','=',int(option.booking_option_id.id))]) @@ -645,6 +495,12 @@ class EventRegistration(models.Model): if status=="not member" and membership_option:price_unit=event_option.booking_option_member_price if status=="not member" and not membership_option:price_unit=event_option.booking_option_price + #calcul du prix en fonction du sejour,nuité, ou jour + # if prd.price_per=='day': + # price_unit=price_unit*event.duration + # if prd.price_per=='night': + # price_unit=price_unit*event.duration-1 + vals={} vals['move_id']=invoice.id #ajout du produit @@ -653,7 +509,7 @@ class EventRegistration(models.Model): vals['price_unit']=price_unit vals['name']=prd.name vals['account_id']=int(account_credit.id) - invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).create(vals) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) #debit_line @@ -670,13 +526,13 @@ class EventRegistration(models.Model): vals_d['price_unit']=price_unit vals_d['exclude_from_invoice_tab']=True - invoice_line=self.env['account.move.line'].with_context(check_move_validity=True).create([vals_d]) + invoice_line=self.env['account.move.line'].with_context(check_move_validity=True).sudo().create([vals_d]) l=self.env['account.move.line'].search([('move_id','=',invoice.id),('balance','<',0)]) l.partner_id=int(reg.partner_id) #si l'option est un produit de don on créé un don pour la personne - if prd.donation: self.create_donation(reg.id,reg.partner_id,vals['product_id'],vals['price_unit']) + if prd.donation: self.sudo().create_donation(reg.id,reg.partner_id,vals['product_id'],vals['price_unit']) reg.balance_invoice_id=invoice.id return invoice.id diff --git a/models/event.py b/models/event.py index 40a6150..82134a3 100644 --- a/models/event.py +++ b/models/event.py @@ -5,7 +5,7 @@ from psycopg2 import sql, DatabaseError from pytz import timezone from werkzeug import utils -from odoo.tools import remove_accents + import os.path from google.oauth2 import service_account @@ -56,7 +56,7 @@ class KalachakraEvent(models.Model): onthespot_event=fields.Boolean('Online event') online_link=fields.Char('link') online_id=fields.Char('id') - online_password=fields.Char('password') + online_password=fields.Char('password',default='123456') 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') ]) @@ -64,9 +64,20 @@ class KalachakraEvent(models.Model): 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) - + find_out_more_link=fields.Char('Find out more link') + def write(self,vals): + res = super(KalachakraEvent, self).write(vals) + #mise à jour du calendrier google si + #modification date de début ou date de fin + #modification du nom de l'événement + if self.calendar_event_id: + + if vals.get('date_begin') or vals.get('date_end') or vals.get('name'): + + self.update_event_google_agenda() + def _compute_generated_events(self): for rec in self: @@ -89,9 +100,10 @@ class KalachakraEvent(models.Model): if rec.end_generation_date100:raise Warning('action cancelled: the duration f the event is more than 100 days !') - + if delta.days>200:raise Warning('action cancelled: the duration f the event is more than 6 months !') + if rec.frequency=='daily':d=1 + if rec.frequency=='weekly':d=7 start_date_event=rec.date_begin+timedelta(days=d) @@ -167,41 +179,57 @@ class KalachakraEvent(models.Model): booking_price=fields.Monetary('Price',currency_field='currency_id') booking_member_price=fields.Monetary('Member price',currency_field='currency_id') booking_super_member_price=fields.Monetary('Super member price',currency_field='currency_id') - booking_down_payment=fields.Monetary('Down payment',currency_field='currency_id') + booking_down_payment=fields.Monetary('Down payment',default=50,currency_field='currency_id') booking_product_id=fields.Many2one('product.product',string='booking product',domain="[('booking_product','=','True')]") - @api.onchange('event_type_id') - def onchange_state(self): - self.booking_event=self.event_type_id.booking_event - - booking_option=self.env['booking.option'].search([('event_type_id','=',int(self.event_type_id))]) - if booking_option: - #on supprime les options existantes: - self.booking_option_ids=False - - #on rappatrie les options du modèle - for option in booking_option: - vals={} - vals['event_id']=self.id - vals['booking_option_id']=option.booking_option_id - vals['booking_option_price']=option.booking_option_price - vals['currency_id']=option.currency_id - self.booking_option_ids = [(0, 0, vals)] + @api.onchange('booking_event') + def onchange_bookin_event(self): + if self.booking_event: + + booking_option=self.env['product.product'].search([('booking_option_product','=',True)]) + if booking_option: + + #on supprime les options existantes: + self.booking_option_ids=False + + #on rappatrie les options + for option in booking_option: + id_prd=int(option.id) + prd=self.env['product.product'].sudo().search([('id','=',id_prd)]) + vals={} + #calcul du prix en fonction du sejour,nuité, ou jour + price=option.list_price + if prd.price_per=='day': + price=option.list_price*self.duration + if prd.price_per=='night': + price=option.list_price*self.duration-1 + + vals['event_id']=self.id + vals['booking_option_id']=option.id + vals['booking_option_price']=price + vals['booking_option_member_price']=price + vals['booking_option_super_member_price']=price + vals['currency_id']=option.currency_id + self.booking_option_ids = [(0, 0, vals)] - if self.event_type_id.booking_questionnaire_id: + # if self.event_type_id.booking_questionnaire_id: - #on supprime les question existantes: - self.question_ids=False - questions=self.env['booking.question'].search([('questionnaire_id','=',int(self.event_type_id.booking_questionnaire_id))]) - #on rappatrie les question - for question in questions: - vals={} - vals['event_id']=self.id - vals['sequence']=question.sequence - vals['question']=question.question + # #on supprime les question existantes: + # self.question_ids=False + # questions=self.env['booking.question'].search([('questionnaire_id','=',int(self.event_type_id.booking_questionnaire_id))]) + # #on rappatrie les question + # for question in questions: + # vals={} + # vals['event_id']=self.id + # vals['sequence']=question.sequence + # vals['question']=question.question - self.question_ids = [(0, 0, vals)] + # self.question_ids = [(0, 0, vals)] + + + + @api.model @@ -235,7 +263,7 @@ class KalachakraEvent(models.Model): start=self.date_begin.astimezone(timezone('Europe/Paris')) end=self.date_end.astimezone(timezone('Europe/Paris')) - + start=start.isoformat() end=end.isoformat() diff_date=self.date_end-self.date_begin @@ -246,14 +274,7 @@ class KalachakraEvent(models.Model): name_param=self.name.replace(' ','-') name_param=name_param.replace('\'','-') - nbcars=300 - ldesc=len(self.description) - if ldescEn savoir plus' + description='Click here to register' #str(self.date_begin.year())+'-'+str(self.date_begin.month())+'-'+self.date_begin.day() body={"summary": self.name, @@ -263,6 +284,7 @@ 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: @@ -288,6 +310,34 @@ class KalachakraEvent(models.Model): self.calendar_event_id=False self.calendar_id=False - + + def update_event_google_agenda(self): + credentials = service_account.Credentials.from_service_account_file(GOOGLE_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')) + + start=start.isoformat() + end=end.isoformat() + diff_date=self.date_end-self.date_begin + if diff_date.days>0: + date_param=self.date_begin.strftime('%Y-%m-%d')+'-'+self.date_end.strftime('%Y-%m-%d')+'-'+str(self.id) + else: + date_param=self.date_begin.strftime('%Y-%m-%d')+'-'+str(self.id) + + name_param=self.name.replace(' ','-') + name_param=name_param.replace('\'','-') + description='Click here to register' + #str(self.date_begin.year())+'-'+str(self.date_begin.month())+'-'+self.date_begin.day() + + body={"summary": self.name, + "description": description, + "start": {"dateTime": start, "timeZone": 'Europe/Paris'}, + "end": {"dateTime": end, "timeZone": 'Europe/Paris'}, + } + #event = service.events().get(calendarId=self.calendar_id, eventId=self.calendar_event_id).execute() + updated_event = service.events().update(calendarId=self.calendar_id, eventId=self.calendar_event_id, body=body).execute() \ No newline at end of file diff --git a/models/product.py b/models/product.py index 0bd0d92..87daa5c 100644 --- a/models/product.py +++ b/models/product.py @@ -12,4 +12,5 @@ class KalachakraProductTemplate(models.Model): super_membership_product = fields.Boolean(string="super membership product", tracking=True) booking_product = fields.Boolean(string="booking product", tracking=True) booking_option_product = fields.Boolean(string="booking option product", tracking=True) + price_per=fields.Selection(string="Price per",selection=[('stay','Stay'),('night', 'Night'), ('day', 'Day')], default='stay', tracking=True) \ No newline at end of file diff --git a/static/src/css/kalachakra.css b/static/src/css/kalachakra.css index cba17d1..8e9e7cb 100644 --- a/static/src/css/kalachakra.css +++ b/static/src/css/kalachakra.css @@ -1,4 +1,5 @@ .header{ position:sticky; top: 0 ; -} \ No newline at end of file +} + diff --git a/views/booking_event.xml b/views/booking_event.xml index af035c1..1f8c8b0 100644 --- a/views/booking_event.xml +++ b/views/booking_event.xml @@ -115,12 +115,12 @@ + - - - + + - + diff --git a/views/booking_event_registration.xml b/views/booking_event_registration.xml index c368d57..0bf1205 100644 --- a/views/booking_event_registration.xml +++ b/views/booking_event_registration.xml @@ -65,7 +65,7 @@ - + @@ -98,6 +98,8 @@ + + diff --git a/views/booking_product.xml b/views/booking_product.xml index b6f9d89..0a2c221 100644 --- a/views/booking_product.xml +++ b/views/booking_product.xml @@ -22,17 +22,15 @@ - + \ No newline at end of file diff --git a/views/event.xml b/views/event.xml index 42068e6..f697675 100644 --- a/views/event.xml +++ b/views/event.xml @@ -47,7 +47,7 @@ - + diff --git a/views/event_templates_page_registration.xml b/views/event_templates_page_registration.xml index 84c7318..3546ec8 100644 --- a/views/event_templates_page_registration.xml +++ b/views/event_templates_page_registration.xml @@ -43,10 +43,18 @@
Media links :
- +

+ + +

+ Find out more +

+ +
+
\ No newline at end of file diff --git a/views/product.xml b/views/product.xml index 31abcc3..c537588 100644 --- a/views/product.xml +++ b/views/product.xml @@ -4,13 +4,19 @@ product.template -
-

+
+ -
diff --git a/views/website_event_registration.xml b/views/website_event_registration.xml index 8fb1903..275fcf8 100644 --- a/views/website_event_registration.xml +++ b/views/website_event_registration.xml @@ -33,8 +33,8 @@

-
- + +
- + + +