[FIX][IMP] account,account_code: fixed the coda import wizard problem and improved the account cash statement code.

bzr revid: vra@tinyerp.com-20100928100311-xo4tl35t747foan3
This commit is contained in:
vra 2010-09-28 15:33:11 +05:30
parent 3569fc7229
commit dabbd0dffa
3 changed files with 80 additions and 74 deletions

View File

@ -192,15 +192,18 @@ class account_cash_statement(osv.osv):
res.append(dct)
return res
def _get_cash_close_box_lines(self, cr, ids, uid, context={}):
res = []
curr = [1, 2, 5, 10, 20, 50, 100, 500]
for rs in curr:
dct = {
'pieces':rs,
'number':0
}
res.append((0,0,dct))
def _get_cash_open_close_box_lines(self, cr, uid, context={}):
res = {}
start_l = []
end_l = []
starting_details = self._get_cash_open_box_lines(cr, uid, context)
ending_details = self._get_default_cash_close_box_lines(cr, uid, context)
for start in starting_details:
start_l.append((0,0,start))
for end in ending_details:
end_l.append((0,0,end))
res['start'] = start_l
res['end'] = end_l
return res
_columns = {
@ -234,11 +237,12 @@ class account_cash_statement(osv.osv):
open_jrnl = self.search(cr, uid, sql)
if open_jrnl:
raise osv.except_osv('Error', _('You can not have two open register for the same journal'))
if self.pool.get('account.journal').browse(cr, uid, vals['journal_id']).type == 'cash':
lines = end_lines = self._get_cash_close_box_lines(cr, uid, [], context)
open_close = self._get_cash_open_close_box_lines(cr, uid, context)
vals.update({
'ending_details_ids':lines
'ending_details_ids':open_close['start'],
'starting_details_ids':open_close['end']
})
else:
vals.update({

View File

@ -48,7 +48,7 @@ class account_coda_import(osv.osv_memory):
'journal_id': fields.many2one('account.journal', 'Bank Journal', required=True),
'def_payable': fields.many2one('account.account', 'Default Payable Account', domain=[('type', '=', 'payable')], required=True, help= 'Set here the payable account that will be used, by default, if the partner is not found'),
'def_receivable': fields.many2one('account.account', 'Default Receivable Account', domain=[('type', '=', 'receivable')], required=True, help= 'Set here the receivable account that will be used, by default, if the partner is not found',),
'awaiting_account': fields.many2one('account.account', 'Default Account for Unrecognized Movement', required=True, help= 'Set here the default account that will be used, if the partner is found but does not have the bank account , or if he is domiciled',),
'awaiting_account': fields.many2one('account.account', 'Default Account for Unrecognized Movement', domain=[('type', '=', 'liquidity')], required=True, help= 'Set here the default account that will be used, if the partner is found but does not have the bank account , or if he is domiciled'),
'coda': fields.binary('Coda File', required=True),
'note':fields.text('Log'),
}
@ -195,59 +195,60 @@ class account_coda_import(osv.osv_memory):
for statement in bank_statements:
try:
bk_st_id =bank_statement_obj.create(cr, uid, {
'journal_id': statement['journal_id'],
'date': time.strftime('%Y-%m-%d', time.strptime(statement['date'], "%y/%m/%d")),
'period_id': statement['period_id'] or period,
'balance_start': statement["balance_start"],
'balance_end_real': statement["balance_end_real"],
'journal_id': statement.get('journal_id',False),
'date': time.strftime('%Y-%m-%d', time.strptime(statement.get('date',time.strftime('%Y-%m-%d')), "%y/%m/%d")),
'period_id': statement.get('period_id',False) or period,
'balance_start': statement.get('balance_start',False),
'balance_end_real': statement.get('balance_end_real',False),
'state': 'draft',
'name': statement['name'],
'name': statement.get('name',False),
})
lines = statement["bank_statement_line"]
for value in lines:
line = lines[value]
voucher_id = False
if line['toreconcile']: # Fix me
name = line['name'][:3] + '/' + line['name'][3:7] + '/' + line['name'][7:]
rec_id = pool.get('account.move.line').search(cr, uid, [('name', '=', name), ('reconcile_id', '=', False), ('account_id.reconcile', '=', True)])
if rec_id:
voucher_res = { 'type':(line['amount'] < 0 and 'payment' or 'receipt') ,
'name': line['name'],#line.name,
'partner_id': line['partner_id'] ,#line.partner_id.id,
'journal_id': statement['journal_id'], #statement.journal_id.id,
'account_id': line['account_id'],#line.account_id.id,
'company_id': statement['company_id'],#statement.company_id.id,
'currency_id': statement['currency'],#statement.currency.id,
'date': line['date'], #line.date,
'amount':abs(line['amount']),
'period_id':statement['period_id'] or period,# statement.period_id.id
}
voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context)
result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype=(amount < 0 and 'payment' or 'receipt'))
voucher_line_dict = False
if result['value']['line_ids']:
for line_dict in result['value']['line_ids']:
move_line = line_obj.browse(cr, uid, line_dict['move_line_id'], context)
if line.move_id.id == move_line.move_id.id:
voucher_line_dict = line_dict
if voucher_line_dict:
voucher_line_dict.update({'voucher_id':voucher_id})
voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)
# reconcile_id = statement_reconcile_obj.create(cr, uid, {
# 'line_ids': [(6, 0, rec_id)]
# }, context=context)
#
mv = pool.get('account.move.line').browse(cr, uid, rec_id[0], context=context)
if mv.partner_id:
line['partner_id'] = mv.partner_id.id
if line['amount'] < 0 :
line['account_id'] = mv.partner_id.property_account_payable.id
else :
line['account_id'] = mv.partner_id.property_account_receivable.id
lines = statement.get('bank_statement_line',False)
if lines:
for value in lines:
line = lines[value]
voucher_id = False
if line.get('toreconcile',False): # Fix me
name = line['name'][:3] + '/' + line['name'][3:7] + '/' + line['name'][7:]
rec_id = self.pool.get('account.move.line').search(cr, uid, [('name', '=', name), ('reconcile_id', '=', False), ('account_id.reconcile', '=', True)])
if rec_id:
voucher_res = { 'type':(line['amount'] < 0 and 'payment' or 'receipt') ,
'name': line['name'],#line.name,
'partner_id': line['partner_id'] ,#line.partner_id.id,
'journal_id': statement['journal_id'], #statement.journal_id.id,
'account_id': line['account_id'],#line.account_id.id,
'company_id': statement['company_id'],#statement.company_id.id,
'currency_id': statement['currency'],#statement.currency.id,
'date': line['date'], #line.date,
'amount':abs(line['amount']),
'period_id':statement.get('period_id',False) or period,# statement.period_id.id
}
voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context)
result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype=(amount < 0 and 'payment' or 'receipt'))
voucher_line_dict = False
if result['value']['line_ids']:
for line_dict in result['value']['line_ids']:
move_line = line_obj.browse(cr, uid, line_dict['move_line_id'], context)
if line.move_id.id == move_line.move_id.id:
voucher_line_dict = line_dict
if voucher_line_dict:
voucher_line_dict.update({'voucher_id':voucher_id})
voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)
# reconcile_id = statement_reconcile_obj.create(cr, uid, {
# 'line_ids': [(6, 0, rec_id)]
# }, context=context)
#
mv = pool.get('account.move.line').browse(cr, uid, rec_id[0], context=context)
if mv.partner_id:
line['partner_id'] = mv.partner_id.id
if line['amount'] < 0 :
line['account_id'] = mv.partner_id.property_account_payable.id
else :
line['account_id'] = mv.partner_id.property_account_receivable.id
str_not1 = ''
if line.has_key('contry_name') and line.has_key('cntry_number'):
str_not1="Partner name:%s \n Partner Account Number:%s \n Communication:%s \n Value Date:%s \n Entry Date:%s \n"%(line["contry_name"], line["cntry_number"], line["free_comm"]+line['extra_note'], line["val_date"][0], line["entry_date"][0])

View File

@ -7,19 +7,20 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Import Coda Statement">
<separator colspan="4" string="Configure Your Journal and Account :" />
<field name="journal_id" colspan="1" domain="[('type','=','cash')]" />
<newline />
<field name="def_payable" />
<newline />
<field name="def_receivable" />
<newline />
<field name="awaiting_account" />
<separator string="Configure Your Journal and Account :"/>
<newline/>
<group colspan="4">
<field name="def_receivable" />
<field name="def_payable" />
<field name="journal_id" domain="[('type','=','cash')]" />
<field name="awaiting_account" />
</group>
<newline/>
<separator string="Click on 'New' to select your file :" colspan="4"/>
<field name="coda"/>
<newline/>
<group colspan="4" col="6">
<separator colspan="6"/>
<separator colspan="4"/>
<group colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="coda_parsing" string="Import" type="object" icon="gtk-ok"/>
</group>