1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ##############################################################################
33 from osv import fields, osv
34 from tools.translate import _
36 class account_move_line(osv.osv):
37 _name = "account.move.line"
38 _description = "Entry lines"
40 def _query_get(self, cr, uid, obj='l', context={}):
41 fiscalyear_obj = self.pool.get('account.fiscalyear')
42 if not context.get('fiscalyear', False):
43 fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
44 fiscalyear_clause = (','.join([str(x) for x in fiscalyear_ids])) or '0'
46 fiscalyear_clause = '%s' % context['fiscalyear']
47 state=context.get('state',False)
50 if state.lower() not in ['all']:
51 where_move_state= " AND "+obj+".move_id in (select id from account_move where account_move.state = '"+state+"')"
53 if context.get('periods', False):
54 ids = ','.join([str(x) for x in context['periods']])
55 return obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) AND id in (%s)) %s" % (fiscalyear_clause, ids,where_move_state)
57 return obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) %s)" % (fiscalyear_clause,where_move_state)
59 def default_get(self, cr, uid, fields, context={}):
60 data = self._default_get(cr, uid, fields, context)
66 def _default_get(self, cr, uid, fields, context={}):
67 # Compute simple values
68 data = super(account_move_line, self).default_get(cr, uid, fields, context)
70 if not 'move_id' in fields: #we are not in manual entry
73 period_obj = self.pool.get('account.period')
74 tax_obj=self.pool.get('account.tax')
76 # Compute the current move
79 if context.get('journal_id',False) and context.get('period_id',False):
80 if 'move_id' in fields:
81 cr.execute('select move_id \
85 journal_id=%d and period_id=%d and create_uid=%d and state=%s \
86 order by id desc limit 1',
87 (context['journal_id'], context['period_id'], uid, 'draft'))
89 move_id = (res and res[0]) or False
94 data['move_id'] = move_id
96 cr.execute('select date \
100 journal_id=%d and period_id=%d and create_uid=%d \
102 (context['journal_id'], context['period_id'], uid))
105 data['date'] = res[0]
107 period = period_obj.browse(cr, uid, context['period_id'],
109 data['date'] = period.date_start
116 move = self.pool.get('account.move').browse(cr, uid, move_id, context)
118 for l in move.line_id:
119 partner_id = partner_id or l.partner_id.id
120 ref_id = ref_id or l.ref
121 total += (l.debit or 0.0) - (l.credit or 0.0)
123 data.setdefault('name', l.name)
126 if 'partner_id' in fields:
127 data['partner_id'] = partner_id
129 if move.journal_id.type == 'purchase':
131 account = move.journal_id.default_credit_account_id
133 account = move.journal_id.default_debit_account_id
136 account = move.journal_id.default_credit_account_id
138 account = move.journal_id.default_debit_account_id
140 data['account_id'] = account.id
141 if account and account.tax_ids:
142 for tax in self.pool.get('account.tax').compute_inv(cr,uid,[account.tax_ids[0]],total,1.00):
143 total -= tax['amount']
144 data['account_tax_id'] = account.tax_ids[0].id
146 data['debit'] = s>0 and s or 0.0
147 data['credit'] = s<0 and -s or 0.0
150 def _on_create_write(self, cr, uid, id, context={}):
151 ml = self.browse(cr, uid, id, context)
152 return map(lambda x: x.id, ml.move_id.line_id)
154 def _balance(self, cr, uid, ids, prop, unknow_none, unknow_dict):
156 # TODO group the foreach in sql
158 cr.execute('SELECT date,account_id FROM account_move_line WHERE id=%d', (id,))
159 dt, acc = cr.fetchone()
160 cr.execute('SELECT SUM(debit-credit) FROM account_move_line WHERE account_id=%d AND (date<%s OR (date=%s AND id<=%d)) and active', (acc,dt,dt,id))
161 res[id] = cr.fetchone()[0]
164 def _invoice(self, cursor, user, ids, name, arg, context=None):
165 invoice_obj = self.pool.get('account.invoice')
169 cursor.execute('SELECT l.id, i.id ' \
170 'FROM account_move_line l, account_invoice i ' \
171 'WHERE l.move_id = i.move_id ' \
172 'AND l.id in (' + ','.join([str(x) for x in ids]) + ')')
174 for line_id, invoice_id in cursor.fetchall():
175 res[line_id] = invoice_id
176 invoice_ids.append(invoice_id)
177 invoice_names = {False: ''}
178 for invoice_id, name in invoice_obj.name_get(cursor, user,
179 invoice_ids, context=context):
180 invoice_names[invoice_id] = name
181 for line_id in res.keys():
182 invoice_id = res[line_id]
183 res[line_id] = (invoice_id, invoice_names[invoice_id])
186 def name_get(self, cr, uid, ids, context={}):
190 for line in self.browse(cr, uid, ids, context):
192 result.append((line.id, (line.name or '')+' ('+line.ref+')'))
194 result.append((line.id, line.name))
197 def _invoice_search(self, cursor, user, obj, name, args):
200 invoice_obj = self.pool.get('account.invoice')
204 fargs = args[i][0].split('.', 1)
206 args[i] = (frags[0], 'in', invoice_obj.search(cursor, user,
207 [(fargs[1], args[i][1], args[i][2])]))
210 if isinstance(args[i][2], basestring):
211 res_ids = invoice_obj.name_search(cursor, user, args[i][2], [],
213 args[i] = (args[i][0], 'in', [x[0] for x in res_ids])
218 if (x[2] is False) and (x[1] == '='):
219 qu1.append('(i.id IS NULL)')
220 elif (x[2] is False) and (x[1] == '<>' or x[1] == '!='):
221 qu1.append('(i.id IS NOT NULL)')
223 qu1.append('(i.id %s %s)' % (x[1], '%d'))
227 qu1.append('(i.id in (%s))' % (','.join(['%d'] * len(x[2]))))
230 qu1.append(' (False)')
232 qu1 = ' AND' + ' AND'.join(qu1)
235 cursor.execute('SELECT l.id ' \
236 'FROM account_move_line l, account_invoice i ' \
237 'WHERE l.move_id = i.move_id ' + qu1, qu2)
238 res = cursor.fetchall()
240 return [('id', '=', '0')]
241 return [('id', 'in', [x[0] for x in res])]
244 'name': fields.char('Name', size=64, required=True),
245 'quantity': fields.float('Quantity', digits=(16,2), help="The optionnal quantity expressed by this line, eg: number of product sold. The quantity is not a legal requirement but is very usefull for some reports."),
246 'debit': fields.float('Debit', digits=(16,2)),
247 'credit': fields.float('Credit', digits=(16,2)),
248 'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade", domain=[('type','<>','view'), ('type', '<>', 'closed')], select=2),
249 'move_id': fields.many2one('account.move', 'Move', ondelete="cascade", states={'valid':[('readonly',True)]}, help="The move of this entry line.", select=2),
251 'ref': fields.char('Ref.', size=32),
252 'statement_id': fields.many2one('account.bank.statement', 'Statement', help="The bank statement used for bank reconciliation", select=1),
253 'reconcile_id': fields.many2one('account.move.reconcile', 'Reconcile', readonly=True, ondelete='set null', select=2),
254 'reconcile_partial_id': fields.many2one('account.move.reconcile', 'Partial Reconcile', readonly=True, ondelete='set null', select=2),
255 'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optionnal other currency if it is a multi-currency entry."),
256 'currency_id': fields.many2one('res.currency', 'Currency', help="The optionnal other currency if it is a multi-currency entry."),
258 'period_id': fields.many2one('account.period', 'Period', required=True, select=2),
259 'journal_id': fields.many2one('account.journal', 'Journal', required=True, select=1),
260 'blocked': fields.boolean('Litigation', help="You can check this box to mark the entry line as a litigation with the associated partner"),
262 'partner_id': fields.many2one('res.partner', 'Partner Ref.'),
263 'date_maturity': fields.date('Maturity date', help="This field is used for payable and receivable entries. You can put the limit date for the payment of this entry line."),
264 'date': fields.date('Effective date', required=True),
265 'date_created': fields.date('Creation date'),
266 'analytic_lines': fields.one2many('account.analytic.line', 'move_id', 'Analytic lines'),
267 'centralisation': fields.selection([('normal','Normal'),('credit','Credit Centralisation'),('debit','Debit Centralisation')], 'Centralisation', size=6),
268 'balance': fields.function(_balance, method=True, string='Balance'),
269 'active': fields.boolean('Active'),
270 'state': fields.selection([('draft','Draft'), ('valid','Valid')], 'State', readonly=True),
271 'tax_code_id': fields.many2one('account.tax.code', 'Tax Account'),
272 'tax_amount': fields.float('Tax/Base Amount', digits=(16,2), select=True),
273 'invoice': fields.function(_invoice, method=True, string='Invoice',
274 type='many2one', relation='account.invoice', fnct_search=_invoice_search),
275 'account_tax_id':fields.many2one('account.tax', 'Tax'),
276 'analytic_account_id' : fields.many2one('account.analytic.account', 'Analytic Account'),
278 'amount_taxed':fields.float("Taxed Amount",digits=(16,2)),
281 def _get_date(self, cr, uid, context):
282 period_obj = self.pool.get('account.period')
283 dt = time.strftime('%Y-%m-%d')
284 if ('journal_id' in context) and ('period_id' in context):
285 cr.execute('select date from account_move_line ' \
286 'where journal_id=%d and period_id=%d ' \
287 'order by id desc limit 1',
288 (context['journal_id'], context['period_id']))
293 period = period_obj.browse(cr, uid, context['period_id'],
295 dt = period.date_start
298 'blocked': lambda *a: False,
299 'active': lambda *a: True,
300 'centralisation': lambda *a: 'normal',
302 'date_created': lambda *a: time.strftime('%Y-%m-%d'),
303 'state': lambda *a: 'draft',
304 'journal_id': lambda self, cr, uid, c: c.get('journal_id', False),
305 'period_id': lambda self, cr, uid, c: c.get('period_id', False),
307 _order = "date desc,id desc"
309 ('credit_debit1', 'CHECK (credit*debit=0)', 'Wrong credit or debit value in accounting entry !'),
310 ('credit_debit2', 'CHECK (credit+debit>=0)', 'Wrong credit or debit value in accounting entry !'),
313 def _auto_init(self, cr, context={}):
314 super(account_move_line, self)._auto_init(cr, context)
315 cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'account_move_line_journal_id_period_id_index\'')
316 if not cr.fetchone():
317 cr.execute('CREATE INDEX account_move_line_journal_id_period_id_index ON account_move_line (journal_id, period_id)')
320 def _check_no_view(self, cr, uid, ids):
321 lines = self.browse(cr, uid, ids)
323 if l.account_id.type == 'view':
327 def _check_no_closed(self, cr, uid, ids):
328 lines = self.browse(cr, uid, ids)
330 if l.account_id.type == 'closed':
335 (_check_no_view, 'You can not create move line on view account.', ['account_id']),
336 (_check_no_closed, 'You can not create move line on closed account.', ['account_id']),
339 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
341 def onchange_partner_id(self, cr, uid, ids, move_id, partner_id, account_id=None, debit=0, credit=0, journal=False):
342 if (not partner_id) or account_id:
344 part = self.pool.get('res.partner').browse(cr, uid, partner_id)
345 id1 = part.property_account_payable.id
346 id2 = part.property_account_receivable.id
349 jt = self.pool.get('account.journal').browse(cr, uid, journal).type
351 val['account_id'] = id2
353 val['account_id'] = id1
354 # Compute Maturity Date in val !
358 # type: the type if reconciliation (no logic behind this field, for info)
360 # writeoff; entry generated for the difference between the lines
363 def reconcile_partial(self, cr, uid, ids, type='auto', context={}):
368 for line in self.browse(cr, uid, ids, context):
369 if line.reconcile_id:
370 raise _('Already Reconciled')
371 if line.reconcile_partial_id:
372 for line2 in line.reconcile_partial_id.line_partial_ids:
373 if not line2.reconcile_id:
374 merges.append(line2.id)
375 total += (line2.debit or 0.0) - (line2.credit or 0.0)
376 merges_rec.append(line.reconcile_partial_id.id)
378 unmerge.append(line.id)
379 total += (line.debit or 0.0) - (line.credit or 0.0)
381 return self.reconcile(cr, uid, merges+unmerge, context=context)
382 r_id = self.pool.get('account.move.reconcile').create(cr, uid, {
384 'line_partial_ids': map(lambda x: (4,x,False), merges+unmerge)
386 self.pool.get('account.move.reconcile').reconcile_partial_check(cr, uid, [r_id] + merges_rec, context=context)
389 def reconcile(self, cr, uid, ids, type='auto', writeoff_acc_id=False, writeoff_period_id=False, writeoff_journal_id=False, context={}):
390 id_set = ','.join(map(str, ids))
391 lines = self.browse(cr, uid, ids, context=context)
392 unrec_lines = filter(lambda x: not x['reconcile_id'], lines)
397 for line in unrec_lines:
398 if line.state <> 'valid':
399 raise osv.except_osv(_('Error'),
400 _('Entry "%s" is not valid !') % line.name)
401 credit += line['credit']
402 debit += line['debit']
403 currency += line['amount_currency'] or 0.0
404 account_id = line['account_id']['id']
405 partner_id = (line['partner_id'] and line['partner_id']['id']) or False
406 writeoff = debit - credit
407 date = time.strftime('%Y-%m-%d')
409 cr.execute('SELECT account_id, reconcile_id \
410 FROM account_move_line \
411 WHERE id IN ('+id_set+') \
412 GROUP BY account_id,reconcile_id')
414 #TODO: move this check to a constraint in the account_move_reconcile object
416 raise osv.except_osv(_('Error'), _('Entries are not of the same account or already reconciled ! '))
417 account = self.pool.get('account.account').browse(cr, uid, account_id, context=context)
418 if not account.reconcile:
419 raise osv.except_osv(_('Error'), _('The account is not defined to be reconcile !'))
421 raise osv.except_osv(_('Error'), _('Some entries are already reconciled !'))
423 if (not self.pool.get('res.currency').is_zero(cr, uid, account.company_id.currency_id, writeoff)) or \
424 (account.currency_id and (not self.pool.get('res.currency').is_zero(cr, uid, account.currency_id, currency))):
425 if not writeoff_acc_id:
426 raise osv.except_osv(_('Warning'), _('You have to provide an account for the write off entry !'))
430 self_credit = writeoff
436 self_debit = -writeoff
442 'credit':self_credit,
443 'account_id':account_id,
445 'partner_id':partner_id,
446 'currency_id': account.currency_id.id or False,
447 'amount_currency': account.currency_id.id and -currency or 0.0
453 'account_id':writeoff_acc_id,
455 'partner_id':partner_id
460 if writeoff_journal_id:
461 journal = self.pool.get('account.journal').browse(cr, uid, writeoff_journal_id)
462 if journal.sequence_id:
463 name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
465 writeoff_move_id = self.pool.get('account.move').create(cr, uid, {
467 'period_id': writeoff_period_id,
468 'journal_id': writeoff_journal_id,
471 'line_id': writeoff_lines
474 writeoff_line_ids = self.search(cr, uid, [('move_id', '=', writeoff_move_id), ('account_id', '=', account_id)])
475 ids += writeoff_line_ids
477 r_id = self.pool.get('account.move.reconcile').create(cr, uid, {
480 'line_id': map(lambda x: (4,x,False), ids),
481 'line_partial_ids': map(lambda x: (3,x,False), ids)
483 # the id of the move.reconcile is written in the move.line (self) by the create method above
484 # because of the way the line_id are defined: (4, x, False)
485 wf_service = netsvc.LocalService("workflow")
487 wf_service.trg_trigger(uid, 'account.move.line', id, cr)
490 def view_header_get(self, cr, user, view_id, view_type, context):
491 if (not context.get('journal_id', False)) or (not context.get('period_id', False)):
493 cr.execute('select code from account_journal where id=%d', (context['journal_id'],))
494 j = cr.fetchone()[0] or ''
495 cr.execute('select code from account_period where id=%d', (context['period_id'],))
496 p = cr.fetchone()[0] or ''
501 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False):
502 result = super(osv.osv, self).fields_view_get(cr, uid, view_id,view_type,context)
503 if view_type=='tree' and 'journal_id' in context:
504 title = self.view_header_get(cr, uid, view_id, view_type, context)
505 journal = self.pool.get('account.journal').browse(cr, uid, context['journal_id'])
507 # if the journal view has a state field, color lines depending on
510 for field in journal.view_id.columns_id:
511 if field.field=='state':
512 state = ' colors="red:state==\'draft\'"'
514 #xml = '''<?xml version="1.0"?>\n<tree string="%s" editable="top" refresh="5"%s>\n\t''' % (title, state)
515 xml = '''<?xml version="1.0"?>\n<tree string="%s" editable="top" refresh="5" on_write="_on_create_write"%s>\n\t''' % (title, state)
525 for field in journal.view_id.columns_id:
526 fields.append(field.field)
528 if field.field=='debit':
529 attrs.append('sum="Total debit"')
530 elif field.field=='credit':
531 attrs.append('sum="Total credit"')
532 elif field.field=='account_id' and journal.id:
533 attrs.append('domain="[(\'journal_id\', \'=\', '+str(journal.id)+'),(\'type\',\'<>\',\'view\'), (\'type\',\'<>\',\'closed\')]"')
535 attrs.append('readonly="1"')
537 attrs.append('required="1"')
539 attrs.append('required="0"')
540 if field.field == 'partner_id':
541 attrs.append('on_change="onchange_partner_id(move_id,partner_id,account_id,debit,credit,((\'journal_id\' in context) and context[\'journal_id\']) or {})"')
542 if field.field in widths:
543 attrs.append('width="'+str(widths[field.field])+'"')
544 xml += '''<field name="%s" %s/>\n''' % (field.field,' '.join(attrs))
548 result['fields'] = self.fields_get(cr, uid, fields, context)
551 def unlink(self, cr, uid, ids, context={}, check=True):
552 self._update_check(cr, uid, ids, context)
554 for line in self.browse(cr, uid, ids, context):
555 context['journal_id']=line.journal_id.id
556 context['period_id']=line.period_id.id
557 result = super(account_move_line, self).unlink(cr, uid, [line.id], context=context)
559 self.pool.get('account.move').validate(cr, uid, [line.move_id.id], context=context)
562 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
566 account_obj = self.pool.get('account.account')
567 acc=account_obj.browse(cr,uid,ids)[0]
569 if ('debit' in vals and 'credit' in vals) and not vals['debit'] and not vals['credit']:
571 if ('debit' in vals and 'credit' not in vals) and not vals['debit'] and not acc.credit:
573 if ('credit' in vals and 'debit' not in vals) and not vals['credit'] and not acc.debit:
577 raise osv.except_osv(_('Wrong Accounting Entry!'), _('Both Credit and Debit cannot be zero!'))
579 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
580 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
582 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):
583 self._update_check(cr, uid, ids, context)
584 result = super(osv.osv, self).write(cr, uid, ids, vals, context)
587 for line in self.browse(cr, uid, ids):
588 if line.move_id.id not in done:
589 done.append(line.move_id.id)
590 self.pool.get('account.move').validate(cr, uid, [line.move_id.id], context)
593 def _update_journal_check(self, cr, uid, journal_id, period_id, context={}):
594 cr.execute('select state from account_journal_period where journal_id=%d and period_id=%d', (journal_id, period_id))
595 result = cr.fetchall()
596 for (state,) in result:
598 raise osv.except_osv(_('Error !'), _('You can not add/modify entries in a closed journal.'))
600 journal = self.pool.get('account.journal').browse(cr, uid, journal_id, context)
601 period = self.pool.get('account.period').browse(cr, uid, period_id, context)
602 self.pool.get('account.journal.period').create(cr, uid, {
603 'name': (journal.code or journal.name)+':'+(period.name or ''),
604 'journal_id': journal.id,
605 'period_id': period.id
609 def _update_check(self, cr, uid, ids, context={}):
611 for line in self.browse(cr, uid, ids, context):
612 if line.move_id.state<>'draft':
613 raise osv.except_osv(_('Error !'), _('You can not do this modification on a confirmed entry ! Please note that you can just change some non important fields !'))
614 if line.reconcile_id:
615 raise osv.except_osv(_('Error !'), _('You can not do this modification on a reconciled entry ! Please note that you can just change some non important fields !'))
616 t = (line.journal_id.id, line.period_id.id)
618 self._update_journal_check(cr, uid, line.journal_id.id, line.period_id.id, context)
622 def create(self, cr, uid, vals, context=None, check=True):
626 account_obj = self.pool.get('account.account')
627 tax_obj=self.pool.get('account.tax')
629 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
630 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
631 if 'journal_id' in vals and 'journal_id' not in context:
632 context['journal_id'] = vals['journal_id']
633 if 'period_id' in vals and 'period_id' not in context:
634 context['period_id'] = vals['period_id']
635 if 'journal_id' not in context and 'move_id' in vals:
636 m = self.pool.get('account.move').browse(cr, uid, vals['move_id'])
637 context['journal_id'] = m.journal_id.id
638 context['period_id'] = m.period_id.id
640 self._update_journal_check(cr, uid, context['journal_id'], context['period_id'], context)
642 move_id = vals.get('move_id', False)
643 journal = self.pool.get('account.journal').browse(cr, uid, context['journal_id'])
645 if journal.centralisation:
646 # use the first move ever created for this journal and period
647 cr.execute('select id, state, name from account_move where journal_id=%d and period_id=%d order by id limit 1', (context['journal_id'],context['period_id']))
650 if res[1] != 'draft':
651 raise osv.except_osv(_('UserError'),
652 _('The account move (%s) for centralisation ' \
653 'has been confirmed!') % res[2])
654 vals['move_id'] = res[0]
656 if not vals.get('move_id', False):
657 if journal.sequence_id:
658 name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
661 'period_id': context['period_id'],
662 'journal_id': context['journal_id']
664 move_id = self.pool.get('account.move').create(cr, uid, v, context)
665 vals['move_id'] = move_id
667 raise osv.except_osv(_('No piece number !'), _('Can not create an automatic sequence for this piece !\n\nPut a sequence in the journal definition for automatic numbering or create a sequence manually for this piece.'))
669 ok = not (journal.type_control_ids or journal.account_control_ids)
670 if ('account_id' in vals):
671 account = account_obj.browse(cr, uid, vals['account_id'])
672 if journal.type_control_ids:
674 for t in journal.type_control_ids:
678 if journal.account_control_ids and not ok:
679 for a in journal.account_control_ids:
680 if a.id==vals['account_id']:
683 if (account.currency_id) and 'amount_currency' not in vals:
684 vals['currency_id'] = account.currency_id.id
685 cur_obj = self.pool.get('res.currency')
688 ctx['date'] = vals['date']
689 vals['amount_currency'] = cur_obj.compute(cr, uid, account.company_id.currency_id.id, account.currency_id.id, vals.get('debit', 0.0)-vals.get('credit', 0.0), context=ctx)
691 raise osv.except_osv(_('Bad account !'), _('You can not use this general account in this journal !'))
693 result = super(osv.osv, self).create(cr, uid, vals, context)
694 if 'analytic_account_id' in vals and vals['analytic_account_id']:
695 if journal.analytic_journal_id:
696 vals['analytic_lines'] = [(0,0, {
697 'name': vals['name'],
698 'date': vals['date'],
699 'account_id': vals['analytic_account_id'],
700 'unit_amount': vals['quantity'],
701 'amount': vals['debit'] or vals['credit'],
702 'general_account_id': vals['account_id'],
703 'journal_id': journal.analytic_journal_id.id,
708 if 'account_tax_id' in vals and vals['account_tax_id']:
709 tax_id=tax_obj.browse(cr,uid,vals['account_tax_id'])
710 total = vals['credit'] or (-vals['debit'])
711 for tax in tax_obj.compute(cr,uid,[tax_id],total,1.00):
712 print 'Processing Tax', tax
713 self.write(cr, uid,[result], {
714 'tax_code_id': tax['base_code_id'],
715 'tax_amount': tax['base_sign'] * total
718 'move_id': vals['move_id'],
719 'journal_id': vals['journal_id'],
720 'period_id': vals['period_id'],
721 'name': vals['name']+' '+tax['name'],
722 'date': vals['date'],
723 'partner_id': vals.get('partner_id',False),
724 'ref': vals.get('ref',False),
725 'account_tax_id': False,
726 'tax_code_id': tax['tax_code_id'],
727 'tax_amount': tax['tax_sign'] * tax['amount'],
728 'account_id': tax['account_paid_id'], # or collected ?
729 'credit': tax['amount']>0 and tax['amount'] or 0.0,
730 'debit': tax['amount']<0 and -tax['amount'] or 0.0,
733 self.create(cr, uid, data, context)
735 self.pool.get('account.move').validate(cr, uid, [vals['move_id']], context)
740 class account_bank_statement_reconcile(osv.osv):
741 _inherit = "account.bank.statement.reconcile"
743 'line_ids': fields.many2many('account.move.line', 'account_bank_statement_line_rel', 'statement_id', 'line_id', 'Entries'),
745 account_bank_statement_reconcile()
747 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: