Browse Source

account export+fix account.move

master
root 2 years ago
parent
commit
a4c9d28e8d
4 changed files with 145 additions and 70 deletions
  1. +21
    -1
      models/account_move.py
  2. +3
    -0
      views/account.xml
  3. +120
    -69
      wizard/accounting_file_wizard.py
  4. +1
    -0
      wizard/accounting_file_wizard.xml

+ 21
- 1
models/account_move.py View File

@ -15,13 +15,15 @@ class AccountMove(models.Model):
transaction_amount=fields.Float(compute='_compute_transaction_amount') transaction_amount=fields.Float(compute='_compute_transaction_amount')
systempay_ref=fields.Text(compute='_compute_systempay_ref') systempay_ref=fields.Text(compute='_compute_systempay_ref')
date_compta=fields.Datetime('date import',default=False) date_compta=fields.Datetime('date import',default=False)
date_compta_end_of_stay=fields.Datetime('date import',default=False)
date_compta_out_refund=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')]") out_invoice_id=fields.Many2one('account.move' ,ondelete="cascade",domain="[('partner_id','=',partner_id),('move_type','=','out_invoice'),('state','!=','paid')]")
def _compute_description(self): def _compute_description(self):
for a in self: for a in self:
description=''
a.description=''
for line in a.line_ids: for line in a.line_ids:
a.description=line.product_id.name a.description=line.product_id.name
break break
@ -55,5 +57,23 @@ class AccountMove(models.Model):
if r_s[0]==" 'vads_order_id'": if r_s[0]==" 'vads_order_id'":
a.systempay_ref=r_s[1].replace("'","") a.systempay_ref=r_s[1].replace("'","")
break break
def button_event_registration(self):
reg=self.env['event.registration'].search(['|','|','|',('invoice_id','=',self.id),\
('down_payment_invoice_id','=',self.id),\
('balance_invoice_id','=',self.id),\
('end_of_stay_invoice_id','=',self.id)])
if reg :
event_id=reg.event_id
action=self.env.ref('event.action_registration').read()[0]
action.update({
'view_mode': 'form',
'res_id': reg.id,
'view_type':'form',
"views": [[False, "form"]],
})
return action

+ 3
- 0
views/account.xml View File

@ -36,6 +36,9 @@
<field string="Out invoice" name="out_invoice_id" attrs="{'invisible': [('move_type', '!=', 'out_refund')]}"/> <field string="Out invoice" name="out_invoice_id" attrs="{'invisible': [('move_type', '!=', 'out_refund')]}"/>
<field string="Date export compta" name="date_compta"/> <field string="Date export compta" name="date_compta"/>
</xpath> </xpath>
<xpath expr="//button[@name='button_draft']" position="after">
<button name="button_event_registration" string="Event registration" type="object"/>
</xpath>
</field> </field>
</record> </record>

+ 120
- 69
wizard/accounting_file_wizard.py View File

