Browse Source

accounting file

master
root 2 years ago
parent
commit
72b8ff5f97
5 changed files with 322 additions and 260 deletions
  1. +1
    -0
      models/__init__.py
  2. +15
    -0
      models/account_move.py
  3. +6
    -1
      models/event_registration.py
  4. +9
    -0
      views/account.xml
  5. +291
    -259
      wizard/accounting_file_wizard.py

+ 1
- 0
models/__init__.py View File

@ -25,4 +25,5 @@ from . import res_users
from . import membership_import
from . import online_payment
from . import accounting_file
from . import account_payment

+ 15
- 0
models/account_move.py View File

@ -18,7 +18,22 @@ class AccountMove(models.Model):
date_compta_end_of_stay=fields.Datetime('date import',default=False)
date_compta_out_refund=fields.Datetime('date import',default=False)
out_invoice_id=fields.Many2one('account.move' ,ondelete="cascade",domain="[('partner_id','=',partner_id),('move_type','=','out_invoice'),('state','!=','paid')]")
payment_ids=fields.Many2many('account.payment',compute='_compute_payment_ids')
def _compute_payment_ids(self):
payments=self.env['account.payment'].sudo().search([])
for rec in self:
rec.payment_ids=False
for p in payments:
for recon in p.reconciled_invoice_ids:
if recon.id==rec.id:
rec.write({'payment_ids':[(4,p.id)]})
def _compute_description(self):
for a in self:


+ 6
- 1
models/event_registration.py View File

@ -21,7 +21,7 @@ class EventRegistration(models.Model):
date_payment_down_payment=fields.Date('date payment down payment',compute='_compute_event_date_payment_down_payment')
date_payment_balance=fields.Date('date payment balance',compute='_compute_event_date_payment_balance')
date_payment_end_of_stay=fields.Date('date payment end of stay',compute='_compute_event_date_payment_end_of_stay')
def _compute_event_date_payment(self):
for rec in self:
if not rec.booking_event:
@ -42,6 +42,11 @@ class EventRegistration(models.Model):
rec.date_payment= payment_info['content'][0]['date']
else : rec.date_payment=False
else :rec.date_payment=False
# payments=self.env['account.payment'].search([])
# for p in payments:
# if p.reconciled_invoice_ids==rec.invoice_id:
# rec.date_payment=p.date
# break
else:
rec.date_payment=False
def _compute_event_date_payment_down_payment(self):


+ 9
- 0
views/account.xml View File

@ -34,6 +34,15 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field string="Out invoice" name="out_invoice_id" attrs="{'invisible': [('move_type', '!=', 'out_refund')]}"/>
<field name="payment_ids">
<tree>
<field name="date"/>
<field name="date_compta"/>
<field name="journal_id"/>
<field name="amount"/>
<field name="state"/>
</tree>
</field>
<field string="Date export compta" name="date_compta"/>
</xpath>
<xpath expr="//button[@name='button_draft']" position="after">


+ 291
- 259
wizard/accounting_file_wizard.py View File

