*modified creation of account analytic move lines: the move lines are now created once the move is validated (and deleted before the validation)
*adapted invoices to the change bzr revid: qdp@tinyerp.com-20081121151745-yfqdxeyh3kbsn0yt
This commit is contained in:
parent
de263be3fb
commit
987e81ff2b
|
@ -919,6 +919,11 @@ class account_move(osv.osv):
|
|||
def validate(self, cr, uid, ids, context={}):
|
||||
ok = True
|
||||
for move in self.browse(cr, uid, ids, context):
|
||||
#unlink analytic lines on move_lines
|
||||
for obj_line in move.line_id:
|
||||
for obj in obj_line.analytic_lines:
|
||||
self.pool.get('account.analytic.line').unlink(cr,uid,obj.id)
|
||||
|
||||
journal = move.journal_id
|
||||
amount = 0
|
||||
line_ids = []
|
||||
|
@ -1026,6 +1031,24 @@ class account_move(osv.osv):
|
|||
'state': 'draft'
|
||||
}, context, check=False)
|
||||
ok = False
|
||||
if ok:
|
||||
obj_line=self.browse(cr, uid, ids[0])
|
||||
for move in self.browse(cr, uid, ids, context):
|
||||
for obj_line in move.line_id:
|
||||
#create analytic lines
|
||||
if obj_line.analytic_account_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
|
||||
}
|
||||
self.pool.get('account.analytic.line').create(cr,uid,vals_lines)
|
||||
return ok
|
||||
account_move()
|
||||
|
||||
|
|
|
@ -679,78 +679,7 @@ class account_move_line(osv.osv):
|
|||
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
|
||||
|
||||
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)
|
||||
result = super(account_move_line, self).write(cr, uid, ids, vals, context)
|
||||
|
||||
if check:
|
||||
done = []
|
||||
|
|
|
@ -611,6 +611,7 @@ class account_invoice(osv.osv):
|
|||
'tax_amount': x.get('tax_amount', False),
|
||||
'ref':x.get('ref',False),
|
||||
'quantity':x.get('quantity',1.00),
|
||||
'analytic_account_id':x.get('account_analytic_id',False),
|
||||
}
|
||||
|
||||
def action_number(self, cr, uid, ids, *args):
|
||||
|
|
Loading…
Reference in New Issue