@ -12,14 +12,14 @@ code_journal='IN'
date_compta=fields.datetime.now() date_compta=fields.datetime.now()
total_debit=total_credit=0 total_debit=total_credit=0
no_mvt=1 no_mvt=1
debug=True
class AccountingFileWizard(models.TransientModel): class AccountingFileWizard(models.TransientModel):
_name = 'accounting.file.wizard' _name = 'accounting.file.wizard'
_description = 'accounting file wizard' _description = 'accounting file wizard'
start_date=fields.Datetime('start date',required=True,default=lambda self: self._compute_start_date()) start_date=fields.Datetime('start date',required=True,default=lambda self: self._compute_start_date())
debug_mode=fields.Boolean('debug mode',default=True)
def _compute_start_date(self): def _compute_start_date(self):
date_max=[] date_max=[]
#recherche de la date d'export d'écriture la plus récente #recherche de la date d'export d'écriture la plus récente
@ -100,6 +100,7 @@ class AccountingFileWizard(models.TransientModel):
self.event_lines(f) self.event_lines(f)
self.booking_event_lines(f) self.booking_event_lines(f)
self.out_refund_lines(f) self.out_refund_lines(f)
self.end_of_stay_lines(f)
fic_line="TOTAL_DEBIT="+str(total_debit)+ " TOTAL CREDIT="+str(total_credit) fic_line="TOTAL_DEBIT="+str(total_debit)+ " TOTAL CREDIT="+str(total_credit)
f.write(fic_line) f.write(fic_line)
@ -128,38 +129,7 @@ class AccountingFileWizard(models.TransientModel):
} }
#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): def donation_lines(self,f):
global total_debit global total_debit
global total_credit global total_credit
@ -179,7 +149,7 @@ class AccountingFileWizard(models.TransientModel):
#on ne prend pas en compte les dons liés à une retraite #on ne prend pas en compte les dons liés à une retraite
#car traité avec les retraites #car traité avec les retraites
if d.invoice_id: continue if d.invoice_id: continue
if not debug: 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) account_debit_number=self._file_format(str(d.payment_mode_id.fixed_journal_id.default_account_id.code),6)
@ -237,7 +207,7 @@ class AccountingFileWizard(models.TransientModel):
for m in membership: for m in membership:
if datetime(m.start_date.year,m.start_date.month,m.start_date.day)<self.start_date:continue if datetime(m.start_date.year,m.start_date.month,m.start_date.day)<self.start_date:continue
if not debug: m.date_compta=date_compta
if not self.debug_mode: m.date_compta=date_compta
#on ne prend pas en compte les adhésions liés à une retraite #on ne prend pas en compte les adhésions liés à une retraite
#car traité avec les retraites #car traité avec les retraites
if m.balance_invoice_id: continue if m.balance_invoice_id: continue
@ -314,7 +284,7 @@ class AccountingFileWizard(models.TransientModel):
if reg.date_payment and reg.date_payment<self.start_date.date(): continue if reg.date_payment and reg.date_payment<self.start_date.date(): continue
membership_credit_line=False membership_credit_line=False
membership_amount=0 membership_amount=0
if not debug: reg.date_compta=date_compta
if not self.debug_mode: 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)) #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) account_debit_number=self._file_format(str(reg.invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6)
if not reg.invoice_id.payment_mode_id : if not reg.invoice_id.payment_mode_id :
@ -376,12 +346,110 @@ class AccountingFileWizard(models.TransientModel):
no_mvt+=1 no_mvt+=1
total_debit+=amount total_debit+=amount
return no_mvt return no_mvt
def end_of_stay_lines(self,f):
global total_debit
global total_credit
global no_mvt
registration=self.env['event.registration'].search([])
for reg in registration:
if not reg.end_of_stay_invoice_id:continue
if reg.end_of_stay_invoice_id.date_compta_end_of_stay:continue
if not reg.date_payment_end_of_stay:continue
if reg.date_payment_end_of_stay and reg.date_payment_end_of_stay<self.start_date.date(): continue
account_debit_number=self._file_format(str(reg.end_of_stay_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6)
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.end_of_stay_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)
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
#recherche de l'adhésion
membership_credit_line=False
membership=self.env['kalachakra.membership'].search([('invoice_id','=',int(reg.end_of_stay_invoice_id.id))])
membership_amount=0
if membership:
membership_credit_line=True
membership_amount=membership.amount
#recherche de dons
donation_credit_line=False
donation_amount=0
donations=donation_booking=self.env['donation.donation'].search([('invoice_id','=',int(reg.end_of_stay_invoice_id.id))])
if donations:
donation_credit_line=True
for d in donations:
donation_amount+=d.amount_total
date_line=self._payment_date(reg.end_of_stay_invoice_id)
#écriture de débit
if not self.debug_mode: reg.date_compta_end_of_stay=date_compta
amount=reg.end_of_stay_invoice_id.amount_total
if amount==0: continue
debit=str(amount)
credit=''
lib_piece=self._file_format(reg.end_of_stay_invoice_id.name,20)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_debit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt+=1
total_debit+=amount
#écriture de crédit
debit=''
credit=str(amount-membership_amount-donation_amount)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_credit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt+=1
total_credit+=amount
if membership_credit_line:
debit=''
credit=str(membership_amount)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+self._file_format('756100',6)+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
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)
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
total_credit+=amount
def booking_event_lines(self,f): def booking_event_lines(self,f):
global total_debit global total_debit
global total_credit global total_credit
global no_mvt global no_mvt
#écritures pour les inscription aux RETRAITES avec facture acomptes payés + factures soldes payés non déjà exporté #é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([]) registration=self.env['event.registration'].search([])
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)
for reg in registration: for reg in registration:
if reg.event_id.booking_event: if reg.event_id.booking_event:
@ -408,7 +476,7 @@ class AccountingFileWizard(models.TransientModel):
_logger.error('CC1') _logger.error('CC1')
if reg.date_payment and reg.date_payment<self.start_date.date(): continue if reg.date_payment and reg.date_payment<self.start_date.date(): continue
if not debug: reg.date_compta=date_compta
if not self.debug_mode: reg.date_compta=date_compta
case_line=1 case_line=1
down_payment=False down_payment=False
balance_payment=False balance_payment=False
@ -442,14 +510,14 @@ class AccountingFileWizard(models.TransientModel):
date_line=self._date_format(reg.date_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) trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.invoice_id.id)],limit=1)
#si facture d'acompte payée et solde payée et pas encore exportée : #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 : 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)) _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 if reg.date_payment_balance and reg.date_payment_balance<self.start_date.date(): continue
case_line=2 case_line=2
if not debug: reg.date_compta=date_compta
if not self.debug_mode: reg.date_compta=date_compta
down_payment=True down_payment=True
balance_payment=True balance_payment=True
membership_amount=0 membership_amount=0
@ -491,7 +559,7 @@ class AccountingFileWizard(models.TransientModel):
_logger.error('CC3') _logger.error('CC3')
if reg.date_payment_down_payment and reg.date_payment_down_payment<self.start_date.date(): continue if reg.date_payment_down_payment and reg.date_payment_down_payment<self.start_date.date(): continue
case_line=3 case_line=3
if not debug: reg.date_compta_down_payment=date_compta
if not self.debug_mode: reg.date_compta_down_payment=date_compta
down_payment=True down_payment=True
balance_payment=False balance_payment=False
donation_credit_line=False donation_credit_line=False
@ -511,7 +579,7 @@ class AccountingFileWizard(models.TransientModel):
_logger.error('CC4') _logger.error('CC4')
if reg.date_payment_balance and reg.date_payment_balance<self.start_date.date(): continue if reg.date_payment_balance and reg.date_payment_balance<self.start_date.date(): continue
case_line=4 case_line=4
if not debug: reg.date_compta=date_compta
if not self.debug_mode: reg.date_compta=date_compta
down_payment=False down_payment=False
balance_payment=True 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)) #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))
@ -540,6 +608,7 @@ class AccountingFileWizard(models.TransientModel):
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.balance_invoice_id.id)],limit=1) trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.balance_invoice_id.id)],limit=1)
else: continue else: continue
@ -631,34 +700,16 @@ class AccountingFileWizard(models.TransientModel):
no_mvt=no_mvt+1 no_mvt=no_mvt+1
total_credit+=amount total_credit+=amount
#écritures pour la facture complémentaire
if reg.end_of_stay_invoice_id and reg.end_of_stay_invoice_id.payment_state=='paid' :
if reg.date_payment_end_of_stay and reg.date_payment_end_of_stay<self.start_date.date(): continue
date_line=self._payment_date(reg.end_of_stay_invoice_id)
#écriture de débit
if not debug: reg.date_compta=date_compta
amount=reg.end_of_stay_invoice_id.amount_total
if amount==0: continue
debit=str(amount)
credit=''
lib_piece=self._file_format(reg.end_of_stay_invoice_id.name,20)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_debit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt+=1
total_debit+=amount
#écriture de crédit
debit=''
credit=str(amount)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_credit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt+=1
total_credit+=amount
_logger.error('TOTAL DEBIT '+str(total_debit)+' TOTAL CREDIT '+str(total_credit)) _logger.error('TOTAL DEBIT '+str(total_debit)+' TOTAL CREDIT '+str(total_credit))
return True return True
def out_refund_lines(self,f): def out_refund_lines(self,f):
global total_debit global total_debit
global total_credit global total_credit
@ -666,7 +717,7 @@ class AccountingFileWizard(models.TransientModel):
#écritures pour les avoirs pas encore utilisés ou payés mais jamais passé en compta #écritures pour les avoirs pas encore utilisés ou payés mais jamais passé en compta
out_refund_invoices=self.env['account.move'].search([('move_type','=','out_refund'),('state','=','posted'),('payment_state','=','not_paid'),('date_compta','=',False),('date_compta_out_refund','=',False)]) out_refund_invoices=self.env['account.move'].search([('move_type','=','out_refund'),('state','=','posted'),('payment_state','=','not_paid'),('date_compta','=',False),('date_compta_out_refund','=',False)])
for invoice in out_refund_invoices: for invoice in out_refund_invoices:
if not debug: invoice.date_compta_out_refund=date_compta
if not self.debug_mode: invoice.date_compta_out_refund=date_compta
firstname=invoice.partner_id.firstname firstname=invoice.partner_id.firstname
name=invoice.partner_id.name name=invoice.partner_id.name
if not name : name='N/A' if not name : name='N/A'
@ -710,11 +761,11 @@ class AccountingFileWizard(models.TransientModel):
out_refund_invoices=self.env['account.move'].search([('move_type','=','out_refund'),('payment_state','=','paid'),('date_compta','=',False)]) out_refund_invoices=self.env['account.move'].search([('move_type','=','out_refund'),('payment_state','=','paid'),('date_compta','=',False)])
for invoice in out_refund_invoices: for invoice in out_refund_invoices:
_logger.error(invoice.id)
if not debug: invoice.date_compta=date_compta
#_logger.error(invoice.id)
if not self.debug_mode: invoice.date_compta=date_compta
firstname=invoice.partner_id.firstname firstname=invoice.partner_id.firstname
name=invoice.partner_id.name name=invoice.partner_id.name
_logger.error(name)
#_logger.error(name)
if not name : name='N/A' if not name : name='N/A'
if not firstname: firstname=' ' if not firstname: firstname=' '
lib1=firstname[0]+' '+name lib1=firstname[0]+' '+name
@ -735,7 +786,7 @@ class AccountingFileWizard(models.TransientModel):
account_debit_number='411000' account_debit_number='411000'
#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))
if not self._payment_date_ok(invoice):continue if not self._payment_date_ok(invoice):continue
date_line=self._payment_date(invoice) date_line=self._payment_date(invoice)
@ -785,7 +836,7 @@ class AccountingFileWizard(models.TransientModel):
payment_info=json.loads(move.invoice_payments_widget) payment_info=json.loads(move.invoice_payments_widget)
if payment_info: if payment_info:
_logger.error(payment_info['content'][0]['date'])
#_logger.error(payment_info['content'][0]['date'])
if datetime.strptime(payment_info['content'][0]['date'],'%Y-%m-%d')>=self.start_date: if datetime.strptime(payment_info['content'][0]['date'],'%Y-%m-%d')>=self.start_date:
return True return True


+ 1
- 0
wizard/accounting_file_wizard.xml View File

@ -6,6 +6,7 @@
<form string="Accounting file wizard"> <form string="Accounting file wizard">
<group> <group>
<field name="start_date" widget="date"/> <field name="start_date" widget="date"/>
<field name="debug_mode"/>
</group> </group>


Loading…
Cancel
Save