@ -39,7 +39,7 @@ class CdrAccountingFileWizard(models.TransientModel):
return datetime ( date_today . year , date_today . month , 1 )
return datetime ( date_today . year , date_today . month , 1 )
def action_create_accounting_file ( self ) :
def action_create_cdr_ accounting_file ( self ) :
global total_debit
global total_debit
global total_credit
global total_credit
total_debit = 0
total_debit = 0
@ -84,7 +84,7 @@ class CdrAccountingFileWizard(models.TransientModel):
vals [ ' exported_date ' ] = fields . Date . context_today ( self )
vals [ ' exported_date ' ] = fields . Date . context_today ( self )
vals [ ' start_date ' ] = self . start_date
vals [ ' start_date ' ] = self . start_date
vals [ ' end_date ' ] = self . end_date
vals [ ' end_date ' ] = self . end_date
res = self . env [ ' accounting.file ' ] . create ( vals )
res = self . env [ ' cdr. accounting.file' ] . create ( vals )
f . close
f . close
os . unlink ( filename )
os . unlink ( filename )
@ -93,7 +93,7 @@ class CdrAccountingFileWizard(models.TransientModel):
' name ' : ' Account deposit form ' ,
' name ' : ' Account deposit form ' ,
' view_type ' : ' form ' ,
' view_type ' : ' form ' ,
' view_mode ' : ' form ' ,
' view_mode ' : ' form ' ,
' res_model ' : ' accounting.file ' ,
' res_model ' : ' cdr. accounting.file' ,
' res_id ' : int ( res . id ) ,
' res_id ' : int ( res . id ) ,
' type ' : ' ir.actions.act_window ' ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' current '
' target ' : ' current '
@ -111,6 +111,7 @@ class CdrAccountingFileWizard(models.TransientModel):
global total_credit
global total_credit
global no_mvt
global no_mvt
#écritures pour les dons validés (donc payés), non déjà exportés
#écritures pour les dons validés (donc payés), non déjà exportés
donation = self . env [ ' donation.donation ' ] . search ( [ ( ' date_compta ' , ' = ' , False ) , ( ' state ' , ' = ' , ' done ' ) ] )
donation = self . env [ ' donation.donation ' ] . search ( [ ( ' date_compta ' , ' = ' , False ) , ( ' state ' , ' = ' , ' done ' ) ] )
#raise UserError(donation)
#raise UserError(donation)
for d in donation :
for d in donation :
@ -129,10 +130,10 @@ class CdrAccountingFileWizard(models.TransientModel):
if not self . debug_mode : d . date_compta = date_compta
if not self . debug_mode : d . date_compta = date_compta
#if not d.payment_mode_id: raise UserError(_("no payment mode found for donation %r ",donation.number))
#if not d.payment_mode_id: raise UserError(_("no payment mode found for donation %r ",donation.number))
#if not d.payment_mode_id.fixed_journal_id: raise UserError(_("no account found for payment mode %r",d.payment_mode_id.name))
#if not d.payment_mode_id.fixed_journal_id: raise UserError(_("no account found for payment mode %r",d.payment_mode_id.name))
account_debit_number = self . _file_format ( str ( d . payment_mode_id . fixed_journal_id . default_account_id . code ) , 6 )
if d . transaction_id . acquirer_id . name == ' Paypal ' :
#account_debit_number=self._file_format(str(d.payment_mode_id.fixed_journal_id.default_account_id.code),6 )
# if d.transaction_id.acquirer_id.name=='Paypal' :
account_debit_number = self . _file_format ( str ( self . env [ ' account.payment.mode ' ] . search ( [ ( ' name ' , ' = ' , ' Paypal ' ) ] ) . fixed_journal_id . default_account_id . code ) , 6 )
# account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','Paypal')]).fixed_journal_id.default_account_id.code),6 )
firstname = d . partner_id . firstname
firstname = d . partner_id . firstname
name = d . partner_id . name
name = d . partner_id . name
@ -154,9 +155,11 @@ class CdrAccountingFileWizard(models.TransientModel):
affectation = line . product_id . name
affectation = line . product_id . name
amount = line . amount
amount = line . amount
#if not line.product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",line.product_id.name))
#if not line.product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",line.product_id.name))
account_credit_number = self . _file_format ( line . product_id . property_account_income_id . code , 6 )
account_debit_number = self . _file_format ( line . product_id . property_account_income_id . code , 6 )
account_credit_number = self . _file_format ( line . product_id . cdr_property_account_income_id . code , 6 )
break
break
if account_debit_number != ' 170000 ' : continue
#credit line
#credit line
lib2 = self . _file_format ( affectation , 13 )
lib2 = self . _file_format ( affectation , 13 )
lib = lib1 + ' ' + lib2
lib = lib1 + ' ' + lib2
@ -281,14 +284,19 @@ class CdrAccountingFileWizard(models.TransientModel):
registration = self . env [ ' event.registration ' ] . search ( [ ] )
registration = self . env [ ' event.registration ' ] . search ( [ ] )
membership_amount = 0
membership_amount = 0
donation_amount = 0
donation_amount = 0
membership_credit_line = False
#membership_credit_line= False
donation_credit_line = False
donation_credit_line = False
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
account_credit_number = self . _file_format ( ' 170000 ' , 6 )
for reg in registration :
for reg in registration :
if reg . event_id . booking_event :
if reg . event_id . booking_event :
if reg . event_id . individual_booking_event :
account_credit_number = self . _file_format ( ' 754799 ' , 6 )
else :
account_credit_number = self . _file_format ( ' 754700 ' , 6 )
#si pas de facture d'acompte et facture payée:
#si pas de facture d'acompte et facture payée:
if reg . invoice_id . amount_total > 0 and reg . invoice_id . payment_state == ' paid ' and reg . date_compta == False :
if reg . invoice_id . amount_total > 0 and reg . invoice_id . payment_state == ' paid ' and reg . date_compta == False :
@ -321,13 +329,17 @@ class CdrAccountingFileWizard(models.TransientModel):
global total_credit
global total_credit
global no_mvt
global no_mvt
membership_amount = 0
#membership_amount= 0
donation_amount = 0
donation_amount = 0
membership_credit_line = False
#membership_credit_line= False
donation_credit_line = False
donation_credit_line = False
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
account_credit_number = self . _file_format ( ' 170000 ' , 6 )
if reg . event_id . individual_booking_event :
account_credit_number = self . _file_format ( ' 754799 ' , 6 )
else :
account_credit_number = self . _file_format ( ' 754700 ' , 6 )
firstname = reg . partner_id . firstname
firstname = reg . partner_id . firstname
name = reg . partner_id . name
name = reg . partner_id . name
@ -342,20 +354,23 @@ class CdrAccountingFileWizard(models.TransientModel):
down_payment = False
down_payment = False
balance_payment = True
balance_payment = True
account_debit_number = ' '
for p in reg . balance_invoice_id . payment_ids :
account_debit_number = self . _file_format ( str ( self . env [ ' account.journal ' ] . search ( [ ( ' id ' , ' = ' , int ( p . journal_id ) ) ] ) . default_account_id . code ) , 6 )
break
# account_debit_number=''
# for p in reg.balance_invoice_id.payment_ids:
# account_debit_number=self._file_format(str(self.env['account.journal'].search([('id','=',int(p.journal_id))]).default_account_id.code),6)
# break
account_debit_number = self . _file_format ( ' 170000 ' , 6 )
date_line = self . _payment_date ( reg . balance_invoice_id )
date_line = self . _payment_date ( reg . balance_invoice_id )
#recherche de l'adhésion
#recherche de l'adhésion
membership_credit_line = False
membership = self . env [ ' kalachakra.membership ' ] . search ( [ ( ' date_compta ' , ' = ' , False ) , ( ' balance_invoice_id ' , ' = ' , int ( reg . balance_invoice_id ) ) ] )
if membership :
membership_credit_line = True
membership_amount = membership . amount
# membership_credit_line= False
# membership=self.env['kalachakra.membership'].search([('date_compta','=',False),('balance_invoice_id','=',int(reg.balance_invoice_id))] )
# if membership :
# membership_credit_line= True
# membership_amount=membership. amount
#recherche de dons
#recherche de dons
donation_credit_line = False
donation_credit_line = False
@ -381,7 +396,7 @@ class CdrAccountingFileWizard(models.TransientModel):
total_debit + = amount
total_debit + = amount
if not amount : amount = 0
if not amount : amount = 0
amount = reg . balance_invoice_id . amount_total - membership_amount - donation_amount
amount = reg . balance_invoice_id . amount_total - donation_amount
debit = ' '
debit = ' '
credit = str ( amount )
credit = str ( amount )
account_number = account_credit_number
account_number = account_credit_number
@ -390,21 +405,21 @@ class CdrAccountingFileWizard(models.TransientModel):
no_mvt = no_mvt + 1
no_mvt = no_mvt + 1
total_credit + = amount
total_credit + = amount
if membership_credit_line :
debit = ' '
credit = str ( membership_amount )
account_number = self . _file_format ( ' 756100 ' , 6 )
fic_line = self . _accounting_line ( no_mvt , date_line , account_number , lib , debit , credit , lib_piece )
f . write ( fic_line )
no_mvt = no_mvt + 1
total_credit + = membership_amount
# if membership_credit_line :
# debit=' '
# credit=str(membership_amount )
# account_number=self._file_format('756100',6 )
# fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece )
# f.write(fic_line )
# no_mvt=no_mvt+ 1
# total_credit+= membership_amount
if donation_credit_line :
if donation_credit_line :
for d in donations :
for d in donations :
deb it = ' '
cre dit= ' '
amount = d . amount_total
amount = d . amount_total
cred it= str ( amount )
account_number = account_credit_number
deb it= str ( amount )
account_number = ' 170000 '
fic_line = self . _accounting_line ( no_mvt , date_line , account_number , lib , debit , credit , lib_piece )
fic_line = self . _accounting_line ( no_mvt , date_line , account_number , lib , debit , credit , lib_piece )
f . write ( fic_line )
f . write ( fic_line )
no_mvt = no_mvt + 1
no_mvt = no_mvt + 1
@ -425,7 +440,11 @@ class CdrAccountingFileWizard(models.TransientModel):
donation_credit_line = False
donation_credit_line = False
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
account_credit_number = self . _file_format ( ' 170000 ' , 6 )
if reg . event_id . individual_booking_event :
account_credit_number = self . _file_format ( ' 754799 ' , 6 )
else :
account_credit_number = self . _file_format ( ' 754700 ' , 6 )
firstname = reg . partner_id . firstname
firstname = reg . partner_id . firstname
name = reg . partner_id . name
name = reg . partner_id . name
@ -442,7 +461,10 @@ class CdrAccountingFileWizard(models.TransientModel):
donation_credit_line = False
donation_credit_line = False
membership_credit_line = False
membership_credit_line = False
account_debit_number = self . _file_format ( str ( reg . down_payment_invoice_id . payment_mode_id . fixed_journal_id . default_account_id . code ) , 6 )
#account_debit_number=self._file_format(str(reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6)
account_debit_number = self . _file_format ( ' 170000 ' , 6 )
trans = self . env [ ' payment.transaction ' ] . search ( [ ( ' invoice_ids ' , ' in ' , reg . down_payment_invoice_id . id ) , ( ' state ' , ' = ' , ' done ' ) ] , limit = 1 )
trans = self . env [ ' payment.transaction ' ] . search ( [ ( ' invoice_ids ' , ' in ' , reg . down_payment_invoice_id . id ) , ( ' state ' , ' = ' , ' done ' ) ] , limit = 1 )
if trans and trans . acquirer_id . name == ' Paypal ' : account_debit_number = self . _file_format ( str ( self . env [ ' account.payment.mode ' ] . search ( [ ( ' name ' , ' = ' , ' Paypal ' ) ] ) . fixed_journal_id . default_account_id . code ) , 6 )
if trans and trans . acquirer_id . name == ' Paypal ' : account_debit_number = self . _file_format ( str ( self . env [ ' account.payment.mode ' ] . search ( [ ( ' name ' , ' = ' , ' Paypal ' ) ] ) . fixed_journal_id . default_account_id . code ) , 6 )
if trans and trans . acquirer_id . name == ' Paiement par carte bancaire ' : account_debit_number = self . _file_format ( str ( self . env [ ' account.payment.mode ' ] . search ( [ ( ' name ' , ' = ' , ' CB ' ) ] ) . fixed_journal_id . default_account_id . code ) , 6 )
if trans and trans . acquirer_id . name == ' Paiement par carte bancaire ' : account_debit_number = self . _file_format ( str ( self . env [ ' account.payment.mode ' ] . search ( [ ( ' name ' , ' = ' , ' CB ' ) ] ) . fixed_journal_id . default_account_id . code ) , 6 )
@ -499,7 +521,11 @@ class CdrAccountingFileWizard(models.TransientModel):
donation_credit_line = False
donation_credit_line = False
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
account_credit_number = self . _file_format ( ' 170000 ' , 6 )
if reg . event_id . individual_booking_event :
account_credit_number = self . _file_format ( ' 754799 ' , 6 )
else :
account_credit_number = self . _file_format ( ' 754700 ' , 6 )
firstname = reg . partner_id . firstname
firstname = reg . partner_id . firstname
name = reg . partner_id . name
name = reg . partner_id . name
@ -515,22 +541,24 @@ class CdrAccountingFileWizard(models.TransientModel):
down_payment = False
down_payment = False
balance_payment = False
balance_payment = False
#if not reg.invoice_id.payment_mode_id.fixed_journal_id: raise UserError(_("no account found payment mode %r",reg.invoice_id.payment_mode_id.name))
#if not reg.invoice_id.payment_mode_id.fixed_journal_id: raise UserError(_("no account found payment mode %r",reg.invoice_id.payment_mode_id.name))
account_debit_number = self . _file_format ( str ( reg . invoice_id . payment_mode_id . fixed_journal_id . default_account_id . code ) , 6 )
trans = self . env [ ' payment.transaction ' ] . search ( [ ( ' invoice_ids ' , ' in ' , reg . invoice_id . id ) , ( ' state ' , ' = ' , ' done ' ) ] , limit = 1 )
if trans and trans . acquirer_id . name == ' Paypal ' :
# account_debit_number=self._file_format(str(reg.invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6 )
# trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.invoice_id.id),('state','=','done')],limit=1 )
# if trans and trans.acquirer_id.name=='Paypal' :
account_debit_number = self . _file_format ( str ( self . env [ ' account.payment.mode ' ] . search ( [ ( ' name ' , ' = ' , ' Paypal ' ) ] ) . fixed_journal_id . default_account_id . code ) , 6 )
# account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','Paypal')]).fixed_journal_id.default_account_id.code),6 )
if trans and trans . acquirer_id . name == ' Paiement par carte bancaire ' :
# if trans and trans.acquirer_id.name=='Paiement par carte bancaire' :
account_debit_number = self . _file_format ( str ( self . env [ ' account.payment.mode ' ] . search ( [ ( ' name ' , ' = ' , ' CB ' ) ] ) . fixed_journal_id . default_account_id . code ) , 6 )
# account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','CB')]).fixed_journal_id.default_account_id.code),6)
account_debit_number = self . _file_format ( ' 170000 ' , 6 )
#recherche de l'adhésion
#recherche de l'adhésion
membership_credit_line = False
membership = self . env [ ' kalachakra.membership ' ] . search ( [ ( ' invoice_id ' , ' = ' , int ( reg . invoice_id ) ) ] )
if membership :
membership_credit_line = True
membership_amount = membership . amount
# membership_credit_line= False
# membership=self.env['kalachakra.membership'].search([('invoice_id','=',int(reg.invoice_id))] )
# if membership :
# membership_credit_line= True
# membership_amount=membership. amount
#recherche de dons
#recherche de dons
donation_credit_line = False
donation_credit_line = False
@ -568,7 +596,7 @@ class CdrAccountingFileWizard(models.TransientModel):
#participation credit line
#participation credit line
if not amount : amount = 0
if not amount : amount = 0
amount = amount - membership_amount - donation_amount
amount = amount - donation_amount
debit = ' '
debit = ' '
credit = str ( amount )
credit = str ( amount )
account_number = account_credit_number
account_number = account_credit_number
@ -577,21 +605,21 @@ class CdrAccountingFileWizard(models.TransientModel):
no_mvt = no_mvt + 1
no_mvt = no_mvt + 1
total_credit + = amount
total_credit + = amount
if membership_credit_line :
debit = ' '
credit = str ( membership_amount )
account_number = self . _file_format ( ' 756100 ' , 6 )
fic_line = self . _accounting_line ( no_mvt , date_line , account_number , lib , debit , credit , lib_piece )
f . write ( fic_line )
no_mvt = no_mvt + 1
total_credit + = membership_amount
# if membership_credit_line :
# debit=' '
# credit=str(membership_amount )
# account_number=self._file_format('756100',6 )
# fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece )
# f.write(fic_line )
# no_mvt=no_mvt+ 1
# total_credit+= membership_amount
if donation_credit_line :
if donation_credit_line :
for d in donations :
for d in donations :
deb it = ' '
cre dit= ' '
amount = d . amount_total
amount = d . amount_total
cred it= str ( amount )
account_number = account_credit_number
deb it= str ( amount )
account_number = ' 170000 '
fic_line = self . _accounting_line ( no_mvt , date_line , account_number , lib , debit , credit , lib_piece )
fic_line = self . _accounting_line ( no_mvt , date_line , account_number , lib , debit , credit , lib_piece )
f . write ( fic_line )
f . write ( fic_line )
no_mvt = no_mvt + 1
no_mvt = no_mvt + 1
@ -626,7 +654,7 @@ class CdrAccountingFileWizard(models.TransientModel):
lib_piece = self . _file_format ( invoice . name , 20 )
lib_piece = self . _file_format ( invoice . name , 20 )
#écriture de débit
#écriture de débit
amount = invoice . amount_total
amount = invoice . amount_total
account_debit_number = ' 1700 00'
account_debit_number = ' 7547 00'
date_line = self . _date_format ( invoice . invoice_date )
date_line = self . _date_format ( invoice . invoice_date )
if amount == 0 : continue
if amount == 0 : continue
debit = str ( amount )
debit = str ( amount )
@ -681,7 +709,7 @@ class CdrAccountingFileWizard(models.TransientModel):
#écriture de débit
#écriture de débit
amount = invoice . amount_total
amount = invoice . amount_total
account_debit_number = ' 1700 00'
account_debit_number = ' 4119 00'
#date du paiement
#date du paiement
#_logger.error(self._payment_date_ok(invoice.out_invoice_id))
#_logger.error(self._payment_date_ok(invoice.out_invoice_id))