From 51aec8f46c2f9da4d317ef337074ea99773427cb Mon Sep 17 00:00:00 2001 From: root Date: Sat, 27 Jan 2024 20:49:22 +0100 Subject: [PATCH] export cdr --- __manifest__.py | 4 +- views/accounting_file.xml | 42 +------- views/accounting_file_cdr.xml | 56 ++++++++++ wizard/accounting_file_wizard_cdr.py | 150 +++++++++++++++----------- wizard/accounting_file_wizard_cdr.xml | 40 +++++++ 5 files changed, 191 insertions(+), 101 deletions(-) create mode 100755 views/accounting_file_cdr.xml create mode 100644 wizard/accounting_file_wizard_cdr.xml diff --git a/__manifest__.py b/__manifest__.py index 7933abf..a5ef714 100755 --- a/__manifest__.py +++ b/__manifest__.py @@ -73,7 +73,9 @@ 'views/mediatheque.xml', 'views/account.xml', 'views/accounting_file.xml', - 'wizard/accounting_file_wizard.xml' + 'views/accounting_file_cdr.xml', + 'wizard/accounting_file_wizard.xml', + 'wizard/accounting_file_wizard_cdr.xml' #'views/payment_views.xml' diff --git a/views/accounting_file.xml b/views/accounting_file.xml index 942d380..17ba61c 100755 --- a/views/accounting_file.xml +++ b/views/accounting_file.xml @@ -15,19 +15,6 @@ - - CDR kalachakra_accounting file list - cdr.accounting.file - - - - - - - - - - kalachakra_accounting_file form @@ -49,25 +36,7 @@ - - CDR kalachakra_accounting_file form - cdr.accounting.file - -
- - - - - - - - - - - -
-
-
+ Accounting files @@ -75,19 +44,14 @@ tree,form,pivot - - CDR accounting files - cdr.accounting.file - tree,form,pivot - + - + \ No newline at end of file diff --git a/views/accounting_file_cdr.xml b/views/accounting_file_cdr.xml new file mode 100755 index 0000000..c43bb2a --- /dev/null +++ b/views/accounting_file_cdr.xml @@ -0,0 +1,56 @@ + + + + + + CDR kalachakra_accounting file list + cdr.accounting.file + + + + + + + + + + + + + + + CDR kalachakra_accounting_file form + cdr.accounting.file + +
+ + + + + + + + + + + +
+
+
+ + + + + CDR accounting files + cdr.accounting.file + tree,form,pivot + + + + + + + +
+
\ No newline at end of file diff --git a/wizard/accounting_file_wizard_cdr.py b/wizard/accounting_file_wizard_cdr.py index ae2e508..33dc45d 100644 --- a/wizard/accounting_file_wizard_cdr.py +++ b/wizard/accounting_file_wizard_cdr.py @@ -39,7 +39,7 @@ class CdrAccountingFileWizard(models.TransientModel): 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_credit total_debit=0 @@ -84,7 +84,7 @@ class CdrAccountingFileWizard(models.TransientModel): vals['exported_date']=fields.Date.context_today(self) vals['start_date']=self.start_date vals['end_date']=self.end_date - res=self.env['accounting.file'].create(vals) + res=self.env['cdr.accounting.file'].create(vals) f.close os.unlink(filename) @@ -93,7 +93,7 @@ class CdrAccountingFileWizard(models.TransientModel): 'name': 'Account deposit form', 'view_type': 'form', 'view_mode': 'form', - 'res_model': 'accounting.file', + 'res_model': 'cdr.accounting.file', 'res_id': int(res.id), 'type': 'ir.actions.act_window', 'target': 'current' @@ -111,6 +111,7 @@ class CdrAccountingFileWizard(models.TransientModel): 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: @@ -129,10 +130,10 @@ class CdrAccountingFileWizard(models.TransientModel): 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.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 name=d.partner_id.name @@ -154,9 +155,11 @@ class CdrAccountingFileWizard(models.TransientModel): affectation=line.product_id.name 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)) - 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 + if account_debit_number!='170000':continue #credit line lib2=self._file_format(affectation,13) lib=lib1+' '+lib2 @@ -281,14 +284,19 @@ class CdrAccountingFileWizard(models.TransientModel): registration=self.env['event.registration'].search([]) membership_amount=0 donation_amount=0 - membership_credit_line=False + #membership_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)) - account_credit_number=self._file_format('170000',6) + + for reg in registration: 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: 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 no_mvt - membership_amount=0 + #membership_amount=0 donation_amount=0 - membership_credit_line=False + #membership_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)) - 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 name=reg.partner_id.name @@ -342,20 +354,23 @@ class CdrAccountingFileWizard(models.TransientModel): down_payment=False 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) #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 donation_credit_line=False @@ -381,7 +396,7 @@ class CdrAccountingFileWizard(models.TransientModel): total_debit+=amount 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='' credit=str(amount) account_number=account_credit_number @@ -390,21 +405,21 @@ class CdrAccountingFileWizard(models.TransientModel): no_mvt=no_mvt+1 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: for d in donations : - debit='' + credit='' amount=d.amount_total - credit=str(amount) - account_number=account_credit_number + debit=str(amount) + account_number='170000' 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 @@ -425,7 +440,11 @@ class CdrAccountingFileWizard(models.TransientModel): 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)) - 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 name=reg.partner_id.name @@ -442,7 +461,10 @@ class CdrAccountingFileWizard(models.TransientModel): donation_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) 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) @@ -499,7 +521,11 @@ class CdrAccountingFileWizard(models.TransientModel): 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)) - 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 name=reg.partner_id.name @@ -515,22 +541,24 @@ class CdrAccountingFileWizard(models.TransientModel): down_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)) - 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 - 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 donation_credit_line=False @@ -568,7 +596,7 @@ class CdrAccountingFileWizard(models.TransientModel): #participation credit line if not amount: amount=0 - amount=amount-membership_amount-donation_amount + amount=amount-donation_amount debit='' credit=str(amount) account_number=account_credit_number @@ -577,21 +605,21 @@ class CdrAccountingFileWizard(models.TransientModel): no_mvt=no_mvt+1 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: for d in donations : - debit='' + credit='' amount=d.amount_total - credit=str(amount) - account_number=account_credit_number + debit=str(amount) + account_number='170000' 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 @@ -626,7 +654,7 @@ class CdrAccountingFileWizard(models.TransientModel): lib_piece=self._file_format(invoice.name,20) #écriture de débit amount=invoice.amount_total - account_debit_number='170000' + account_debit_number='754700' date_line=self._date_format(invoice.invoice_date) if amount==0: continue debit=str(amount) @@ -681,7 +709,7 @@ class CdrAccountingFileWizard(models.TransientModel): #écriture de débit amount=invoice.amount_total - account_debit_number='170000' + account_debit_number='411900' #date du paiement #_logger.error(self._payment_date_ok(invoice.out_invoice_id)) diff --git a/wizard/accounting_file_wizard_cdr.xml b/wizard/accounting_file_wizard_cdr.xml new file mode 100644 index 0000000..24f8aa3 --- /dev/null +++ b/wizard/accounting_file_wizard_cdr.xml @@ -0,0 +1,40 @@ + + + cdr accounting_file_wizard view + cdr.accounting.file.wizard + +
+ + + + + + + + + + + +
+
+
+
+
+ + + + Generate cdr accounting file + cdr.accounting.file.wizard + + form + new + + + + + + +
\ No newline at end of file