L10N_CH/V11 : new version from crystal branch
bzr revid: pinky-f13214b4254c6cb2c4343eec9310732da9c72768
This commit is contained in:
parent
d99f39edaa
commit
d38455cf2e
|
@ -35,11 +35,17 @@ class account_v11(osv.osv):
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char('Date', size=64), # pe mettre une sequence
|
'name': fields.char('Date', size=64), # pe mettre une sequence
|
||||||
'file': fields.binary('V11 file'),
|
'file': fields.binary('V11 file'),
|
||||||
|
'state': fields.selection([('new','New'), # completely new file
|
||||||
|
('partial','Partial'), # file with unknown lines
|
||||||
|
('error','Error'), # file completely wrong
|
||||||
|
('done','Done')], # file ok even if some lines were ignored
|
||||||
|
'State',readonly= True),
|
||||||
'note': fields.text('Import log'),
|
'note': fields.text('Import log'),
|
||||||
}
|
}
|
||||||
|
|
||||||
_defaults= {
|
_defaults= {
|
||||||
'name': lambda *a : time.strftime('%Y-%m-%d'),
|
'name': lambda *a : time.strftime('%Y-%m-%d'),
|
||||||
|
'state': lambda *a : 'new',
|
||||||
}
|
}
|
||||||
account_v11()
|
account_v11()
|
||||||
|
|
||||||
|
|
|
@ -27,139 +27,166 @@
|
||||||
import pooler
|
import pooler
|
||||||
import time
|
import time
|
||||||
import wizard
|
import wizard
|
||||||
import ir
|
|
||||||
import netsvc
|
import netsvc
|
||||||
from time import sleep
|
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
|
from osv import osv
|
||||||
|
|
||||||
|
ask_form = """<?xml version="1.0"?>
|
||||||
test_form = """<?xml version="1.0"?>
|
|
||||||
<form string="V11 parsing">
|
<form string="V11 parsing">
|
||||||
<separator colspan="4" string="Extract V11 data ?" />
|
<separator colspan="4" string="Extract V11 data :" />
|
||||||
<field name="journal_id"/>
|
<field name="journal_id" colspan="1"/>
|
||||||
|
<newline/>
|
||||||
|
<field name="v11"/>
|
||||||
</form>
|
</form>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
test_fields = {
|
ask_fields = {
|
||||||
'journal_id' : {
|
'journal_id' : {
|
||||||
'string':'Destination Journal',
|
'string':'Destination Journal',
|
||||||
'type':'many2one',
|
'type':'many2one',
|
||||||
'relation':'account.journal',
|
'relation':'account.journal',
|
||||||
'required':True,
|
'required':True,
|
||||||
# 'domain':[('type','=','sale')]
|
},
|
||||||
|
'v11' : {
|
||||||
|
'string':'V11 file',
|
||||||
|
'type':'binary',
|
||||||
|
'required':True,
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res_form = """<?xml version="1.0"?>
|
||||||
|
<form string="V11 parsing">
|
||||||
|
<separator colspan="4" string="Results :" />
|
||||||
|
<field name="journal_id"/>
|
||||||
|
<newline/>
|
||||||
|
<field name="v11"/>
|
||||||
|
<separator string="Logs" colspan="4"/>
|
||||||
|
<field name="note" colspan="4" nolabel="1"/>
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
|
||||||
|
res_fields = {
|
||||||
|
'journal_id' : {
|
||||||
|
'string':'Destination Journal',
|
||||||
|
'type':'many2one',
|
||||||
|
'relation':'account.journal',
|
||||||
|
'required':True,
|
||||||
|
},
|
||||||
|
'v11' : {
|
||||||
|
'string':'V11 file',
|
||||||
|
'type':'binary',
|
||||||
|
'required':True,
|
||||||
|
},
|
||||||
|
|
||||||
|
'note' : {'string':'Log','type':'text'}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _v11_parsing(self, cr, uid, data, context):
|
def _v11_parsing(self, cr, uid, data, context):
|
||||||
|
|
||||||
pool = pooler.get_pool(cr.dbname)
|
pool = pooler.get_pool(cr.dbname)
|
||||||
v11_obj = pool.get('account.v11')
|
v11 = data['form']['v11']
|
||||||
|
|
||||||
for v11 in v11_obj.browse(cr, uid, data['ids']):
|
|
||||||
|
|
||||||
line=""
|
|
||||||
record={}
|
|
||||||
total={}
|
|
||||||
total_compute= 0
|
|
||||||
rec_list=[]
|
|
||||||
log=''
|
|
||||||
|
|
||||||
|
|
||||||
# v11 parsing :
|
line=""
|
||||||
for char in b64decode(v11.file):
|
record={}
|
||||||
|
total={}
|
||||||
|
total_compute= 0
|
||||||
|
rec_list=[]
|
||||||
|
log=''
|
||||||
|
nb_err=0
|
||||||
|
|
||||||
if not char == '\n':
|
# v11 parsing :
|
||||||
line += char
|
for char in b64decode(v11):
|
||||||
|
|
||||||
|
if not char == '\n':
|
||||||
|
line += char
|
||||||
|
|
||||||
|
else :
|
||||||
|
|
||||||
|
record['genre'] = line[0:3]
|
||||||
|
|
||||||
|
if record['genre'] == '999':
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
total={'n_postal': line[3:12],
|
||||||
|
'cle': line[12:39],
|
||||||
|
'tot_montant': line[39:51],
|
||||||
|
'nb_rec': line[51:63],
|
||||||
|
'date_etabl': line[63:69],
|
||||||
|
'tot_frais_encaissement': line[69:78],
|
||||||
|
}
|
||||||
|
|
||||||
else :
|
else :
|
||||||
|
|
||||||
record['genre'] = line[0:3]
|
record={'n_postal': line[3:12],
|
||||||
|
'n_ref': line[12:39],
|
||||||
|
'montant': line[39:49],
|
||||||
|
'reserve': line[49:59],
|
||||||
|
'date_remise': line[59:65],
|
||||||
|
'date_comptable': line[65:71],
|
||||||
|
'date_valeur': line[71:77],
|
||||||
|
'invoice_ref': line[77:87],
|
||||||
|
'reserve2': line[87:96],
|
||||||
|
'frais_encaissement': line[96:100],
|
||||||
|
'line':line,
|
||||||
|
}
|
||||||
|
|
||||||
if record['genre'] == '999':
|
total_compute+= int(record['montant'])
|
||||||
|
rec_list.append( record )
|
||||||
|
|
||||||
|
line=""
|
||||||
|
|
||||||
|
|
||||||
|
# check the amounts :
|
||||||
|
if not total_compute == int(total['tot_montant']):
|
||||||
|
return {'note': 'Incoherent V11 file ! IMPORT ABORTED.' }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
total={'n_postal': line[3:12],
|
period_id = pool.get('account.period').find(cr,uid, context=context)
|
||||||
'cle': line[12:39],
|
if not period_id:
|
||||||
'tot_montant': line[39:51],
|
return {'note': 'No period found ! IMPORT ABORTED.' }
|
||||||
'nb_rec': line[51:63],
|
|
||||||
'date_etabl': line[63:69],
|
|
||||||
'tot_frais_encaissement': line[69:78],
|
|
||||||
}
|
|
||||||
|
|
||||||
else :
|
period_id = period_id[0]
|
||||||
|
invoice_obj= pool.get('account.invoice')
|
||||||
|
|
||||||
record={'n_postal': line[3:12],
|
acc2 = pool.get('account.journal').browse(cr,uid,data['form']['journal_id'],context).default_debit_account_id.id
|
||||||
'n_ref': line[12:39],
|
if not acc2:
|
||||||
'montant': line[39:49],
|
return {'note': 'No debit account specified for this journal ! IMPORT ABORTED.' }
|
||||||
'reserve': line[49:59],
|
|
||||||
'date_remise': line[59:65],
|
|
||||||
'date_comptable': line[65:71],
|
|
||||||
'date_valeur': line[71:77],
|
|
||||||
'internal_ref': line[77:87],
|
|
||||||
'reserve2': line[87:96],
|
|
||||||
'frais_encaissement': line[96:100],
|
|
||||||
'line':line,
|
|
||||||
}
|
|
||||||
|
|
||||||
total_compute+= int(record['montant'])
|
|
||||||
rec_list.append( record )
|
|
||||||
|
|
||||||
line=""
|
|
||||||
|
|
||||||
|
|
||||||
# check the amounts :
|
|
||||||
if not total_compute == int(total['tot_montant']):
|
for rec in rec_list:
|
||||||
raise wizard.except_wizard('warning', 'Incoherent v11 file !')
|
|
||||||
|
# get the invoice via his number
|
||||||
|
try:
|
||||||
|
invoice_id= invoice_obj.search(cr,uid,[ ('number','=',int(rec['invoice_ref'])) ])[0]
|
||||||
|
except:
|
||||||
|
log = log + '\n * No invoice with invoice number '+ rec['invoice_ref'].lstrip('0') + '.\n line : '+rec['line']
|
||||||
|
nb_err+=1
|
||||||
|
continue
|
||||||
|
invoice = invoice_obj.browse(cr, uid, invoice_id)
|
||||||
|
|
||||||
|
try:
|
||||||
|
acc1 = invoice.partner_id.property_account_receivable[0]
|
||||||
|
except:
|
||||||
|
log = log + '\n * invoice with number '+ rec['invoice_ref'].lstrip('0') +' has no partner !'+ '\n line : '+rec['line']
|
||||||
|
nb_err+=1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
period_id = pool.get('account.period').find(cr,uid, context=context)
|
|
||||||
if not period_id:
|
|
||||||
raise wizard.except_wizard('No period found !', 'Unable to find a valid period !')
|
|
||||||
period_id = period_id[0]
|
|
||||||
invoice_obj= pool.get('account.invoice')
|
|
||||||
for rec in rec_list:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# recherche sur l'id (pr garder un num absolu):
|
|
||||||
# implique de mettre l'id sur le bvr..
|
|
||||||
invoice_id= invoice_obj.search(cr,uid,[ ('id','=',int(rec['internal_ref'])) ])[0]
|
|
||||||
print invoice_id
|
|
||||||
invoice = invoice_obj.browse(cr, uid, invoice_id)
|
|
||||||
invoice_obj.write(cr,uid,[invoice_id],{'state':'paid'})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# TODO feedbacker en log les erreurs
|
|
||||||
acc2 = pool.get('account.journal').browse(cr,uid,data['form']['journal_id'],context).default_debit_account_id.id
|
|
||||||
if not acc2:
|
|
||||||
raise wizard.except_wizard('Warning !', 'No debit account specified for this journal !')
|
|
||||||
continue
|
|
||||||
|
|
||||||
# TODO idem
|
|
||||||
try:
|
|
||||||
acc1 = invoice.partner_id.property_account_receivable[0]
|
|
||||||
except:
|
|
||||||
raise wizard.except_wizard('Warning !','invoice with number '+str(int(rec['internal_ref'])) +' has no partner !')
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
move_id = pool.get('account.move').create(cr, uid, {
|
move_id = pool.get('account.move').create(cr, uid, {
|
||||||
'name': 'Imported from v11',
|
'name': 'Imported from v11',
|
||||||
'period_id': period_id,
|
'period_id': period_id,
|
||||||
'journal_id': data['form']['journal_id']
|
'journal_id': data['form']['journal_id']
|
||||||
})
|
})
|
||||||
|
line_id = pool.get('account.move.line').create(cr,uid,{
|
||||||
|
'name': 'v11', # maybe a better name ..
|
||||||
|
|
||||||
pool.get('account.move.line').create(cr,uid,{
|
|
||||||
'name': 'v11',
|
|
||||||
'debit': 0,
|
'debit': 0,
|
||||||
'credit': rec['montant'],
|
'credit': rec['montant'],
|
||||||
'account_id': acc1,
|
'account_id': acc1,
|
||||||
|
@ -182,42 +209,65 @@ def _v11_parsing(self, cr, uid, data, context):
|
||||||
'journal_id': data['form']['journal_id']
|
'journal_id': data['form']['journal_id']
|
||||||
|
|
||||||
})
|
})
|
||||||
|
account_move_lines = invoice.move_line_id_payment_get(cr,uid,[invoice.id])
|
||||||
|
|
||||||
|
if not account_move_lines:
|
||||||
|
raise Exception("No moves associated to invoice number "+ rec['invoice_ref'].lstrip('0'))
|
||||||
|
account_move_lines.append(line_id )
|
||||||
|
pool.get('account.move.line').reconcile(cr,uid,account_move_lines,
|
||||||
|
writeoff_acc_id=0,#FIXME
|
||||||
|
writeoff_journal_id=0,#FIXME
|
||||||
|
writeoff_period_id= 0,
|
||||||
|
)
|
||||||
|
cr.commit()
|
||||||
|
|
||||||
|
except osv.except_osv, e:
|
||||||
|
cr.rollback()
|
||||||
|
nb_err+=1
|
||||||
|
if e.value.startswith('You have to provide an account for the write off entry !'):
|
||||||
|
log= log +'\n * Error amount mismatch for invoice '+ rec['invoice_ref'].lstrip('0')+ ':\n line : '+rec['line']
|
||||||
|
else:
|
||||||
|
log= log +'\n * '+str(e.value)+ ' :\n line : '+rec['line']
|
||||||
|
#raise # REMOVEME
|
||||||
|
|
||||||
|
except Exception, e:
|
||||||
|
cr.rollback()
|
||||||
|
nb_err+=1
|
||||||
|
log= log +'\n * '+str(e)+ ' :\n line : '+rec['line']
|
||||||
|
#raise # REMOVEME
|
||||||
|
except :
|
||||||
|
cr.rollback()
|
||||||
|
nb_err+=1
|
||||||
|
log= log +'\n * Reconciliation Error\n line : '+rec['line']
|
||||||
|
#raise
|
||||||
|
|
||||||
|
log= log + '-'*5 +'\nNumber of parsed lines : '+ str(len(rec_list)) +'\nNumber of error : '+ str(nb_err)
|
||||||
|
|
||||||
|
return {'note':log,'journal_id': data['form']['journal_id'], 'v11': data['form']['v11']}
|
||||||
|
|
||||||
|
|
||||||
|
# def _init(self, cr, uid, data, context):
|
||||||
log= log + 'Number of parsed lines : '+ str(len(rec_list)) +'\nTotal amount for this bvr : '+ str(int(total['tot_montant']))+' '+invoice.currency_id.name
|
# if not data['form']:
|
||||||
|
# return {}
|
||||||
|
# return {'journal_id': data['form']['journal_id'], 'v11': data['form']['v11']}
|
||||||
v11.write(cr,uid,[v11.id],{'note': log })
|
|
||||||
|
|
||||||
# peut-etre retourner un nouvel onglet avec la liste des ecritures generee :
|
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class v11_import(wizard.interface):
|
class v11_import(wizard.interface):
|
||||||
states = {
|
states = {
|
||||||
'init' : {
|
'init' : {
|
||||||
'actions' : [],
|
'actions' : [],
|
||||||
'result' : {'type' : 'form',
|
'result' : {'type' : 'form',
|
||||||
'arch' : test_form,
|
'arch' : ask_form,
|
||||||
'fields' : test_fields,
|
'fields' : ask_fields,
|
||||||
'state' : [('end', 'Cancel'),('extraction', 'Yes') ]}
|
'state' : [('end', 'Cancel'),('extraction', 'Yes') ]}
|
||||||
},
|
},
|
||||||
'extraction' : {
|
'extraction' : {
|
||||||
'actions' : [_v11_parsing],
|
'actions' : [_v11_parsing],
|
||||||
'result' : {'type' : 'state', 'state' : 'end'}
|
'result' : {'type' : 'form',
|
||||||
|
'arch' : res_form,
|
||||||
|
'fields' : res_fields,
|
||||||
|
'state' : [('extraction', 'Retry') ,('end', 'Quit') ]}
|
||||||
},
|
},
|
||||||
|
|
||||||
# 'result' : {
|
|
||||||
# 'actions' : [],
|
|
||||||
# 'result' : {'type' : 'form',
|
|
||||||
# 'state' : 'end'}
|
|
||||||
# },
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
v11_import("account.v11_import")
|
v11_import("account.v11_import")
|
||||||
|
|
||||||
|
|
|
@ -5,33 +5,34 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- defini le formulaire -->
|
<!-- <\!-- defini le formulaire -\-> -->
|
||||||
<record model="ir.ui.view" id="view_v11_form">
|
<!-- <record model="ir.ui.view" id="view_v11_form"> -->
|
||||||
<field name="name">account.v11.form</field>
|
<!-- <field name="name">account.v11.form</field> -->
|
||||||
<field name="model">account.v11</field>
|
<!-- <field name="model">account.v11</field> -->
|
||||||
<field name="type">form</field>
|
<!-- <field name="type">form</field> -->
|
||||||
<field name="arch" type="xml">
|
<!-- <field name="arch" type="xml"> -->
|
||||||
<form string="V11">
|
<!-- <form string="V11"> -->
|
||||||
<field name="name" />
|
<!-- <field name="name" /> -->
|
||||||
<field name="file" />
|
<!-- <field name="file" /> -->
|
||||||
<separator colspan="3" />
|
<!-- <field name="state" colors="red:state=='error'"/> -->
|
||||||
<field name="note" colspan="4" select="1"/>
|
<!-- <separator colspan="3" /> -->
|
||||||
</form>
|
<!-- <field name="note" colspan="4" select="1"/> -->
|
||||||
</field>
|
<!-- </form> -->
|
||||||
</record>
|
<!-- </field> -->
|
||||||
|
<!-- </record> -->
|
||||||
|
|
||||||
<!-- defini une action -->
|
<!-- <\!-- defini une action -\-> -->
|
||||||
<record model="ir.actions.act_window" id="open_view_test_form">
|
<!-- <record model="ir.actions.act_window" id="open_view_test_form"> -->
|
||||||
<field name="name">account.v11</field>
|
<!-- <field name="name">account.v11</field> -->
|
||||||
<field name="type">ir.actions.act_window</field>
|
<!-- <field name="type">ir.actions.act_window</field> -->
|
||||||
<field name="res_model">account.v11</field>
|
<!-- <field name="res_model">account.v11</field> -->
|
||||||
<field name="view_type">form</field>
|
<!-- <field name="view_type">form</field> -->
|
||||||
<field name="view_mode">form,tree</field>
|
<!-- <field name="view_mode">form,tree</field> -->
|
||||||
</record>
|
<!-- </record> -->
|
||||||
|
|
||||||
<!-- defini l'entree -->
|
<!-- defini l'entree -->
|
||||||
|
|
||||||
<menuitem name="Financial Management/V11" id="menu_account_v11" action="open_view_test_form"/>
|
<!-- <menuitem name="Financial Management/V11" id="menu_account_v11" action=""/> -->
|
||||||
|
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
|
|
||||||
<wizard
|
<wizard
|
||||||
string="Import V11 data"
|
string="Import V11 data"
|
||||||
model="account.v11"
|
model="account.bank.statement"
|
||||||
name="account.v11_import"
|
name="account.v11_import"
|
||||||
id="wizard_account_v11_import"
|
id="wizard_account_v11_import"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<menuitem name="Financial Management/Import V11" action="wizard_account_v11_import" type="wizard" id="menu_account_v11" sequence="15"/>
|
||||||
|
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
Loading…
Reference in New Issue