|
|
@ -5,6 +5,9 @@ import os,secrets |
|
|
|
import decimal |
|
|
|
import base64 |
|
|
|
|
|
|
|
code_journal='IN' |
|
|
|
date_compta=fields.datetime.now() |
|
|
|
|
|
|
|
class AccountingFileWizard(models.TransientModel): |
|
|
|
_name = 'accounting.file.wizard' |
|
|
|
_description = 'accounting file wizard' |
|
|
@ -29,7 +32,7 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
filename='/tmp/accounting_file_'+tmstp+'.txt' |
|
|
|
f = open(filename, "a") |
|
|
|
|
|
|
|
date_compta=fields.datetime.now() |
|
|
|
|
|
|
|
#N° mouvement 1-5 |
|
|
|
#Code du journal "IN" 6-7 |
|
|
|
#Date 8-17 (10 cars) ex:01/04/2022 |
|
|
@ -39,10 +42,77 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
#Crédit ex : 200,00 |
|
|
|
#N° de pièce: ref transaction , ex: txD-457 |
|
|
|
no_mvt=1 |
|
|
|
code_journal='IN' |
|
|
|
|
|
|
|
fic_line="N° mouvement;Code du journal;Date;N° de compte;Libellé;Débit;Crédit;N° de pièce"+"\n" |
|
|
|
f.write(fic_line) |
|
|
|
#écritures pour les dons validés (donc payés), non déjà exportés |
|
|
|
|
|
|
|
#self.donation_lines(f,no_mvt) |
|
|
|
#self.membership_lines(f,no_mvt) |
|
|
|
#self.event_lines(f,no_mvt) |
|
|
|
self.booking_event_lines(f,no_mvt) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f.close |
|
|
|
f = open(filename, "r") |
|
|
|
data = str.encode(f.read(), 'utf-8') |
|
|
|
#raise UserError('gg'+f.read()) |
|
|
|
vals={} |
|
|
|
vals['accounting_file']=base64.encodebytes(data) |
|
|
|
vals['document_fname']='export_comptable.txt' |
|
|
|
vals['exported_date']=fields.Date.context_today(self) |
|
|
|
res=self.env['accounting.file'].create(vals) |
|
|
|
f.close |
|
|
|
os.unlink(filename) |
|
|
|
|
|
|
|
#display account deposit |
|
|
|
return { |
|
|
|
'name': 'Account deposit form', |
|
|
|
'view_type': 'form', |
|
|
|
'view_mode': 'form', |
|
|
|
'res_model': 'accounting.file', |
|
|
|
'res_id': int(res.id), |
|
|
|
'type': 'ir.actions.act_window', |
|
|
|
'target': 'current' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#rajouter en fin de fichier un total DEBIT et un total CREDIT |
|
|
|
|
|
|
|
f.close |
|
|
|
|
|
|
|
#création de l'export en base |
|
|
|
vals={} |
|
|
|
|
|
|
|
|
|
|
|
f = open(filename, "r") |
|
|
|
data = str.encode(f.read(), 'utf-8') |
|
|
|
|
|
|
|
vals['accounting_file']=base64.encodebytes(data) |
|
|
|
vals['document_fname']='export_comptable.csv' |
|
|
|
vals['exported_date']=fields.Date.context_today(self) |
|
|
|
res=self.env['accounting.file'].create(vals) |
|
|
|
|
|
|
|
f.close |
|
|
|
os.unlink(filename) |
|
|
|
|
|
|
|
#affichage de l'export |
|
|
|
|
|
|
|
return { |
|
|
|
'name': 'Account file form', |
|
|
|
'view_type': 'form', |
|
|
|
'view_mode': 'form', |
|
|
|
'res_model': 'accounting.file', |
|
|
|
'res_id': int(res.id), |
|
|
|
'type': 'ir.actions.act_window', |
|
|
|
'target': 'current' |
|
|
|
} |
|
|
|
|
|
|
|
return True |
|
|
|
def donation_lines(self,f,no_mvt): |
|
|
|
#é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')]) |
|
|
|
for d in donation: |
|
|
|
#on ne prend pas en compte les dons liés à une retraite |
|
|
@ -54,6 +124,7 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
account_debit_number=self._file_format(str(d.payment_mode_id.fixed_journal_id.default_account_id.code),6) |
|
|
|
firstname=d.partner_id.firstname |
|
|
|
name=d.partner_id.name |
|
|
|
if not name : name='N/A' |
|
|
|
if not firstname: firstname=' ' |
|
|
|
lib1=firstname[0]+' '+name |
|
|
|
|
|
|
@ -88,7 +159,8 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_debit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n' |
|
|
|
f.write(fic_line) |
|
|
|
no_mvt=no_mvt+1 |
|
|
|
|
|
|
|
return no_mvt |
|
|
|
def membership_lines(self,f,no_mvt): |
|
|
|
#écritures pour les ADHESIONS réglées non déjà exportés |
|
|
|
membership=self.env['kalachakra.membership'].search([('date_compta','=',False),('state','=','done')]) |
|
|
|
for m in membership: |
|
|
@ -96,28 +168,27 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
|
|
|
|
#on ne prend pas en compte les adhésions liés à une retraite |
|
|
|
#car traité avec les retraites |
|
|
|
if m.invoice_id: continue |
|
|
|
|
|
|
|
#si l'adhésion est liée à une facture, alors on récupère la facture pour trouver le mode de paiement |
|
|
|
if m.balance_invoice_id: continue |
|
|
|
if m.invoice_id: |
|
|
|
#if not m.invoice_id.payment_id.fixed_journal_id: raise UserError(_("no account found for payment mode %r",m.invoice_id.payment_id.name)) |
|
|
|
account_debit_number=self._file_format(str(m.invoice_id.payment_id.fixed_journal_id.default_account_id.code),6) |
|
|
|
#si l'adhésion est liée à une transaction,le mode de paiement est CB |
|
|
|
elif m.transaction_id: |
|
|
|
reg=self.env['event.registration'].search([('invoice_id','=',int(m.invoice_id))]) |
|
|
|
if reg: |
|
|
|
if reg.event_id.booking_event:continue |
|
|
|
#si adhésion pas liée à une facture ou à une transaction, on ne prend pas |
|
|
|
if not m.invoice_id and not m.transaction_id : continue |
|
|
|
|
|
|
|
if m.transaction_id: |
|
|
|
CB_pm=self.env['account.payment.mode'].search([('name','=','CB')],limit=1) |
|
|
|
if CB_pm: |
|
|
|
account_debit_number=self._file_format(str(CB_pm.fixed_journal_id.default_account_id.code),6) |
|
|
|
else: |
|
|
|
raise UserError(_('please configure CB payement mode')) |
|
|
|
|
|
|
|
#sinon on prend le mode de paiement au niveau de la fiche d'adhésion |
|
|
|
else: |
|
|
|
if m.payment_mode_id: |
|
|
|
#if not m.payment_mode_id: raise UserError(_("no payment mode found for membership %r",m.partner_id.name)) |
|
|
|
account_debit_number=self._file_format(str(m.payment_mode_id.fixed_journal_id.default_account_id.code),6) |
|
|
|
|
|
|
|
if m.invoice_id: |
|
|
|
#if not m.invoice_id.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(m.invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6) |
|
|
|
|
|
|
|
firstname=m.partner_id.firstname |
|
|
|
name=m.partner_id.name |
|
|
|
if not name : name='N/A' |
|
|
|
if not firstname: firstname=' ' |
|
|
|
lib1=firstname[0]+' '+name |
|
|
|
lib1=self._file_format(lib1,12) |
|
|
@ -150,8 +221,8 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_debit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n' |
|
|
|
f.write(fic_line) |
|
|
|
no_mvt=no_mvt+1 |
|
|
|
|
|
|
|
|
|
|
|
return no_mvt |
|
|
|
def event_lines(self,f,no_mvt): |
|
|
|
#écritures pour les inscriptions évts hors RETRAITES avec facture payée non déjà exportés |
|
|
|
|
|
|
|
|
|
|
@ -161,16 +232,18 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
reg.date_compta=date_compta |
|
|
|
#if not reg.invoice_id.payment_mode_id.fixed_journal_id: raise UserError(_("no account found for payment mode %r",reg.invoice_id.payment_mode_id)) |
|
|
|
account_debit_number=self._file_format(str(reg.invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6) |
|
|
|
firstname=m.partner_id.firstname |
|
|
|
name=m.partner_id.name |
|
|
|
firstname=reg.partner_id.firstname |
|
|
|
name=reg.partner_id.name |
|
|
|
if not name : name='N/A' |
|
|
|
if not firstname: firstname=' ' |
|
|
|
lib1=firstname[0]+' '+name |
|
|
|
lib1=self._file_format(lib1,12) |
|
|
|
#date du paiement |
|
|
|
date_line=str(m.write_date.year)+'-'+str(m.write_date.month)+'-'+str(m.write_date.day) |
|
|
|
date_line=str(reg.write_date.year)+'-'+str(reg.write_date.month)+'-'+str(reg.write_date.day) |
|
|
|
date_line=self._date_format(date_line) |
|
|
|
|
|
|
|
amount=str(m.amount) |
|
|
|
if reg.invoice_id.amount_total==0: continue |
|
|
|
if reg.invoice_id.payment_state!='paid': continue |
|
|
|
amount=str(reg.invoice_id.amount_total) |
|
|
|
#if not reg.event_id.participation_product_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name)) |
|
|
|
account_credit_number=self._file_format(reg.event_id.participation_product_id.property_account_income_id.code,6) |
|
|
|
affectation=reg.event_id.participation_product_id.name |
|
|
@ -196,7 +269,8 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_debit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n' |
|
|
|
f.write(fic_line) |
|
|
|
no_mvt=no_mvt+1 |
|
|
|
|
|
|
|
return no_mvt |
|
|
|
def booking_event_lines(self,f,no_mvt): |
|
|
|
#écritures pour les inscription aux RETRAITES avec facture acomptes payés + factures soldes payés non déjà exporté |
|
|
|
registration=self.env['event.registration'].search(['|',('date_compta','=',False),('date_compta_down_payment','!=',False)]) |
|
|
|
|
|
|
@ -212,6 +286,7 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
|
|
|
|
firstname=reg.firstname |
|
|
|
name=reg.name |
|
|
|
if not name : name='N/A' |
|
|
|
if not firstname: firstname=' ' |
|
|
|
lib1=firstname[0]+' '+name |
|
|
|
lib1=self._file_format(lib1,12) |
|
|
@ -219,7 +294,7 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
lib=lib1+' '+lib2 |
|
|
|
|
|
|
|
#si pas de facture d'acompte et facture payée: |
|
|
|
if not reg.down_payment_invoice_id and reg.payment_status=='paid' and not reg.date_compta : |
|
|
|
if not reg.down_payment_invoice_id and reg.invoice_id.payment_state=='paid' and not reg.date_compta : |
|
|
|
|
|
|
|
down_payment=False |
|
|
|
balance_payment=False |
|
|
@ -242,7 +317,7 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
|
|
|
|
|
|
|
|
#si facture d'acompte payée et solde payée et pas encore exportée : |
|
|
|
if reg.payment_status=='paid' and not reg.date_compta: |
|
|
|
elif reg.down_payment_invoice_id.payment_state=='paid' and reg.balance_invoice_id.payment_state=='paid' and not reg.date_compta: |
|
|
|
reg.date_compta=date_compta |
|
|
|
down_payment=True |
|
|
|
balance_payment=True |
|
|
@ -270,10 +345,10 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
for d in donations: |
|
|
|
donation_amount=donation_amount+d.amount_total |
|
|
|
|
|
|
|
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.invoice_id)]) |
|
|
|
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.invoice_id.id)]) |
|
|
|
|
|
|
|
#si facture d'acompte payée pas encore exporté et solde non payée : |
|
|
|
if reg.payment_status=='down payment paid' and not reg.date_compta_down_payment: |
|
|
|
elif reg.down_payment_invoice_id.payment_state=='paid' and not reg.date_compta_down_payment: |
|
|
|
reg.date_compta_down_payment=date_compta |
|
|
|
down_payment=True |
|
|
|
balance_payment=False |
|
|
@ -283,9 +358,9 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
account_debit_number=self._file_format(str(reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6) |
|
|
|
amount=reg.down_payment_invoice_id.amount_total |
|
|
|
date_line=self._date_format(str(reg.down_payment_invoice_id.write_date)) |
|
|
|
|
|
|
|
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.down_payment_invoice_id.id)]) |
|
|
|
#si facture d'acompte payée et exporté et solde payée pas exporté : |
|
|
|
if reg.payment_status=='paid' and reg.date_compta_down_payment: |
|
|
|
elif reg.down_payment_invoice_id.payment_state=='paid' and reg.balance_invoice_id.payment_state=='paid' and reg.date_compta_down_payment: |
|
|
|
reg.date_compta=date_compta |
|
|
|
down_payment=False |
|
|
|
balance_payment=True |
|
|
@ -306,9 +381,11 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
donation_credit_line=True |
|
|
|
for d in donations: |
|
|
|
amount_donation=amount_donation+donations.amount_total |
|
|
|
|
|
|
|
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.balance_invoice_id.id)]) |
|
|
|
#écritures pour les inscription aux RETRAITES avec facture complémentaire |
|
|
|
|
|
|
|
else: continue |
|
|
|
|
|
|
|
if trans: |
|
|
|
lib_piece=self._file_format(trans.reference,20) |
|
|
|
else: |
|
|
@ -346,77 +423,7 @@ class AccountingFileWizard(models.TransientModel): |
|
|
|
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_credit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n' |
|
|
|
f.write(fic_line) |
|
|
|
no_mvt=no_mvt+1 |
|
|
|
|
|
|
|
f.close |
|
|
|
f = open(filename, "r") |
|
|
|
data = str.encode(f.read(), 'utf-8') |
|
|
|
#raise UserError('gg'+f.read()) |
|
|
|
vals={} |
|
|
|
vals['accounting_file']=base64.encodebytes(data) |
|
|
|
vals['document_fname']='export_comptable.txt' |
|
|
|
vals['exported_date']=fields.Date.context_today(self) |
|
|
|
res=self.env['accounting.file'].create(vals) |
|
|
|
f.close |
|
|
|
os.unlink(filename) |
|
|
|
|
|
|
|
#display account deposit |
|
|
|
return { |
|
|
|
'name': 'Account deposit form', |
|
|
|
'view_type': 'form', |
|
|
|
'view_mode': 'form', |
|
|
|
'res_model': 'accounting.file', |
|
|
|
'res_id': int(res.id), |
|
|
|
'type': 'ir.actions.act_window', |
|
|
|
'target': 'current' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#rajouter en fin de fichier un total DEBIT et un total CREDIT |
|
|
|
|
|
|
|
f.close |
|
|
|
|
|
|
|
#création de l'export en base |
|
|
|
vals={} |
|
|
|
|
|
|
|
|
|
|
|
f = open(filename, "r") |
|
|
|
data = str.encode(f.read(), 'utf-8') |
|
|
|
|
|
|
|
vals['accounting_file']=base64.encodebytes(data) |
|
|
|
vals['document_fname']='export_comptable.csv' |
|
|
|
vals['exported_date']=fields.Date.context_today(self) |
|
|
|
res=self.env['accounting.file'].create(vals) |
|
|
|
|
|
|
|
f.close |
|
|
|
os.unlink(filename) |
|
|
|
|
|
|
|
#affichage de l'export |
|
|
|
|
|
|
|
return { |
|
|
|
'name': 'Account file form', |
|
|
|
'view_type': 'form', |
|
|
|
'view_mode': 'form', |
|
|
|
'res_model': 'accounting.file', |
|
|
|
'res_id': int(res.id), |
|
|
|
'type': 'ir.actions.act_window', |
|
|
|
'target': 'current' |
|
|
|
} |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
return no_mvt |
|
|
|
def _file_format(self,data,nbcars): |
|
|
|
if data: |
|
|
|
if len(data)>nbcars: |
|
|
|