@ -473,286 +473,318 @@ class AccountingFileWizard(models.TransientModel):
for reg in registration:
if reg.event_id.booking_event:
#_logger.error('acompte:'+str(reg.down_payment_invoice_id.payment_state)+' solde :'+str(reg.balance_invoice_id.payment_state)+' date_compta'+str(reg.date_compta)+' date_compta_down_payment:'+str(reg.date_compta_down_payment))
membership_amount=0
donation_amount=0
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)
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)
lib2=self._file_format(reg.event_id.booking_product_id.name,13)
lib=lib1+' '+lib2
#si pas de facture d'acompte et facture payée:
if not reg.down_payment_invoice_id and reg.balance_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 :
_logger.error('CC1')
if reg.date_payment and reg.date_payment<self.start_date.date(): continue
if not self.debug_mode: reg.date_compta=date_compta
case_line=1
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(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)
#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
#recherche de dons
donation_credit_line=False
donations=donation_booking=self.env['donation.donation'].search([('invoice_id','=',int(reg.invoice_id))])
if donations:
donation_credit_line=True
for d in donations:
donation_amount+=d.amount_total
self.booking_invoice_lines(f,reg)
#si facture d'acompte payée et pas encore exporté
if reg.down_payment_invoice_id.payment_state=='paid' and not reg.date_compta_down_payment:
date_line=self._date_format(reg.date_payment)
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.invoice_id.id)],limit=1)
if reg.date_payment_down_payment and reg.date_payment_down_payment>=self.start_date.date():
self.booking_down_payment_invoice_lines(f,reg)
#si facture d'acompte payée et solde payée et pas encore exportée :
elif reg.down_payment_invoice_id.payment_state=='paid' and reg.balance_invoice_id.payment_state=='paid' and not reg.date_compta_down_payment and not reg.date_compta :
_logger.error('CC2 '+'date_compta='+str(reg.date_compta)+' date_compta_down_payment='+str(reg.date_compta_down_payment))
if reg.date_payment_balance and reg.date_payment_balance<self.start_date.date(): continue
case_line=2
if not self.debug_mode: reg.date_compta=date_compta
down_payment=True
balance_payment=True
membership_amount=0
donation_amount=0
membership_credit_line=False
donation_credit_line=False
#if not reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id: raise UserError(_("no account found payment mode %r",reg.down_payment_invoice_id.payment_mode_id.name))
account_debit_number=self._file_format(str(reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),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)
#_logger.error('facture='+str(reg.down_payment_invoice_id.name)+str(reg.date_payment_down_payment))
if reg.date_payment_down_payment:
if reg.date_payment_down_payment>=self.start_date.date():
amount=reg.down_payment_invoice_id.amount_total+reg.balance_invoice_id.amount_total
else:
amount=reg.balance_invoice_id.amount_total
else:
#si pas de date de paiement, la facture doit être à zero
amount=reg.balance_invoice_id.amount_total
date_line=self._date_format(reg.date_payment_balance)
#recherche de l'adhésion
#si solde payée pas exporté :
if reg.balance_invoice_id.payment_state=='paid' and not reg.date_compta:
membership=self.env['kalachakra.membership'].search([('balance_invoice_id','=',int(reg.balance_invoice_id))])
if membership:
membership_credit_line=True
membership_amount=membership.amount
if reg.date_payment_balance and reg.date_payment_balance>=self.start_date.date():
self.booking_balance_invoice_lines(f,reg)
#recherche de dons
donation_credit_line=False
donations=donation_booking=self.env['donation.donation'].search([('invoice_id','=',int(reg.balance_invoice_id))])
if donations:
donation_credit_line=True
for d in donations:
donation_amount=donation_amount+d.amount_total
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.balance_invoice_id.id)],limit=1)
#si facture d'acompte payée pas encore exporté et solde non payée :
elif reg.down_payment_invoice_id.payment_state=='paid' and not reg.date_compta_down_payment and reg.balance_invoice_id.payment_state!='paid':
_logger.error('CC3')
if reg.date_payment_down_payment and reg.date_payment_down_payment<self.start_date.date(): continue
case_line=3
if not self.debug_mode: reg.date_compta_down_payment=date_compta
down_payment=True
balance_payment=False
donation_credit_line=False
membership_credit_line=False
#if not reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id: raise UserError(_("no account found payment mode %r",reg.down_payment_invoice_id.payment_mode_id.name))
account_debit_number=self._file_format(str(reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),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)
amount=reg.down_payment_invoice_id.amount_total
date_line=self._date_format(reg.date_payment_down_payment)
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.down_payment_invoice_id.id)],limit=1)
#si facture d'acompte payée et exporté et solde payée pas exporté :
elif reg.down_payment_invoice_id.payment_state=='paid' and reg.balance_invoice_id.payment_state=='paid' and reg.date_compta_down_payment and not reg.date_compta:
_logger.error('CC4')
if reg.date_payment_balance and reg.date_payment_balance<self.start_date.date(): continue
case_line=4
if not self.debug_mode: reg.date_compta=date_compta
down_payment=False
balance_payment=True
#if not reg.balance_invoice_id.payment_mode_id.fixed_journal_id: raise UserError(_("no account found payment mode %r",reg.balance_invoice_id.payment_mode_id.name))
account_debit_number=self._file_format(str(reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),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)
date_line=self._payment_date(reg.balance_invoice_id)
#recherche de l'adhésion
membership_credit_line=False
membership=self.env['kalachakra.membership'].search([('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
donations=donation_booking=self.env['donation.donation'].search([('invoice_id','=',int(reg.balance_invoice_id))])
if donations:
donation_credit_line=True
for d in donations:
amount_donation=amount_donation+donations.amount_total
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.balance_invoice_id.id)],limit=1)
else: continue
if trans:
lib_piece=self._file_format(trans.reference,20)
else:
if case_line==1:lib_piece=self._file_format(reg.invoice_id.name,20)
if case_line==2:lib_piece=self._file_format(reg.balance_invoice_id.name,20)
if case_line==3:lib_piece=self._file_format(reg.down_payment_invoice_id.name,20)
if case_line==4:lib_piece=self._file_format(reg.balance_invoice_id.name,20)
#debit line
if case_line==1:amount=reg.invoice_id.amount_total
if case_line==2:
down_payment_already_in_accounting=True
if reg.date_payment_down_payment:
if reg.date_payment_down_payment>=self.start_date.date():
down_payment_already_in_accounting=False
amount=reg.down_payment_invoice_id.amount_total+reg.balance_invoice_id.amount_total
else:
amount=reg.balance_invoice_id.amount_total
if case_line==3:amount=reg.down_payment_invoice_id.amount_total
if case_line==4:amount=reg.balance_invoice_id.amount_total
if amount==0: continue
credit=''
debit=str(amount)
account_number=account_debit_number
_logger.error('TOTAL DEBIT '+str(total_debit)+' TOTAL CREDIT '+str(total_credit))
return True
def booking_balance_invoice_lines(self,f,reg) :
global total_debit
global total_credit
global no_mvt
membership_amount=0
donation_amount=0
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)
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)
lib2=self._file_format(reg.event_id.booking_product_id.name,13)
lib=lib1+' '+lib2
if not self.debug_mode: reg.date_compta=date_compta
down_payment=False
balance_payment=True
#if not reg.balance_invoice_id.payment_mode_id.fixed_journal_id: raise UserError(_("no account found payment mode %r",reg.balance_invoice_id.payment_mode_id.name))
#account_debit_number=self._file_format(str(reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),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)
# if not trans:
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
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
#recherche de dons
donation_credit_line=False
donations=donation_booking=self.env['donation.donation'].search([('date_compta','=',False),('invoice_id','=',int(reg.balance_invoice_id))])
if donations:
donation_credit_line=True
for d in donations:
donation_amount+=donations.amount_total
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.balance_invoice_id.id)],limit=1)
if trans:
lib_piece=self._file_format(trans.reference,20)
else:
lib_piece=self._file_format(reg.balance_invoice_id.name,20)
amount=reg.balance_invoice_id.amount_total
if amount==0: return False
credit=''
debit=str(amount)
account_number=account_debit_number
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_debit+=amount
if not amount: amount=0
amount=reg.balance_invoice_id.amount_total-membership_amount-donation_amount
debit=''
credit=str(amount)
account_number=account_credit_number
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+=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=''
amount=d.amount_total
credit=str(amount)
account_number=account_credit_number
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_debit+=amount
total_credit+=amount
#credit(s) line(s)
#participation credit line
if not amount: amount=0
if case_line==1:
amount=amount-membership_amount-donation_amount
debit=''
credit=str(amount)
account_number=account_credit_number
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+=amount
if case_line==2:
if not down_payment_already_in_accounting:
amount=reg.down_payment_invoice_id.amount_total
debit=''
credit=str(amount)
account_number=account_credit_number
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+=amount
amount=float(reg.balance_invoice_id.amount_total)-float(membership_amount)-float(donation_amount)
debit=''
credit=str(amount)
account_number=account_credit_number
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+=amount
if case_line==3:
amount=reg.down_payment_invoice_id.amount_total
debit=''
credit=str(amount)
account_number=account_credit_number
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+=amount
if case_line==4:
amount=reg.balance_invoice_id.amount_total-membership_amount-donation_amount
debit=''
credit=str(amount)
account_number=account_credit_number
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+=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=''
amount=d.amount_total
credit=str(amount)
account_number=account_credit_number
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+=amount
def booking_down_payment_invoice_lines(self,f,reg):
global total_debit
global total_credit
global no_mvt
membership_amount=0
donation_amount=0
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)
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)
lib2=self._file_format(reg.event_id.booking_product_id.name,13)
lib=lib1+' '+lib2
if not self.debug_mode: reg.date_compta_down_payment=date_compta
down_payment=True
balance_payment=False
donation_credit_line=False
membership_credit_line=False
#if not reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id: raise UserError(_("no account found payment mode %r",reg.down_payment_invoice_id.payment_mode_id.name))
account_debit_number=self._file_format(str(reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),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)
amount=reg.down_payment_invoice_id.amount_total
date_line=self._date_format(reg.date_payment_down_payment)
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.down_payment_invoice_id.id)],limit=1)
if trans:
lib_piece=self._file_format(trans.reference,20)
else:
lib_piece=self._file_format(reg.down_payment_invoice_id.name,20)
amount=reg.down_payment_invoice_id.amount_total
if amount==0: return False
credit=''
debit=str(amount)
account_number=account_debit_number
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_debit+=amount
#credit(s) line(s)
#participation credit line
if not amount: amount=0
amount=reg.down_payment_invoice_id.amount_total
debit=''
credit=str(amount)
account_number=account_credit_number
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+=amount
_logger.error('TOTAL DEBIT '+str(total_debit)+' TOTAL CREDIT '+str(total_credit))
def booking_invoice_lines(self,f,reg):
global total_debit
global total_credit
global no_mvt
#_logger.error('acompte:'+str(reg.down_payment_invoice_id.payment_state)+' solde :'+str(reg.balance_invoice_id.payment_state)+' date_compta'+str(reg.date_compta)+' date_compta_down_payment:'+str(reg.date_compta_down_payment))
membership_amount=0
donation_amount=0
membership_credit_line=False
donation_credit_line=False
return True
#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)
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)
lib2=self._file_format(reg.event_id.booking_product_id.name,13)
lib=lib1+' '+lib2
if not self.debug_mode: reg.date_compta=date_compta
case_line=1
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(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)
#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
#recherche de dons
donation_credit_line=False
donations=donation_booking=self.env['donation.donation'].search([('invoice_id','=',int(reg.invoice_id))])
if donations:
donation_credit_line=True
for d in donations:
donation_amount+=d.amount_total
date_line=self._date_format(reg.date_payment)
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.invoice_id.id)],limit=1)
if trans:
lib_piece=self._file_format(trans.reference,20)
else:
lib_piece=self._file_format(reg.invoice_id.name,20)
#debit line
amount=reg.invoice_id.amount_total
if amount==0: return False
credit=''
debit=str(amount)
account_number=account_debit_number
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_debit+=amount
#credit(s) line(s)
#participation credit line
if not amount: amount=0
amount=amount-membership_amount-donation_amount
debit=''
credit=str(amount)
account_number=account_credit_number
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+=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=''
amount=d.amount_total
credit=str(amount)
account_number=account_credit_number
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+=amount
def out_refund_lines(self,f):
global total_debit


Loading…
Cancel
Save