|
@ -93,6 +93,8 @@ class EventRegistration(models.Model): |
|
|
balance_invoice_id=fields.Many2one('account.move' ,ondelete="cascade") |
|
|
balance_invoice_id=fields.Many2one('account.move' ,ondelete="cascade") |
|
|
#balance_invoice_state=fields.Selection(related='balance_order_id.state') |
|
|
#balance_invoice_state=fields.Selection(related='balance_order_id.state') |
|
|
|
|
|
|
|
|
|
|
|
end_of_stay_invoice_id=fields.Many2one('account.move' ,string='end of stay invoice',ondelete="cascade") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
payment_status=fields.Char(string='payment status',compute='_compute_payment_status') |
|
|
payment_status=fields.Char(string='payment status',compute='_compute_payment_status') |
|
|
payment_adjustement=fields.Monetary('payment adjustement',currency_field='currency_id') |
|
|
payment_adjustement=fields.Monetary('payment adjustement',currency_field='currency_id') |
|
@ -182,12 +184,10 @@ class EventRegistration(models.Model): |
|
|
donation_draft.state='done' |
|
|
donation_draft.state='done' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def action_event_registration_generate_invoice(self,id_registration=None,backoffice=True): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#suppression des factures existantes |
|
|
|
|
|
if self.invoice_id: |
|
|
|
|
|
|
|
|
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=self.env['account.move'].sudo().search([('id','=',int(self.invoice_id))]) |
|
|
invoice.state='draft' |
|
|
invoice.state='draft' |
|
|
|
|
|
|
|
@ -195,24 +195,46 @@ class EventRegistration(models.Model): |
|
|
#invoice2.unlink() |
|
|
#invoice2.unlink() |
|
|
#raise Warning(invoice2) |
|
|
#raise Warning(invoice2) |
|
|
|
|
|
|
|
|
if self.down_payment_invoice_id: |
|
|
|
|
|
|
|
|
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=self.env['account.move'].sudo().search([('id','=',int(self.down_payment_invoice_id))]) |
|
|
invoice.state='draft' |
|
|
invoice.state='draft' |
|
|
# self.env['account.move'].search([('id','=',int(self.down_payment_invoice_id))]).unlink() |
|
|
# self.env['account.move'].search([('id','=',int(self.down_payment_invoice_id))]).unlink() |
|
|
# self.down_payment_invoice_id=False |
|
|
# self.down_payment_invoice_id=False |
|
|
|
|
|
|
|
|
if self.balance_invoice_id: |
|
|
|
|
|
|
|
|
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=self.env['account.move'].sudo().search([('id','=',int(self.balance_invoice_id))]) |
|
|
invoice.state='draft' |
|
|
invoice.state='draft' |
|
|
# self.env['account.move'].search([('id','=',int(self.balance_invoice_id))]).unlink() |
|
|
# self.env['account.move'].search([('id','=',int(self.balance_invoice_id))]).unlink() |
|
|
# self.balance_invoice_id=False |
|
|
# self.balance_invoice_id=False |
|
|
|
|
|
|
|
|
#suppression des dons existants |
|
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def remove_donation(self): |
|
|
|
|
|
#suppression des dons existants lié à l'inscription et aux options |
|
|
donation=self.env['donation.donation'].sudo().search([('id','in',self.donation_ids.ids)]) |
|
|
donation=self.env['donation.donation'].sudo().search([('id','in',self.donation_ids.ids)]) |
|
|
for d in donation: |
|
|
for d in donation: |
|
|
d.state='draft' |
|
|
d.state='draft' |
|
|
self.env['donation.donation'].sudo().search([('id','in',self.donation_ids.ids)]).unlink() |
|
|
self.env['donation.donation'].sudo().search([('id','in',self.donation_ids.ids)]).unlink() |
|
|
self.donation_ids=False |
|
|
self.donation_ids=False |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def action_event_registration_generate_end_of_stay_invoice(self): |
|
|
|
|
|
return self.action_event_registration_generate_invoice(None,True,True) |
|
|
|
|
|
|
|
|
|
|
|
def action_event_registration_generate_invoice(self,id_registration=None,backoffice=True,end_of_stay_invoice=False): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not end_of_stay_invoice: |
|
|
|
|
|
#suppression des factures existantes |
|
|
|
|
|
#si les factures sont payés on les supprime pas |
|
|
|
|
|
self.remove_invoice() |
|
|
|
|
|
#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' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if id_registration:reg=self.env['event.registration'].search([('id','=',int(id_registration))]) |
|
|
if id_registration:reg=self.env['event.registration'].search([('id','=',int(id_registration))]) |
|
|
else : reg=self |
|
|
else : reg=self |
|
@ -248,11 +270,11 @@ class EventRegistration(models.Model): |
|
|
if self.payment_adjustement!=0: |
|
|
if self.payment_adjustement!=0: |
|
|
product_price=product_price+self.payment_adjustement |
|
|
product_price=product_price+self.payment_adjustement |
|
|
#calcul du montant total à régler |
|
|
#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 accompte |
|
|
|
|
|
|
|
|
if not reg.down_payment: |
|
|
|
|
|
|
|
|
if (not reg.down_payment and reg.invoice_state!='paid') or (end_of_stay_invoice): |
|
|
#création de la facture |
|
|
#création de la facture |
|
|
vals={} |
|
|
vals={} |
|
|
|
|
|
|
|
@ -320,7 +342,7 @@ class EventRegistration(models.Model): |
|
|
|
|
|
|
|
|
#prix à appliquer aux options en fonction du statut ou de la présence de l'option d'adhesion |
|
|
#prix à appliquer aux options en fonction du statut ou de la présence de l'option d'adhesion |
|
|
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) |
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
price_unit=0 |
|
|
if event_option: |
|
|
if event_option: |
|
|
if status=="super member":price_unit=event_option.booking_option_super_member_price |
|
|
if status=="super member":price_unit=event_option.booking_option_super_member_price |
|
|
if status=="member":price_unit=event_option.booking_option_member_price |
|
|
if status=="member":price_unit=event_option.booking_option_member_price |
|
@ -329,23 +351,29 @@ class EventRegistration(models.Model): |
|
|
if backoffice: |
|
|
if backoffice: |
|
|
if option.booking_option_id.booking_option_product_backoffice: |
|
|
if option.booking_option_id.booking_option_product_backoffice: |
|
|
price_unit=option.booking_option_price |
|
|
price_unit=option.booking_option_price |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vals={} |
|
|
vals={} |
|
|
vals['move_id']=invoice.id |
|
|
vals['move_id']=invoice.id |
|
|
#ajout du produit |
|
|
#ajout du produit |
|
|
vals['product_id']=int(option.booking_option_id.id) |
|
|
vals['product_id']=int(option.booking_option_id.id) |
|
|
vals['quantity']=1 |
|
|
vals['quantity']=1 |
|
|
vals['price_unit']=price_unit |
|
|
vals['price_unit']=price_unit |
|
|
vals['name']=prd.name |
|
|
|
|
|
|
|
|
vals['name']=prd.name |
|
|
vals['account_id']=int(account_credit.id) |
|
|
vals['account_id']=int(account_credit.id) |
|
|
|
|
|
|
|
|
invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) |
|
|
invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#debit_line |
|
|
#debit_line |
|
|
vals_d={} |
|
|
vals_d={} |
|
|
vals_d['move_id']=invoice.id |
|
|
vals_d['move_id']=invoice.id |
|
|
vals_d['debit']=price_unit |
|
|
|
|
|
vals_d['credit']=0 |
|
|
|
|
|
|
|
|
if price_unit>=0: |
|
|
|
|
|
vals_d['debit']=price_unit |
|
|
|
|
|
vals_d['credit']=0 |
|
|
|
|
|
if price_unit<0: |
|
|
|
|
|
vals_d['debit']=0 |
|
|
|
|
|
vals_d['credit']=-price_unit |
|
|
|
|
|
|
|
|
vals_d['date']=datetime.now() |
|
|
vals_d['date']=datetime.now() |
|
|
vals_d['partner_id']=int(reg.partner_id) |
|
|
vals_d['partner_id']=int(reg.partner_id) |
|
|
vals_d['product_id']=int(option.booking_option_id.id) |
|
|
vals_d['product_id']=int(option.booking_option_id.id) |
|
@ -364,176 +392,184 @@ class EventRegistration(models.Model): |
|
|
if prd.donation: self.sudo().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 |
|
|
|
|
|
|
|
|
if not end_of_stay_invoice: |
|
|
|
|
|
reg.invoice_id=invoice.id |
|
|
|
|
|
else: |
|
|
|
|
|
reg.end_of_stay_invoice_id=invoice.id |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return invoice |
|
|
return invoice |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#2 factures si paiement avec acompte |
|
|
#2 factures si paiement avec acompte |
|
|
else: |
|
|
else: |
|
|
#création de la 1ère facture d'acompte |
|
|
|
|
|
vals={} |
|
|
|
|
|
|
|
|
|
|
|
vals['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals['invoice_date']=datetime.now() |
|
|
|
|
|
|
|
|
if reg.down_payment_invoice_state!='paid' and reg.down_payment and not end_of_stay_invoice: |
|
|
|
|
|
#création de la 1ère facture d'acompte |
|
|
|
|
|
vals={} |
|
|
|
|
|
|
|
|
|
|
|
vals['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals['invoice_date']=datetime.now() |
|
|
|
|
|
|
|
|
|
|
|
#mode de paiement CB par defaut |
|
|
|
|
|
electronic_method=self.env['account.payment.method'].sudo().search([('code','=','electronic')],limit=1) |
|
|
|
|
|
if electronic_method: |
|
|
|
|
|
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: |
|
|
|
|
|
raise Warning('please configure credit card mode') |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
invoice.payment_reference=invoice.name |
|
|
|
|
|
|
|
|
|
|
|
vals={} |
|
|
|
|
|
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) |
|
|
|
|
|
vals['quantity']=1 |
|
|
|
|
|
vals['price_unit']=event.booking_down_payment |
|
|
|
|
|
vals['name']='Acompte '+event.booking_product_id.name |
|
|
|
|
|
|
|
|
|
|
|
vals['account_id']=int(account_credit.id) |
|
|
|
|
|
|
|
|
#mode de paiement CB par defaut |
|
|
|
|
|
electronic_method=self.env['account.payment.method'].sudo().search([('code','=','electronic')],limit=1) |
|
|
|
|
|
if electronic_method: |
|
|
|
|
|
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: |
|
|
|
|
|
raise Warning('please configure credit card mode') |
|
|
|
|
|
|
|
|
invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
invoice.payment_reference=invoice.name |
|
|
|
|
|
|
|
|
|
|
|
vals={} |
|
|
|
|
|
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) |
|
|
|
|
|
vals['quantity']=1 |
|
|
|
|
|
vals['price_unit']=event.booking_down_payment |
|
|
|
|
|
vals['name']='Acompte '+event.booking_product_id.name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# #debit_line |
|
|
|
|
|
vals_d={} |
|
|
|
|
|
vals_d['move_id']=invoice.id |
|
|
|
|
|
vals_d['debit']=event.booking_down_payment |
|
|
|
|
|
vals_d['credit']=0 |
|
|
|
|
|
vals_d['date']=datetime.now() |
|
|
|
|
|
vals_d['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals_d['product_id']=int(event.booking_product_id) |
|
|
|
|
|
vals_d['name']='Acompte '+event.booking_product_id.name |
|
|
|
|
|
vals_d['account_id']=int(account_debit.id) |
|
|
|
|
|
vals_d['quantity']=1 |
|
|
|
|
|
vals_d['price_unit']=event.booking_down_payment |
|
|
|
|
|
vals_d['exclude_from_invoice_tab']=True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
vals['account_id']=int(account_credit.id) |
|
|
|
|
|
|
|
|
if reg.balance_invoice_state!='paid' and reg.down_payment and not end_of_stay_invoice: |
|
|
|
|
|
#création 2ème facture de solde + paiement des options |
|
|
|
|
|
vals={} |
|
|
|
|
|
|
|
|
|
|
|
vals['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals['invoice_date']=datetime.now() |
|
|
|
|
|
|
|
|
invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# #debit_line |
|
|
|
|
|
vals_d={} |
|
|
|
|
|
vals_d['move_id']=invoice.id |
|
|
|
|
|
vals_d['debit']=event.booking_down_payment |
|
|
|
|
|
vals_d['credit']=0 |
|
|
|
|
|
vals_d['date']=datetime.now() |
|
|
|
|
|
vals_d['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals_d['product_id']=int(event.booking_product_id) |
|
|
|
|
|
vals_d['name']='Acompte '+event.booking_product_id.name |
|
|
|
|
|
vals_d['account_id']=int(account_debit.id) |
|
|
|
|
|
vals_d['quantity']=1 |
|
|
|
|
|
vals_d['price_unit']=event.booking_down_payment |
|
|
|
|
|
vals_d['exclude_from_invoice_tab']=True |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
invoice.payment_reference=invoice.name |
|
|
|
|
|
|
|
|
|
|
|
vals={} |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
#création 2ème facture de solde + paiement des options |
|
|
|
|
|
vals={} |
|
|
|
|
|
|
|
|
|
|
|
vals['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals['invoice_date']=datetime.now() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
invoice.payment_reference=invoice.name |
|
|
|
|
|
|
|
|
|
|
|
vals={} |
|
|
|
|
|
|
|
|
|
|
|
vals['move_id']=invoice.id |
|
|
|
|
|
vals['product_id']=int(event.booking_product_id) |
|
|
|
|
|
vals['quantity']=1 |
|
|
|
|
|
vals['price_unit']=product_price-event.booking_down_payment |
|
|
|
|
|
vals['name']='solde '+event.booking_product_id.name |
|
|
|
|
|
|
|
|
|
|
|
vals['account_id']=int(account_credit.id) |
|
|
|
|
|
|
|
|
|
|
|
invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) |
|
|
|
|
|
|
|
|
vals['move_id']=invoice.id |
|
|
|
|
|
vals['product_id']=int(event.booking_product_id) |
|
|
|
|
|
vals['quantity']=1 |
|
|
|
|
|
vals['price_unit']=product_price-event.booking_down_payment |
|
|
|
|
|
vals['name']='solde '+event.booking_product_id.name |
|
|
|
|
|
|
|
|
|
|
|
vals['account_id']=int(account_credit.id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# #debit_line |
|
|
|
|
|
vals_d={} |
|
|
|
|
|
vals_d['move_id']=invoice.id |
|
|
|
|
|
vals_d['debit']=product_price-event.booking_down_payment |
|
|
|
|
|
vals_d['credit']=0 |
|
|
|
|
|
vals_d['date']=datetime.now() |
|
|
|
|
|
vals_d['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals_d['product_id']=int(event.booking_product_id) |
|
|
|
|
|
vals_d['name']='solde '+event.booking_product_id.name |
|
|
|
|
|
vals_d['account_id']=int(account_debit.id) |
|
|
|
|
|
vals_d['quantity']=1 |
|
|
|
|
|
vals_d['price_unit']=product_price-event.booking_down_payment |
|
|
|
|
|
vals_d['exclude_from_invoice_tab']=True |
|
|
|
|
|
|
|
|
invoice_line=self.env['account.move.line'].with_context(check_move_validity=False).sudo().create(vals) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# #debit_line |
|
|
|
|
|
vals_d={} |
|
|
|
|
|
vals_d['move_id']=invoice.id |
|
|
|
|
|
vals_d['debit']=product_price-event.booking_down_payment |
|
|
|
|
|
vals_d['credit']=0 |
|
|
|
|
|
vals_d['date']=datetime.now() |
|
|
|
|
|
vals_d['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals_d['product_id']=int(event.booking_product_id) |
|
|
|
|
|
vals_d['name']='solde '+event.booking_product_id.name |
|
|
|
|
|
vals_d['account_id']=int(account_debit.id) |
|
|
|
|
|
vals_d['quantity']=1 |
|
|
|
|
|
vals_d['price_unit']=product_price-event.booking_down_payment |
|
|
|
|
|
vals_d['exclude_from_invoice_tab']=True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ajout des options |
|
|
|
|
|
if selected_registrant_options: |
|
|
|
|
|
for option in selected_registrant_options: |
|
|
|
|
|
|
|
|
|
|
|
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))]) |
|
|
|
|
|
price_unit=0 |
|
|
|
|
|
if event_option: |
|
|
|
|
|
if status=="super member":price_unit=event_option.booking_option_super_member_price |
|
|
|
|
|
if status=="member":price_unit=event_option.booking_option_member_price |
|
|
|
|
|
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 |
|
|
|
|
|
if backoffice: |
|
|
|
|
|
if option.booking_option_id.booking_option_product_backoffice: |
|
|
|
|
|
price_unit=option.booking_option_price |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ajout des options |
|
|
|
|
|
if selected_registrant_options: |
|
|
|
|
|
for option in selected_registrant_options: |
|
|
|
|
|
|
|
|
|
|
|
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))]) |
|
|
|
|
|
|
|
|
|
|
|
if event_option: |
|
|
|
|
|
if status=="super member":price_unit=event_option.booking_option_super_member_price |
|
|
|
|
|
if status=="member":price_unit=event_option.booking_option_member_price |
|
|
|
|
|
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['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).sudo().create(vals) |
|
|
|
|
|
|
|
|
#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 |
|
|
|
|
|
vals['product_id']=int(event.booking_product_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).sudo().create(vals) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#debit_line |
|
|
|
|
|
vals_d={} |
|
|
|
|
|
vals_d['move_id']=invoice.id |
|
|
|
|
|
vals_d['debit']=price_unit |
|
|
|
|
|
vals_d['credit']=0 |
|
|
|
|
|
vals_d['date']=datetime.now() |
|
|
|
|
|
vals_d['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals_d['product_id']=int(option.booking_option_id.id) |
|
|
|
|
|
vals_d['name']=prd.name |
|
|
|
|
|
vals_d['account_id']=int(account_debit.id) |
|
|
|
|
|
vals_d['quantity']=1 |
|
|
|
|
|
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).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.sudo().create_donation(reg.id,reg.partner_id,vals['product_id'],vals['price_unit']) |
|
|
|
|
|
|
|
|
|
|
|
reg.balance_invoice_id=invoice.id |
|
|
|
|
|
|
|
|
#debit_line |
|
|
|
|
|
vals_d={} |
|
|
|
|
|
vals_d['move_id']=invoice.id |
|
|
|
|
|
if price_unit>=0: |
|
|
|
|
|
vals_d['debit']=price_unit |
|
|
|
|
|
vals_d['credit']=0 |
|
|
|
|
|
if price_unit<0: |
|
|
|
|
|
vals_d['debit']=0 |
|
|
|
|
|
vals_d['credit']=-price_unit |
|
|
|
|
|
vals_d['date']=datetime.now() |
|
|
|
|
|
vals_d['partner_id']=int(reg.partner_id) |
|
|
|
|
|
vals_d['product_id']=int(option.booking_option_id.id) |
|
|
|
|
|
vals_d['name']=prd.name |
|
|
|
|
|
vals_d['account_id']=int(account_debit.id) |
|
|
|
|
|
vals_d['quantity']=1 |
|
|
|
|
|
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).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.sudo().create_donation(reg.id,reg.partner_id,vals['product_id'],vals['price_unit']) |
|
|
|
|
|
|
|
|
|
|
|
reg.balance_invoice_id=invoice.id |
|
|
return invoice.id |
|
|
return invoice.id |
|
|
|
|
|
|
|
|
def info_objet(self,model_id,objet_id): |
|
|
def info_objet(self,model_id,objet_id): |
|
|