Bugfix:Created analytic lines on creation and modification of account move line.
bzr revid: jvo@tinyerp.com-20081118105151-ompt3emkv393lc47
This commit is contained in:
parent
90b6097fb8
commit
df2f894eef
|
@ -676,7 +676,83 @@ class account_move_line(osv.osv):
|
|||
if update_check:
|
||||
if ('account_id' in vals) or ('journal_id' in vals) or ('period_id' in vals) or ('move_id' in vals) or ('debit' in vals) or ('credit' in vals) or ('date' in vals):
|
||||
self._update_check(cr, uid, ids, context)
|
||||
|
||||
obj_line=self.browse(cr, uid, ids[0])
|
||||
lines={}
|
||||
|
||||
obj_analytic_line=self.pool.get('account.analytic.line')
|
||||
analytic=True
|
||||
journal_flag=False
|
||||
del_line=False
|
||||
|
||||
if ('journal_id' in vals):
|
||||
journal=self.pool.get('account.journal').browse(cr,uid,vals['journal_id'])
|
||||
journal_flag=True
|
||||
if not journal.analytic_journal_id:
|
||||
del_line=True
|
||||
|
||||
if ('analytic_account_id' in vals) and (not vals['analytic_account_id']):
|
||||
del_line=True
|
||||
|
||||
if del_line:
|
||||
for obj in obj_line.analytic_lines:
|
||||
obj_analytic_line.unlink(cr,uid,obj.id)
|
||||
analytic=False
|
||||
|
||||
if obj_line.analytic_lines:
|
||||
mode='write'
|
||||
else:
|
||||
mode='create'
|
||||
|
||||
if obj_line.analytic_lines and analytic:
|
||||
if ('analytic_account_id' in vals):
|
||||
lines['account_id'] = vals['analytic_account_id']
|
||||
|
||||
if ('account_id' in vals):
|
||||
lines['general_account_id'] = vals['account_id']
|
||||
|
||||
if ('name' in vals):
|
||||
lines['name'] = vals['name']
|
||||
|
||||
if ('date' in vals):
|
||||
lines['date'] = vals['date']
|
||||
|
||||
if ('ref' in vals and vals['ref']):
|
||||
lines['ref'] = vals['ref']
|
||||
|
||||
if ('quantity' in vals and vals['quantity']):
|
||||
lines['unit_amount'] = vals['quantity']
|
||||
|
||||
if ('credit' in vals and vals['credit']):
|
||||
lines['amount'] = vals['credit']
|
||||
|
||||
if ('debit' in vals and vals['debit']):
|
||||
lines['amount'] = vals['debit']
|
||||
|
||||
if journal_flag:
|
||||
lines['journal_id']=journal.analytic_journal_id.id
|
||||
|
||||
if lines:
|
||||
if mode=='write':
|
||||
obj_analytic_line.write(cr,uid,obj_line.analytic_lines[0].id,lines,context)
|
||||
|
||||
result = super(osv.osv, self).write(cr, uid, ids, vals, context)
|
||||
|
||||
if mode=='create' and analytic and obj_line.analytic_account_id:
|
||||
if obj_line.journal_id.analytic_journal_id:
|
||||
vals_lines={
|
||||
'name': obj_line.name,
|
||||
'date': obj_line.date,
|
||||
'account_id': obj_line.analytic_account_id.id,
|
||||
'unit_amount':obj_line.quantity,
|
||||
'amount': obj_line.debit or obj_line.credit,
|
||||
'general_account_id': obj_line.account_id.id,
|
||||
'journal_id': obj_line.journal_id.analytic_journal_id.id,
|
||||
'ref': obj_line.ref,
|
||||
'move_id':obj_line.id
|
||||
}
|
||||
obj_analytic_line.create(cr,uid,vals_lines)
|
||||
|
||||
if check:
|
||||
done = []
|
||||
for line in self.browse(cr, uid, ids):
|
||||
|
@ -786,20 +862,20 @@ class account_move_line(osv.osv):
|
|||
if not ok:
|
||||
raise osv.except_osv(_('Bad account !'), _('You can not use this general account in this journal !'))
|
||||
|
||||
result = super(osv.osv, self).create(cr, uid, vals, context)
|
||||
# result = super(osv.osv, self).create(cr, uid, vals, context)
|
||||
if 'analytic_account_id' in vals and vals['analytic_account_id']:
|
||||
if journal.analytic_journal_id:
|
||||
vals['analytic_lines'] = [(0,0, {
|
||||
'name': vals['name'],
|
||||
'date': vals['date'],
|
||||
'account_id': vals['analytic_account_id'],
|
||||
'unit_amount': vals['quantity'],
|
||||
'unit_amount':'quantity' in vals and vals['quantity'] or 1.0,
|
||||
'amount': vals['debit'] or vals['credit'],
|
||||
'general_account_id': vals['account_id'],
|
||||
'journal_id': journal.analytic_journal_id.id,
|
||||
'ref': vals['ref'],
|
||||
})]
|
||||
|
||||
result = super(osv.osv, self).create(cr, uid, vals, context)
|
||||
# CREATE Taxes
|
||||
if 'account_tax_id' in vals and vals['account_tax_id']:
|
||||
tax_id=tax_obj.browse(cr,uid,vals['account_tax_id'])
|
||||
|
|
Loading…
Reference in New Issue