diff --git a/models/booking_event_registration.py b/models/booking_event_registration.py index 7e99f08..5142404 100644 --- a/models/booking_event_registration.py +++ b/models/booking_event_registration.py @@ -195,26 +195,32 @@ class EventRegistration(models.Model): def remove_invoice(self): - if self.invoice_id and self.invoice_state!='paid': - 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 and self.down_payment_invoice_state!='paid': - #si la facture d'acompte est payé, on le la supprime pas - 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 + invoice=self.env['account.move'].sudo().search([('id','=',int(self.invoice_id))]) + if invoice: + if invoice.payment_state!='paid': + invoice.state='draft' + invoice_id=self.invoice_id + self.invoice_id=False + self.env['account.move'].sudo().search([('id','=',int(invoice_id))]).unlink() + + invoice=self.env['account.move'].sudo().search([('id','=',int(self.down_payment_invoice_id))]) + if invoice: + if invoice.payment_state!='paid': + invoice.state='draft' + invoice_id=self.down_payment_invoice_id + self.down_payment_invoice_id=False + self.env['account.move'].sudo().search([('id','=',int(invoice_id))]).unlink() - if self.balance_invoice_id and self.balance_invoice_state!='paid': - 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 + invoice=self.env['account.move'].sudo().search([('id','=',int(self.balance_invoice_id))]) + if invoice: + if invoice.payment_state!='paid': + invoice.state='draft' + invoice_id=self.balance_invoice_id + self.balance_invoice_id=False + self.env['account.move'].sudo().search([('id','=',int(invoice_id))]).unlink() + + return True def remove_donation(self): @@ -239,8 +245,12 @@ class EventRegistration(models.Model): #suppression des dons existants lié aux options de l'inscription self.remove_donation() else: - invoice=self.env['account.move'].sudo().search([('id','=',int(self.end_of_stay_invoice_id))]) - invoice.state='draft' + end_invoice=self.env['account.move'].sudo().search([('id','=',int(self.end_of_stay_invoice_id))]) + if end_invoice: + if end_invoice.payment_state!='paid': + invoice_id=self.end_of_stay_invoice_id + self.end_of_stay_invoice_id=False + self.env['account.move'].sudo().search([('id','=',int(invoice_id))]).unlink() @@ -256,7 +266,17 @@ class EventRegistration(models.Model): 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 + if reg.partner_id.email==reg.email: + status=reg.partner_id.member_status + #le participant n'est pas la personne qui s'est connecté + else: + participant=self.env['res.partner'].sudo().search([('email','=',reg.email)],limit=1) + if participant: + status=participant.member_status + else: + status='not member' + + product_price=event.booking_price if status=='not member':product_price=event.booking_price if status=='member':product_price=event.booking_member_price @@ -280,9 +300,13 @@ class EventRegistration(models.Model): #calcul du montant total à régler if end_of_stay_invoice:product_price=0 - #création du devis sans accompte + #création du devis sans acompte if (not reg.down_payment and reg.invoice_state!='paid') or (end_of_stay_invoice): + if not selected_registrant_options and end_of_stay_invoice : + return False + + #création de la facture vals={} @@ -308,7 +332,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'].sudo().create(vals) invoice.state='posted' invoice.name='REC'+str(invoice.id) @@ -343,8 +367,10 @@ class EventRegistration(models.Model): vals_d['price_unit']=product_price vals_d['exclude_from_invoice_tab']=True - + + #statut payment=paid invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals_d) + #statut payment=not_paid l=self.env['account.move.line'].sudo().search([('move_id','=',invoice.id),('balance','<',0)]) l.partner_id=int(reg.partner_id)