@ -90,6 +90,7 @@ class EventRegistration(models.Model):
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 ' )
def _compute_payment_status ( self ) :
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 ) :
def create_donation ( self , event_registration_id , partner_id , product_id , price_unit ) :
vals = { }
vals = { }
vals [ ' partner_id ' ] = int ( partner_id )
vals [ ' partner_id ' ] = int ( partner_id )
#raise Warning(vals['partner_id'])
vals [ ' donation_date ' ] = datetime . now ( )
vals [ ' donation_date ' ] = datetime . now ( )
vals [ ' tax_receipt_option ' ] = ' annual '
vals [ ' tax_receipt_option ' ] = ' annual '
@ -175,6 +175,7 @@ class EventRegistration(models.Model):
#create line donation
#create line donation
vals [ ' donation_id ' ] = donation_draft . id
vals [ ' donation_id ' ] = donation_draft . id
product = self . env [ ' product.product ' ] . search ( [ ( ' id ' , ' = ' , int ( product_id ) ) ] )
product = self . env [ ' product.product ' ] . search ( [ ( ' id ' , ' = ' , int ( product_id ) ) ] )
vals [ ' product_id ' ] = int ( product_id )
vals [ ' product_id ' ] = int ( product_id )
vals [ ' display_name ' ] = product . name
vals [ ' display_name ' ] = product . name
vals [ ' quantity ' ] = 1
vals [ ' quantity ' ] = 1
@ -185,190 +186,37 @@ class EventRegistration(models.Model):
donation_line = self . env [ ' donation.line ' ] . sudo ( ) . create ( vals )
donation_line = self . env [ ' donation.line ' ] . sudo ( ) . create ( vals )
donation_draft . state = ' done '
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 ) :
def action_event_registration_generate_invoice ( self , id_registration = None ) :
#suppression des factures existantes
#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.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 :
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.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
#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
self . donation_ids = False
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 ) ) ] )
@ -378,6 +226,7 @@ class EventRegistration(models.Model):
selected_registrant_options = self . env [ ' event.registration_option ' ] . search ( [
selected_registrant_options = self . env [ ' event.registration_option ' ] . search ( [
( ' event_registration_id ' , ' = ' , int ( reg . id ) ) ] )
( ' event_registration_id ' , ' = ' , int ( reg . id ) ) ] )
#controles avant traitement : un produit doit être associé à l'événement
#controles avant traitement : un produit doit être associé à l'événement
if not event . booking_product_id : raise Warning ( ' product missing for event booking ' )
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 ( )
vals [ ' invoice_date ' ] = datetime . now ( )
#mode de paiement CB par defaut
#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 ( ) . s earch ( [ ( ' code ' , ' = ' , ' electronic ' ) ] , limit = 1 )
if electronic_method :
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 ( ) . s earch ( [ ( ' payment_method_id ' , ' = ' , int ( electronic_method . id ) ) ] , limit = 1 )
if cb_mode :
if cb_mode :
vals [ ' payment_mode_id ' ] = cb_mode . id
vals [ ' payment_mode_id ' ] = cb_mode . id
else :
else :
@ -425,14 +274,14 @@ class EventRegistration(models.Model):
vals [ ' move_type ' ] = ' out_invoice '
vals [ ' move_type ' ] = ' out_invoice '
vals [ ' state ' ] = ' draft '
vals [ ' state ' ] = ' draft '
#vals['currency_id']=self.currency_id.id
#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 . state = ' posted '
invoice . name = ' REC ' + str ( invoice . id )
invoice . name = ' REC ' + str ( invoice . id )
invoice . payment_reference = invoice . name
invoice . payment_reference = invoice . name
vals = { }
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 ( ) . s earch ( [ ( ' code ' , ' = ' , ' 707100 ' ) ] )
account_debit = self . env [ ' account.account ' ] . sudo ( ) . s earch ( [ ( ' code ' , ' = ' , ' 411100 ' ) ] )
vals [ ' move_id ' ] = invoice . id
vals [ ' move_id ' ] = invoice . id
vals [ ' product_id ' ] = int ( event . booking_product_id )
vals [ ' product_id ' ] = int ( event . booking_product_id )
@ -442,7 +291,7 @@ class EventRegistration(models.Model):
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 ) . create ( vals )
invoice_line = self . env [ ' account.move.line ' ] . with_context ( check_move_validity = False ) . sudo ( ) . create ( vals )
# #debit_line
# #debit_line
@ -460,8 +309,8 @@ class EventRegistration(models.Model):
vals_d [ ' exclude_from_invoice_tab ' ] = True
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 ( ) . s earch ( [ ( ' move_id ' , ' = ' , invoice . id ) , ( ' balance ' , ' < ' , 0 ) ] )
l . partner_id = int ( reg . partner_id )
l . partner_id = int ( reg . partner_id )
@ -470,10 +319,10 @@ class EventRegistration(models.Model):
if selected_registrant_options :
if selected_registrant_options :
for option in 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 ( ) . s earch ( [ ( ' 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
#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 ( ) . s earch ( [ ' & ' , ( ' event_id ' , ' = ' , int ( reg . event_id ) ) , ( ' booking_option_id ' , ' = ' , int ( option . booking_option_id . id ) ) ] , limit = 1 )
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
@ -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 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 status == " not member " and not membership_option : price_unit = event_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 ( event . booking_product_ 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 ) . create ( vals )
invoice_line = self . env [ ' account.move.line ' ] . with_context ( check_move_validity = False ) . sudo ( ) . create ( vals )
#debit_line
#debit_line
@ -506,13 +356,13 @@ class EventRegistration(models.Model):
vals_d [ ' price_unit ' ] = price_unit
vals_d [ ' price_unit ' ] = price_unit
vals_d [ ' exclude_from_invoice_tab ' ] = True
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 ( ) . s earch ( [ ( ' move_id ' , ' = ' , invoice . id ) , ( ' balance ' , ' < ' , 0 ) ] )
l . partner_id = int ( reg . partner_id )
l . partner_id = int ( reg . partner_id )
#si l'option est un produit de don on créé un don pour la personne
#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
reg . invoice_id = invoice . id
@ -529,9 +379,9 @@ class EventRegistration(models.Model):
vals [ ' invoice_date ' ] = datetime . now ( )
vals [ ' invoice_date ' ] = datetime . now ( )
#mode de paiement CB par defaut
#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 ( ) . s earch ( [ ( ' code ' , ' = ' , ' electronic ' ) ] , limit = 1 )
if electronic_method :
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 ( ) . s earch ( [ ( ' payment_method_id ' , ' = ' , int ( electronic_method . id ) ) ] , limit = 1 )
if cb_mode :
if cb_mode :
vals [ ' payment_mode_id ' ] = cb_mode . id
vals [ ' payment_mode_id ' ] = cb_mode . id
else :
else :
@ -540,14 +390,14 @@ class EventRegistration(models.Model):
vals [ ' move_type ' ] = ' out_invoice '
vals [ ' move_type ' ] = ' out_invoice '
vals [ ' state ' ] = ' draft '
vals [ ' state ' ] = ' draft '
#vals['currency_id']=self.currency_id.id
#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 . state = ' posted '
invoice . name = ' REC ' + str ( invoice . id )
invoice . name = ' REC ' + str ( invoice . id )
invoice . payment_reference = invoice . name
invoice . payment_reference = invoice . name
vals = { }
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 ( ) . s earch ( [ ( ' code ' , ' = ' , ' 707100 ' ) ] )
account_debit = self . env [ ' account.account ' ] . sudo ( ) . s earch ( [ ( ' code ' , ' = ' , ' 411100 ' ) ] )
vals [ ' move_id ' ] = invoice . id
vals [ ' move_id ' ] = invoice . id
vals [ ' product_id ' ] = int ( event . booking_product_id )
vals [ ' product_id ' ] = int ( event . booking_product_id )
@ -557,7 +407,7 @@ class EventRegistration(models.Model):
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 ) . create ( vals )
invoice_line = self . env [ ' account.move.line ' ] . with_context ( check_move_validity = False ) . sudo ( ) . create ( vals )
# #debit_line
# #debit_line
@ -575,8 +425,8 @@ class EventRegistration(models.Model):
vals_d [ ' exclude_from_invoice_tab ' ] = True
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 ( ) . s earch ( [ ( ' move_id ' , ' = ' , invoice . id ) , ( ' balance ' , ' < ' , 0 ) ] )
l . partner_id = int ( reg . partner_id )
l . partner_id = int ( reg . partner_id )
reg . down_payment_invoice_id = invoice . id
reg . down_payment_invoice_id = invoice . id
@ -591,7 +441,7 @@ class EventRegistration(models.Model):
vals [ ' move_type ' ] = ' out_invoice '
vals [ ' move_type ' ] = ' out_invoice '
vals [ ' state ' ] = ' draft '
vals [ ' state ' ] = ' draft '
#vals['currency_id']=self.currency_id.id
#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 . state = ' posted '
invoice . name = ' REC ' + str ( invoice . id )
invoice . name = ' REC ' + str ( invoice . id )
@ -607,7 +457,7 @@ class EventRegistration(models.Model):
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 ) . create ( vals )
invoice_line = self . env [ ' account.move.line ' ] . with_context ( check_move_validity = False ) . sudo ( ) . create ( vals )
# #debit_line
# #debit_line
@ -625,8 +475,8 @@ class EventRegistration(models.Model):
vals_d [ ' exclude_from_invoice_tab ' ] = True
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 ( ) . s earch ( [ ( ' move_id ' , ' = ' , invoice . id ) , ( ' balance ' , ' < ' , 0 ) ] )
l . partner_id = int ( reg . partner_id )
l . partner_id = int ( reg . partner_id )
@ -634,8 +484,8 @@ class EventRegistration(models.Model):
if selected_registrant_options :
if selected_registrant_options :
for option in 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 ( ) . s earch ( [ ( ' 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
#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 ) ) ] )
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 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 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 = { }
vals [ ' move_id ' ] = invoice . id
vals [ ' move_id ' ] = invoice . id
#ajout du produit
#ajout du produit
@ -653,7 +509,7 @@ class EventRegistration(models.Model):
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 ) . create ( vals )
invoice_line = self . env [ ' account.move.line ' ] . with_context ( check_move_validity = False ) . sudo ( ) . create ( vals )
#debit_line
#debit_line
@ -670,13 +526,13 @@ class EventRegistration(models.Model):
vals_d [ ' price_unit ' ] = price_unit
vals_d [ ' price_unit ' ] = price_unit
vals_d [ ' exclude_from_invoice_tab ' ] = True
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 = self . env [ ' account.move.line ' ] . search ( [ ( ' move_id ' , ' = ' , invoice . id ) , ( ' balance ' , ' < ' , 0 ) ] )
l . partner_id = int ( reg . partner_id )
l . partner_id = int ( reg . partner_id )
#si l'option est un produit de don on créé un don pour la personne
#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
reg . balance_invoice_id = invoice . id
return invoice . id
return invoice . id