bug-fix for the account voucher

create an analytic entry when voicher entry created

bzr revid: mga@mga-laptop-20081024115748-s75ewnn2yxw213jh
This commit is contained in:
Mantavya Gajjar
2008-10-24 17:27:48 +05:30
parent b541df5ba9
commit 4c8838b8ff
2 changed files with 19 additions and 18 deletions
+15 -15
View File
@@ -8,7 +8,6 @@ from mx.DateTime import RelativeDateTime
from tools import config
class account_voucher(osv.osv):
def _get_period(self, cr, uid, context):
periods = self.pool.get('account.period').find(cr, uid)
@@ -24,10 +23,8 @@ class account_voucher(osv.osv):
def _get_reference_type(self, cursor, user, context=None):
return [('none', 'Free Reference')]
def _get_journal(self, cr, uid, context):
type_inv = context.get('type', 'rec_voucher')
type_inv = context #.get('type', 'rec_voucher')
type2journal = {'rec_voucher': 'cash', 'bank_rec_voucher': 'cash','pay_voucher': 'cash','bank_pay_voucher': 'cash', 'cont_voucher': 'cash','journal_sale_voucher': 'sale','journal_pur_voucher': 'purchase' }
journal_obj = self.pool.get('account.journal')
res = journal_obj.search(cr, uid, [('type', '=', type2journal.get(type_inv, 'cash'))], limit=1)
@@ -72,8 +69,7 @@ class account_voucher(osv.osv):
('cancel','Cancel')
], 'State',
readonly=True),
'amount':fields.float('Amount', readonly=True),
# , states={'draft':[('readonly',False)]}
'amount':fields.float('Amount'),
'number':fields.char('Number', size=32, readonly=True),
'reference': fields.char('Voucher Reference', size=64),
'reference_type': fields.selection(_get_reference_type, 'Reference Type',
@@ -147,11 +143,13 @@ class account_voucher(osv.osv):
self.write(cr,uid,ids,{'amount':total})
self.write(cr, uid, ids, {'state':'proforma'})
return True
def proforma_voucher(self, cr, uid, ids, context={}):
self.action_move_line_create(cr, uid, ids)
self.action_number(cr, uid, ids)
self.write(cr, uid, ids, {'state':'posted'})
return True
def cancel_voucher(self,cr,uid,ids,context={}):
self.action_cancel(cr, uid, ids)
self.write(cr, uid, ids, {'state':'cancel'})
@@ -192,12 +190,13 @@ class account_voucher(osv.osv):
ref = inv.reference
else:
ref = self._convert_ref(cr, uid, inv.number)
il['analytic_lines'] = [(0,0, {
'name': il['name'],
'date': inv['date'],
'account_id': il['account_analytic_id'],
'amount': inv['amount'] * sign,
'partner_id': il['partner_id'] or False,
#'partner_id': il['partner_id'] or False,
'general_account_id': il['account_id'] or False,
'journal_id': self._get_journal(cr, uid, inv.type),
'ref': ref,
@@ -206,10 +205,14 @@ class account_voucher(osv.osv):
return iml
def action_move_line_create(self, cr, uid, ids, *args):
for inv in self.browse(cr, uid, ids):
if inv.move_id:
continue
company_currency = inv.company_id.currency_id.id
# create the analytical lines
line_ids = self.read(cr, uid, [inv.id], ['payment_ids'])[0]['payment_ids']
ils = self.pool.get('account.voucher.line').read(cr, uid, line_ids)
@@ -256,13 +259,12 @@ class account_voucher(osv.osv):
'currency_id': diff_currency_p \
and inv.currency_id.id or False,
'ref': ref
})
})
date = inv.date
inv.amount=total
line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x,date, context={})) ,iml)
line = map(lambda x:(0, 0, self.line_get_convert(cr, uid, x,date, context={})), iml)
journal_id = inv.journal_id.id #self._get_journal(cr, uid, {'type': inv['type']})
journal = self.pool.get('account.journal').browse(cr, uid, journal_id)
@@ -270,6 +272,7 @@ class account_voucher(osv.osv):
name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
move = {'name': name, 'line_id': line, 'journal_id': journal_id}
if inv.period_id:
move['period_id'] = inv.period_id.id
for i in line:
@@ -280,12 +283,9 @@ class account_voucher(osv.osv):
obj=self.pool.get('account.move').browse(cr,uid,move_id)
for line in obj.line_id :
cr.execute('insert into voucher_id (account_id,rel_account_move) values (%d, %d)',(int(ids[0]),int(line.id)))
# self.pool.get('account.move').post(cr, uid, [move_id])
# self._log_event(cr, uid, ids)
return True
return True
def line_get_convert(self, cr, uid, x, date, context={}):
return {
'date':date,
+4 -3
View File
@@ -30,13 +30,14 @@
<field name="name" select="1"/>
<field name="journal_id" select="1" on_change="onchange_journal(journal_id,type)"/>
<field name="account_id" select="2" on_change="onchange_account(account_id)"/>
<field name="amount" select="1" required="1"/>
<field name="amount" select="1"/>
<newline/>
<field name="payment_ids" colspan="4" nolabel="1">
<tree string="Voucher Lines" editable="top">
<field name="account_analytic_id"/>
<field name="partner_id" on_change="onchange_partner(partner_id,type,parent.type)"/>
<field name="account_id" groups="base.group_system"/>
<field name="name" groups="base.group_system"/>
<field name="account_id"/>
<field name="name"/>
<field name="ref"/>
<field name="amount"/>
<field name="type"/>