diff --git a/addons/account/account.py b/addons/account/account.py index 99e3bb9ee68..59c4b2acf9b 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1095,7 +1095,7 @@ class account_tax(osv.osv): 'ref_tax_sign': fields.float('Tax Code Sign', help="Usualy 1 or -1."), 'include_base_amount': fields.boolean('Include in base amount', help="Indicate if the amount of tax must be included in the base amount for the computation of the next taxes"), 'company_id': fields.many2one('res.company', 'Company', required=True), - 'description': fields.char('Internal Name', 32), + 'description': fields.char('Internal Name',size=32), } def name_get(self, cr, uid, ids, context={}): diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index a5ede47259c..1ee414e6b74 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -49,9 +49,9 @@ class account_move_line(osv.osv): if state: if state.lower() not in ['all']: where_move_state= " AND "+obj+".move_id in (select id from account_move where account_move.state = '"+state+"')" - + if context.get('periods', False): - ids = ','.join([str(x) for x in context['periods']]) + ids = ','.join([str(x) for x in context['periods']]) 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) else: 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) @@ -71,6 +71,7 @@ class account_move_line(osv.osv): return data period_obj = self.pool.get('account.period') + tax_obj=self.pool.get('account.tax') # Compute the current move move_id = False @@ -86,6 +87,7 @@ class account_move_line(osv.osv): (context['journal_id'], context['period_id'], uid, 'draft')) res = cr.fetchone() move_id = (res and res[0]) or False + if not move_id: return data else: @@ -111,102 +113,39 @@ class account_move_line(osv.osv): total = 0 ref_id = False - taxes = {} move = self.pool.get('account.move').browse(cr, uid, move_id, context) + for l in move.line_id: partner_id = partner_id or l.partner_id.id ref_id = ref_id or l.ref - total += (l.debit - l.credit) - for tax in l.account_id.tax_ids: - if move.journal_id.type == 'sale': - if l.debit: - code = tax.ref_tax_code_id.id - acc = tax.account_paid_id.id - else: - code = tax.tax_code_id.id - acc = tax.account_collected_id.id - else: - if l.debit: - code = tax.tax_code_id.id - acc = tax.account_collected_id.id - else: - code = tax.ref_tax_code_id.id - acc = tax.account_paid_id.id - taxes.setdefault((acc, code), False) - taxes[(l.account_id.id, l.tax_code_id.id)] = True + total += (l.debit or 0.0) - (l.credit or 0.0) if 'name' in fields: - data.setdefault('name', l.name) - + data.setdefault('name', l.name) if 'ref' in fields: data['ref'] = ref_id if 'partner_id' in fields: data['partner_id'] = partner_id - if move.journal_id.type in ('purchase', 'sale'): - for t in taxes: - if not taxes[t] and t[0]: - s = 0 - tax_amount = 0 - for l in move.line_id: - if move.journal_id.type == 'sale': - if l.debit: - field_base = 'ref_' - key = 'account_paid_id' - else: - field_base = '' - key = 'account_collected_id' - else: - if l.debit: - field_base = '' - key = 'account_collected_id' - else: - field_base = 'ref_' - key = 'account_paid_id' - for tax in self.pool.get('account.tax').compute(cr, uid, - l.account_id.tax_ids, l.debit or l.credit, 1, False): - if (tax[key] == t[0]) \ - and (tax[field_base + 'tax_code_id'] == t[1]): - if l.debit: - s += tax['amount'] - else: - s -= tax['amount'] - tax_amount += tax['amount'] * \ - tax[field_base + 'tax_sign'] - if ('debit' in fields) or ('credit' in fields): - data['debit'] = s>0 and s or 0.0 - data['credit'] = s<0 and -s or 0.0 - - if 'tax_code_id' in fields: - data['tax_code_id'] = t[1] - if 'account_id' in fields: - data['account_id'] = t[0] - if 'tax_amount' in fields: - data['tax_amount'] = tax_amount - # - # Compute line for tax T - # - return data - - # - # Compute latest line - # - if ('debit' in fields) or ('credit' in fields): - data['credit'] = total>0 and total - data['debit'] = total<0 and -total - if 'account_id' in fields: - if total >= 0: - data['account_id'] = move.journal_id.default_credit_account_id.id or False + if move.journal_id.type == 'purchase': + if total>0: + account = move.journal_id.default_credit_account_id else: - data['account_id'] = move.journal_id.default_debit_account_id.id or False - if 'account_id' in fields and data['account_id']: - account = self.pool.get('account.account').browse(cr, uid, data['account_id']) - data['tax_code_id'] = self._default_get_tax(cr, uid, account ) - return data + account = move.journal_id.default_debit_account_id + else: + if total>0: + account = move.journal_id.default_credit_account_id + else: + account = move.journal_id.default_debit_account_id - def _default_get_tax(self, cr, uid, account, debit=0, credit=0, context={}): - if account.tax_ids: - return account.tax_ids[0].base_code_id.id - return False + data['account_id'] = account.id + if account and account.tax_ids: + for tax in self.pool.get('account.tax').compute_inv(cr,uid,[account.tax_ids[0]],total,1.00): + total -= tax['amount'] + data['account_tax_id'] = account.tax_ids[0].id + s = -total + data['debit'] = s>0 and s or 0.0 + data['credit'] = s<0 and -s or 0.0 + return data def _on_create_write(self, cr, uid, id, context={}): ml = self.browse(cr, uid, id, context) @@ -307,7 +246,6 @@ class account_move_line(osv.osv): 'debit': fields.float('Debit', digits=(16,2)), 'credit': fields.float('Credit', digits=(16,2)), 'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade", domain=[('type','<>','view'), ('type', '<>', 'closed')], select=2), - 'move_id': fields.many2one('account.move', 'Move', ondelete="cascade", states={'valid':[('readonly',True)]}, help="The move of this entry line.", select=2), 'ref': fields.char('Ref.', size=32), @@ -334,6 +272,10 @@ class account_move_line(osv.osv): 'tax_amount': fields.float('Tax/Base Amount', digits=(16,2), select=True), 'invoice': fields.function(_invoice, method=True, string='Invoice', type='many2one', relation='account.invoice', fnct_search=_invoice_search), + 'account_tax_id':fields.many2one('account.tax', 'Tax'), + 'analytic_account_id' : fields.many2one('account.analytic.account', 'Analytic Account'), +#TODO: remove this + 'amount_taxed':fields.float("Taxed Amount",digits=(16,2)), } def _get_date(self, cr, uid, context): @@ -394,34 +336,22 @@ class account_move_line(osv.osv): (_check_no_closed, 'You can not create move line on closed account.', ['account_id']), ] + #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id + def onchange_partner_id(self, cr, uid, ids, move_id, partner_id, account_id=None, debit=0, credit=0, journal=False): if (not partner_id) or account_id: return {} part = self.pool.get('res.partner').browse(cr, uid, partner_id) id1 = part.property_account_payable.id id2 = part.property_account_receivable.id - cr.execute('select sum(debit-credit) from account_move_line where (reconcile_id is null) and partner_id=%d and account_id=%d', (partner_id, id2)) - balance = cr.fetchone()[0] or 0.0 val = {} - if (not debit) and (not credit): - if abs(balance)>0.01: - val['credit'] = ((balance>0) and balance) or 0 - val['debit'] = ((balance<0) and -balance) or 0 - val['account_id'] = id2 - else: - cr.execute('select sum(debit-credit) from account_move_line where (reconcile_id is null) and partner_id=%d and account_id=%d', (partner_id, id1)) - balance = cr.fetchone()[0] or 0.0 - val['credit'] = ((balance>0) and balance) or 0 - val['debit'] = ((balance<0) and -balance) or 0 - val['account_id'] = id1 - else: - val['account_id'] = (debit>0) and id2 or id1 if journal: jt = self.pool.get('account.journal').browse(cr, uid, journal).type if jt=='sale': val['account_id'] = id2 elif jt=='purchase': val['account_id'] = id1 + # Compute Maturity Date in val ! return {'value':val} # @@ -632,7 +562,19 @@ class account_move_line(osv.osv): def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): if not context: context={} + raise_ex=False account_obj = self.pool.get('account.account') + acc=account_obj.browse(cr,uid,ids)[0] + + if ('debit' in vals and 'credit' in vals) and not vals['debit'] and not vals['credit']: + raise_ex=True + if ('debit' in vals and 'credit' not in vals) and not vals['debit'] and not acc.credit: + raise_ex=True + if ('credit' in vals and 'debit' not in vals) and not vals['credit'] and not acc.debit: + raise_ex=True + + if raise_ex: + raise osv.except_osv(_('Wrong Accounting Entry!'), _('Both Credit and Debit cannot be zero!')) if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']: raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!')) @@ -680,7 +622,9 @@ class account_move_line(osv.osv): def create(self, cr, uid, vals, context=None, check=True): if not context: context={} + account_obj = self.pool.get('account.account') + tax_obj=self.pool.get('account.tax') if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']: raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!')) @@ -692,7 +636,9 @@ class account_move_line(osv.osv): m = self.pool.get('account.move').browse(cr, uid, vals['move_id']) context['journal_id'] = m.journal_id.id context['period_id'] = m.period_id.id + self._update_journal_check(cr, uid, context['journal_id'], context['period_id'], context) + move_id = vals.get('move_id', False) journal = self.pool.get('account.journal').browse(cr, uid, context['journal_id']) if not move_id: @@ -743,7 +689,48 @@ class account_move_line(osv.osv): 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) 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) + 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'], + 'amount': vals['debit'] or vals['credit'], + 'general_account_id': vals['account_id'], + 'journal_id': journal.analytic_journal_id.id, + 'ref': vals['ref'], + })] + + # CREATE Taxes + if 'account_tax_id' in vals and vals['account_tax_id']: + tax_id=tax_obj.browse(cr,uid,vals['account_tax_id']) + total = vals['credit'] or (-vals['debit']) + for tax in tax_obj.compute(cr,uid,[tax_id],total,1.00): + print 'Processing Tax', tax + self.write(cr, uid,[result], { + 'tax_code_id': tax['base_code_id'], + 'tax_amount': tax['base_sign'] * total + }) + data = { + 'move_id': vals['move_id'], + 'journal_id': vals['journal_id'], + 'period_id': vals['period_id'], + 'name': vals['name']+' '+tax['name'], + 'date': vals['date'], + 'partner_id': vals.get('partner_id',False), + 'ref': vals.get('ref',False), + 'account_tax_id': False, + 'tax_code_id': tax['tax_code_id'], + 'tax_amount': tax['tax_sign'] * tax['amount'], + 'account_id': tax['account_paid_id'], # or collected ? + 'credit': tax['amount']>0 and tax['amount'] or 0.0, + 'debit': tax['amount']<0 and -tax['amount'] or 0.0, + } + print data + self.create(cr, uid, data, context) if check: self.pool.get('account.move').validate(cr, uid, [vals['move_id']], context) return result @@ -757,7 +744,5 @@ class account_bank_statement_reconcile(osv.osv): } account_bank_statement_reconcile() - - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 19978b2bd04..8b66b7b62b8 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -653,6 +653,8 @@ + + @@ -695,6 +697,9 @@ + + + @@ -743,6 +748,9 @@ + + + @@ -1343,6 +1351,8 @@ + + diff --git a/addons/account/data/account_data2.xml b/addons/account/data/account_data2.xml index 9f51843efd2..02475a31902 100644 --- a/addons/account/data/account_data2.xml +++ b/addons/account/data/account_data2.xml @@ -1,10 +1,10 @@ - + + --> 30 Days Net @@ -15,7 +15,7 @@ net days - + @@ -74,6 +74,18 @@ credit + + + Tax + account_tax_id + + + + + Analytic Account + analytic_account_id + + Ref @@ -84,9 +96,9 @@ State state - + - + Multi-Currency Cash Journal View @@ -142,17 +154,29 @@ credit + + + Tax + account_tax_id + + + + + Analytic Account + analytic_account_id + + Currency Amt. amount_currency - + Currency currency_id - + @@ -164,10 +188,10 @@ State state - + - - + + Journal View @@ -229,30 +253,42 @@ credit + + + Tax + account_tax_id + + + + + Analytic Account + analytic_account_id + + Tax Acc. tax_code_id - + Tax tax_amount - + State state - + - - + + - + Account Journal account.journal @@ -262,11 +298,11 @@ account.journal - + - + Account reconcile sequence account.reconcile @@ -278,8 +314,8 @@ - - + + Bank Statement account.bank.statement @@ -291,11 +327,11 @@ - + - + Sales Journal SAJ @@ -316,7 +352,7 @@ - + Bank Journal BNK @@ -327,7 +363,7 @@ - + Stock Journal STJ @@ -336,6 +372,6 @@ - + \ No newline at end of file diff --git a/addons/account/project/project.py b/addons/account/project/project.py index fd327d8db96..8bab0577586 100644 --- a/addons/account/project/project.py +++ b/addons/account/project/project.py @@ -237,6 +237,14 @@ class account_analytic_journal(osv.osv): } account_analytic_journal() +class account_journal(osv.osv): + _inherit="account.journal" + + _columns = { + 'analytic_journal_id':fields.many2one('account.analytic.journal','Analytic Journal'), + } +account_journal() + # --------------------------------------------------------- # Budgets diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml index 8cff25efd59..27ba38f3f88 100644 --- a/addons/account/project/project_view.xml +++ b/addons/account/project/project_view.xml @@ -1,7 +1,7 @@ - + account.analytic.account.list account.analytic.account @@ -17,7 +17,7 @@ - + account.analytic.account.tree account.analytic.account @@ -37,7 +37,7 @@ - + account.analytic.account.form account.analytic.account @@ -66,7 +66,7 @@ - + Analytic Accounts ir.actions.act_window @@ -76,7 +76,7 @@ - + Analytic Charts of Accounts ir.actions.act_window @@ -86,13 +86,13 @@ - + - + account.analytic.line.form account.analytic.line @@ -141,8 +141,8 @@ - - + + action.account.tree1 account.analytic.line @@ -157,7 +157,7 @@ - + account.analytic.line.extended_form account.analytic.line @@ -183,11 +183,11 @@ form - + # # Analytic Journal # - + account.analytic.journal.tree account.analytic.journal @@ -200,7 +200,7 @@ - + account.analytic.journal.form account.analytic.journal @@ -221,11 +221,11 @@ tree,form - + # # Open journal entries # - + account.analytic.journal.open.form account.analytic.line @@ -240,19 +240,19 @@ - + # # Reporting # - + Print Analytic Journals account.analytic.journal tree - - + + Analytic Entries by Journal account.analytic.journal @@ -260,11 +260,11 @@ - + # # Statistics # - + report.hr.timesheet.invoice.journal.form report.hr.timesheet.invoice.journal @@ -277,8 +277,8 @@ - - + + report.hr.timesheet.invoice.journal.tree report.hr.timesheet.invoice.journal @@ -294,7 +294,7 @@ - + report.hr.timesheet.invoice.journal.graph report.hr.timesheet.invoice.journal @@ -308,7 +308,7 @@ - + Account cost and revenue by journal report.hr.timesheet.invoice.journal @@ -316,7 +316,7 @@ tree,graph - + Account cost and revenue by journal (This Month) report.hr.timesheet.invoice.journal @@ -325,11 +325,23 @@ [('name','=',time.strftime('%Y-%m-01'))] - + - - + + - + + + account.journal.form.1 + account.journal + + form + + + + + + +