diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index 6f3675392e0..da1f95de301 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -53,11 +53,11 @@ module named account_voucher. 'wizard/account_move_bank_reconcile_view.xml', 'wizard/account_use_model_view.xml', 'account_installer.xml', + 'wizard/account_period_close_view.xml', 'account_view.xml', 'account_report.xml', 'wizard/account_report_common_view.xml', 'wizard/account_invoice_refund_view.xml', - 'wizard/account_period_close_view.xml', 'wizard/account_fiscalyear_close_state.xml', 'wizard/account_chart_view.xml', 'wizard/account_tax_chart_view.xml', @@ -75,7 +75,6 @@ module named account_voucher. 'wizard/account_journal_select_view.xml', 'wizard/account_change_currency_view.xml', 'wizard/account_validate_move_view.xml', - 'wizard/account_pay_invoice_view.xml', 'wizard/account_unreconcile_view.xml', 'wizard/account_report_general_ledger_view.xml', 'wizard/account_invoice_state_view.xml', diff --git a/addons/account/account.py b/addons/account/account.py index 5db5c080060..402340afc9a 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -18,6 +18,7 @@ # along with this program. If not, see . # ############################################################################## + import time from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta @@ -60,7 +61,7 @@ class account_payment_term(osv.osv): 'line_ids': fields.one2many('account.payment.term.line', 'payment_id', 'Terms'), } _defaults = { - 'active': lambda *a: 1, + 'active': 1, } _order = "name" @@ -120,9 +121,9 @@ class account_payment_term_line(osv.osv): 'payment_id': fields.many2one('account.payment.term', 'Payment Term', required=True, select=True), } _defaults = { - 'value': lambda *a: 'balance', - 'sequence': lambda *a: 5, - 'days2': lambda *a: 0, + 'value': 'balance', + 'sequence': 5, + 'days2': 0, } _order = "sequence" @@ -405,10 +406,10 @@ class account_account(osv.osv): } _defaults = { - 'type': lambda *a : 'view', - 'reconcile': lambda *a: False, - 'active': lambda *a: True, - 'currency_mode': lambda *a: 'current', + 'type': 'view', + 'reconcile': False, + 'active': True, + 'currency_mode': 'current', 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'account.account', context=c), } @@ -502,7 +503,7 @@ class account_account(osv.osv): default['child_parent_ids'] = False return super(account_account, self).copy(cr, uid, id, default, context=context) - def _check_moves(self, cr, uid, ids, method, context): + def _check_moves(self, cr, uid, ids, method, context=None): line_obj = self.pool.get('account.move.line') account_ids = self.search(cr, uid, [('id', 'child_of', ids)]) @@ -518,7 +519,7 @@ class account_account(osv.osv): raise osv.except_osv(_('Warning !'), _('You cannot remove/deactivate an account which is set as a property to any Partner.')) return True - def _check_allow_type_change(self, cr, uid, ids, new_type, context): + def _check_allow_type_change(self, cr, uid, ids, new_type, context=None): group1 = ['payable', 'receivable', 'other'] group2 = ['consolidation','view'] line_obj = self.pool.get('account.move.line') @@ -548,9 +549,9 @@ class account_account(osv.osv): self._check_allow_type_change(cr, uid, ids, vals['type'], context=context) return super(account_account, self).write(cr, uid, ids, vals, context=context) - def unlink(self, cr, uid, ids, context={}): - self._check_moves(cr, uid, ids, "unlink", context) - return super(account_account, self).unlink(cr, uid, ids, context) + def unlink(self, cr, uid, ids, context=None): + self._check_moves(cr, uid, ids, "unlink", context=context) + return super(account_account, self).unlink(cr, uid, ids, context=context) account_account() @@ -562,6 +563,7 @@ class account_journal_view(osv.osv): 'columns_id': fields.one2many('account.journal.column', 'view_id', 'Columns') } _order = "name" + account_journal_view() @@ -587,6 +589,7 @@ class account_journal_column(osv.osv): 'readonly': fields.boolean('Readonly'), } _order = "sequence" + account_journal_column() class account_journal(osv.osv): @@ -614,7 +617,7 @@ class account_journal(osv.osv): 'user_id': fields.many2one('res.users', 'User', help="The user responsible for this journal"), 'groups_id': fields.many2many('res.groups', 'account_journal_group_rel', 'journal_id', 'group_id', 'Groups'), 'currency': fields.many2one('res.currency', 'Currency', help='The currency used to enter statement'), - 'entry_posted': fields.boolean('Skip \'Draft\' State for Created Entries', help='Check this box if you don\'t want new account moves to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation.'), + 'entry_posted': fields.boolean('Skip \'Draft\' State for Manual Entries', help='Check this box if you don\'t want new journal entries to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation. \nNote that journal entries that are automatically created by the system are always skipping that state.'), 'company_id': fields.many2one('res.company', 'Company', required=True, select=1, help="Company related to this journal"), # 'invoice_sequence_id': fields.many2one('ir.sequence', 'Invoice Sequence', \ # help="The sequence used for invoice numbers in this journal."), @@ -997,7 +1000,7 @@ class account_move(osv.osv): @param context: context arguments, like lang, time zone @param limit: Returns first 'n' ids of complete result, default is 80. - @return: Returns a list of tupples containing id and name + @return: Returns a list of tuples containing id and name """ if not args: @@ -1058,13 +1061,13 @@ class account_move(osv.osv): else: if cond[1] in ['=like', 'like', 'not like', 'ilike', 'not ilike', 'in', 'not in', 'child_of']: continue - + cr.execute("select move_id from account_move_line group by move_id having sum(debit) %s %%s" % (cond[1]) ,(amount,)) res_ids = set(id[0] for id in cr.fetchall()) ids = ids and (ids & res_ids) or res_ids if ids: return [('id','in',tuple(ids))] - else: + else: return [('id', '=', '0')] _columns = { @@ -1075,7 +1078,7 @@ class account_move(osv.osv): 'state': fields.selection([('draft','Draft'), ('posted','Posted')], 'State', required=True, readonly=True, help='When new account move is created the state will be \'Draft\'. When all the payments are done it will be in \'Posted\' state.'), 'line_id': fields.one2many('account.move.line', 'move_id', 'Entries', states={'posted':[('readonly',True)]}), - 'to_check': fields.boolean('To Be Verified'), + 'to_check': fields.boolean('To Review', help='Check this box if you are unsure of that journal entry and if you want to note it as \'to be reviewed\' by an accounting expert.'), 'partner_id': fields.related('line_id', 'partner_id', type="many2one", relation="res.partner", string="Partner"), 'amount': fields.function(_amount_compute, method=True, string='Amount', digits_compute=dp.get_precision('Account'), type='float', fnct_search=_search_amount), 'date': fields.date('Date', required=True, states={'posted':[('readonly',True)]}), @@ -1148,6 +1151,24 @@ class account_move(osv.osv): return True def button_validate(self, cursor, user, ids, context=None): + def _get_chart_account(cursor, user, account): + if account.parent_id: + chart_account = _get_chart_account(cursor, user, account.parent_id) + else: + chart_account = account + return chart_account + + for move in self.browse(cursor, user, ids): + lines = move.line_id + if lines: + ref_line = lines[0] + ref_chart_account = _get_chart_account(cursor, user, ref_line.account_id) + parent_left = ref_chart_account.parent_left + parent_right = ref_chart_account.parent_right + result = True + for line in lines[1:]: + if not (line.account_id.parent_left > parent_left and line.account_id.parent_left < parent_right): + raise osv.except_osv(_('Error !'), _('You cannot validate a move unless accounts in its entry lines are in same Chart Of Accounts !')) return self.post(cursor, user, ids, context=context) def button_cancel(self, cr, uid, ids, context={}): @@ -1453,7 +1474,7 @@ class account_tax_code(osv.osv): This code is used for some tax declarations. """ - def _sum(self, cr, uid, ids, name, args, context,where ='', where_params=()): + def _sum(self, cr, uid, ids, name, args, context, where ='', where_params=()): parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)])) if context.get('based_on', 'invoices') == 'payments': cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ @@ -1466,13 +1487,15 @@ class account_tax_code(osv.osv): AND ((invoice.state = \'paid\') \ OR (invoice.id IS NULL)) \ GROUP BY line.tax_code_id', - (parent_ids,)+where_params) + (parent_ids,) + where_params) else: cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ - FROM account_move_line AS line \ + FROM account_move_line AS line, \ + account_move AS move \ WHERE line.tax_code_id IN %s '+where+' \ + AND move.id = line.move_id \ GROUP BY line.tax_code_id', - (parent_ids,)+where_params) + (parent_ids,) + where_params) res=dict(cr.fetchall()) for record in self.browse(cr, uid, ids, context): def _rec_get(record): @@ -1483,7 +1506,12 @@ class account_tax_code(osv.osv): res[record.id] = round(_rec_get(record), self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')) return res - def _sum_year(self, cr, uid, ids, name, args, context): + def _sum_year(self, cr, uid, ids, name, args, context=None): + if context is None: + context = {} + move_state = ('posted', ) + if 'state' in context and context['state'] == 'all': + move_state = ('draft', 'posted', ) if 'fiscalyear_id' in context and context['fiscalyear_id']: fiscalyear_id = context['fiscalyear_id'] else: @@ -1493,12 +1521,17 @@ class account_tax_code(osv.osv): if fiscalyear_id: pids = map(lambda x: str(x.id), self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id).period_ids) if pids: - where = ' and period_id IN %s' - where_params = (tuple(pids),) + where = ' AND line.period_id IN %s AND move.state IN %s ' + where_params = (tuple(pids), move_state) return self._sum(cr, uid, ids, name, args, context, where=where, where_params=where_params) def _sum_period(self, cr, uid, ids, name, args, context): + if context is None: + context = {} + move_state = ('posted', ) + if 'state' in context and context['state'] == 'all': + move_state = ('draft', 'posted', ) if 'period_id' in context and context['period_id']: period_id = context['period_id'] else: @@ -1507,7 +1540,7 @@ class account_tax_code(osv.osv): return dict.fromkeys(ids, 0.0) period_id = period_id[0] return self._sum(cr, uid, ids, name, args, context, - where=' and line.period_id=%s', where_params=(period_id,)) + where=' AND line.period_id=%s AND move.state IN %s', where_params=(period_id, move_state)) _name = 'account.tax.code' _description = 'Tax Code' @@ -1665,37 +1698,37 @@ class account_tax(osv.osv): return super(account_tax, self).search(cr, uid, args, offset, limit, order, context, count) - def name_get(self, cr, uid, ids, context={}): + def name_get(self, cr, uid, ids, context=None): if not len(ids): return [] res = [] - for record in self.read(cr, uid, ids, ['description','name'], context): + for record in self.read(cr, uid, ids, ['description','name'], context=context): name = record['description'] and record['description'] or record['name'] res.append((record['id'],name )) return res - def _default_company(self, cr, uid, context={}): + def _default_company(self, cr, uid, context=None): user = self.pool.get('res.users').browse(cr, uid, uid, context=context) if user.company_id: return user.company_id.id return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0] _defaults = { - 'python_compute': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or None\n# partner : res.partner object or None\n\nresult = price_unit * 0.10''', - 'python_compute_inv': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or False\n\nresult = price_unit * 0.10''', - 'applicable_type': lambda *a: 'true', - 'type': lambda *a: 'percent', - 'amount': lambda *a: 0, - 'price_include': lambda *a: 0, - 'active': lambda *a: 1, - 'type_tax_use': lambda *a: 'all', - 'sequence': lambda *a: 1, - 'tax_group': lambda *a: 'vat', - 'ref_tax_sign': lambda *a: 1, - 'ref_base_sign': lambda *a: 1, - 'tax_sign': lambda *a: 1, - 'base_sign': lambda *a: 1, - 'include_base_amount': lambda *a: False, + 'python_compute': '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or None\n# partner : res.partner object or None\n\nresult = price_unit * 0.10''', + 'python_compute_inv': '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or False\n\nresult = price_unit * 0.10''', + 'applicable_type': 'true', + 'type': 'percent', + 'amount': 0, + 'price_include': 0, + 'active': 1, + 'type_tax_use': 'all', + 'sequence': 1, + 'tax_group': 'vat', + 'ref_tax_sign': 1, + 'ref_base_sign': 1, + 'tax_sign': 1, + 'base_sign': 1, + 'include_base_amount': False, 'company_id': _default_company, } _order = 'sequence' diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 6d5a6ac470b..f7c943f71d3 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -720,4 +720,4 @@ class account_bank_statement_line(osv.osv): account_bank_statement_line() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index 42837ad1fb7..5ed057536a8 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -77,7 +77,7 @@ class account_cash_statement(osv.osv): """ res ={} for statement in self.browse(cr, uid, ids): - amount_total=0.0 + amount_total = 0.0 if statement.journal_id.type not in('cash'): continue @@ -232,7 +232,7 @@ class account_cash_statement(osv.osv): 'starting_details_ids':False }) res_id = super(account_cash_statement, self).create(cr, uid, vals, context=context) - self.write(cr, uid, [res_id], {}) + #self.write(cr, uid, [res_id], {}) return res_id def write(self, cr, uid, ids, vals, context=None): @@ -273,8 +273,6 @@ class account_cash_statement(osv.osv): 'balance_start': balance_start }) return res - - res = super(account_cash_statement, self).onchange_journal_id(cr, uid, statement_id, journal_id, context) return res @@ -304,7 +302,7 @@ class account_cash_statement(osv.osv): if statement.name and statement.name == '/': number = self.pool.get('ir.sequence').get(cr, uid, 'account.cash.statement') vals.update({ - 'name':number + 'name': number }) cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm')) @@ -346,6 +344,7 @@ class account_cash_statement(osv.osv): res_users_obj = self.pool.get('res.users') account_move_obj = self.pool.get('account.move') account_move_line_obj = self.pool.get('account.move.line') + account_analytic_line_obj = self.pool.get('account.analytic.line') account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') company_currency_id = res_users_obj.browse(cr, uid, uid, context=context).company_id.currency_id.id @@ -374,6 +373,10 @@ class account_cash_statement(osv.osv): # In line we get reconcile_id on bank.ste.rec. # in bank stat.rec we get line_new_ids on bank.stat.rec.line for move in st.line_ids: + if move.analytic_account_id: + if not st.journal_id.analytic_journal_id: + raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (st.journal_id.name,)) + context.update({'date':move.date}) move_id = account_move_obj.create(cr, uid, { 'journal_id': st.journal_id.id, @@ -412,6 +415,7 @@ class account_cash_statement(osv.osv): 'journal_id': st.journal_id.id, 'period_id': st.period_id.id, 'currency_id': st.currency.id, + 'analytic_account_id': move.analytic_account_id and move.analytic_account_id.id or False } amount = res_currency_obj.compute(cr, uid, st.currency.id, @@ -432,8 +436,28 @@ class account_cash_statement(osv.osv): move.account_id.currency_id.id, amount, context=context, account=acc_cur) val['amount_currency'] = amount_cur + move_line_id = account_move_line_obj.create(cr, uid, val , context=context) + torec.append(move_line_id) - torec.append(account_move_line_obj.create(cr, uid, val , context=context)) + if move.analytic_account_id: + anal_val = {} + amt = (val['credit'] or 0.0) - (val['debit'] or 0.0) + anal_val = { + 'name': val['name'], + 'ref': val['ref'], + 'date': val['date'], + 'amount': amt, + 'account_id': val['analytic_account_id'], + 'currency_id': val['currency_id'], + 'general_account_id': val['account_id'], + 'journal_id': st.journal_id.analytic_journal_id.id, + 'period_id': val['period_id'], + 'user_id': uid, + 'move_id': move_line_id + } + if val.get('amount_currency', False): + anal_val['amount_currency'] = val['amount_currency'] + account_analytic_line_obj.create(cr, uid, anal_val, context=context) if move.reconcile_id and move.reconcile_id.line_new_ids: for newline in move.reconcile_id.line_new_ids: @@ -498,9 +522,8 @@ class account_cash_statement(osv.osv): account_move_line_obj.reconcile(cr, uid, torec, 'statement', writeoff_acc_id=writeoff_acc_id, writeoff_period_id=st.period_id.id, writeoff_journal_id=st.journal_id.id, context=context) else: account_move_line_obj.reconcile_partial(cr, uid, torec, 'statement', context) - - if st.journal_id.entry_posted: - account_move_obj.write(cr, uid, [move_id], {'state':'posted'}) + move_name = st.name + ' - ' + str(move.sequence) + account_move_obj.write(cr, uid, [move_id], {'state':'posted', 'name': move_name}) done.append(st.id) vals = { diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 60466fe8ca5..0cb9165490e 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -136,7 +136,6 @@