diff --git a/wizard/accounting_file_wizard.py b/wizard/accounting_file_wizard.py index 212a396..c2421bb 100644 --- a/wizard/accounting_file_wizard.py +++ b/wizard/accounting_file_wizard.py @@ -4,17 +4,59 @@ from datetime import datetime,date import os,secrets import decimal import base64 +import logging +import json +_logger = logging.getLogger(__name__) code_journal='IN' date_compta=fields.datetime.now() +total_debit=total_credit=0 +no_mvt=1 class AccountingFileWizard(models.TransientModel): _name = 'accounting.file.wizard' _description = 'accounting file wizard' + start_date=fields.Datetime('start date',required=True,default=lambda self: self._compute_start_date()) + + def _compute_start_date(self): + date_max=[] + #recherche de la date d'export d'écriture la plus récente + query="select max(date_compta) as date_compta from donation_donation" + self._cr.execute(query) + query_res = self._cr.dictfetchall() + for r in query_res: + d_date_compta=r['date_compta'] + if d_date_compta: date_max.append(d_date_compta) + + query="select max(date_compta) as date_compta from kalachakra_membership" + self._cr.execute(query) + query_res = self._cr.dictfetchall() + for r in query_res: + m_date_compta=r['date_compta'] + if m_date_compta: date_max.append(m_date_compta) + + query="select max(date_compta) as date_compta from event_registration" + self._cr.execute(query) + query_res = self._cr.dictfetchall() + for r in query_res: + e_date_compta=r['date_compta'] + if e_date_compta: date_max.append(e_date_compta) + + + if date_max: return max(date_max) + else: return fields.Date.context_today(self) + + + #accounting_date=fields.Date(string='Accounting date',required=True) def action_create_accounting_file(self): + global total_debit + global total_credit + total_debit=0 + total_credit=0 + #debug donation=self.env['donation.donation'].search([]) for d in donation: @@ -26,7 +68,7 @@ class AccountingFileWizard(models.TransientModel): for r in reg: r.date_compta=False r.date_compta_down_payment=False - + tmstp=secrets.token_hex(16) filename='/tmp/accounting_file_'+tmstp+'.txt' @@ -41,19 +83,18 @@ class AccountingFileWizard(models.TransientModel): #Débit ex: 200,00 #Crédit ex : 200,00 #N° de pièce: ref transaction , ex: txD-457 - no_mvt=1 + 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) - #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) - - - + self.donation_lines(f) + self.membership_lines(f) + self.event_lines(f) + self.booking_event_lines(f) + fic_line="TOTAL_DEBIT="+str(total_debit)+ " TOTAL CREDIT="+str(total_credit) + f.write(fic_line) f.close f = open(filename, "r") @@ -111,10 +152,15 @@ class AccountingFileWizard(models.TransientModel): } return True - def donation_lines(self,f,no_mvt): + def donation_lines(self,f): + global total_debit + global total_credit + global 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')]) + #raise UserError(donation) for d in donation: + if datetime(d.donation_date.year, d.donation_date.month, d.donation_date.day)nbcars: @@ -433,7 +622,44 @@ class AccountingFileWizard(models.TransientModel): else: return '' + def _payment_(self,move_id): + if move_id.invoice_payments_widget: + payment_info=json.loads(move_id.invoice_payments_widget) + if payment_info: + if datetime.strptime(payment_info['content'][0]['date'],'%Y-%m-%d')>self.start_date: + return False + + else: + return True + else:return True + + def _payment_date_date(self,move_id): + if move_id.invoice_payments_widget: + payment_info=json.loads(move_id.invoice_payments_widget) + if payment_info: + if datetime.strptime(payment_info['content'][0]['date'],'%Y-%m-%d')>self.start_date: + return False + + else: + return True + else:return True + + def _payment_date(self,move_id): + if move_id.invoice_payments_widget: + payment_info=json.loads(move_id.invoice_payments_widget) + if payment_info: + return self._date_format(payment_info['content'][0]['date']) + # + + else: + return 'False' + else:return 'False' def _date_format(self,data): - r=data.split('-') - return r[2]+'/'+r[1]+'/'+r[0] + #_logger.error('date='+str(data)) + if data: + r=str(data).split('-') + + return r[2]+'/'+r[1]+'/'+r[0] + else: + return 'False' diff --git a/wizard/accounting_file_wizard.xml b/wizard/accounting_file_wizard.xml index 12fcd4b..837ea46 100644 --- a/wizard/accounting_file_wizard.xml +++ b/wizard/accounting_file_wizard.xml @@ -5,11 +5,12 @@
-