diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index b6c9a889476..662fdda69d5 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -29,6 +29,25 @@ import decimal_precision as dp class account_bank_statement(osv.osv): + def create(self, cr, uid, vals, context=None): + seq = 0 + if 'line_ids' in vals: + for line in vals['line_ids']: + seq += 1 + line[2]['sequence'] = seq + vals[seq - 1] = line + return super(account_bank_statement, self).create(cr, uid, vals, context=context) + + def write(self, cr, uid, ids, vals, context=None): + res = super(account_bank_statement, self).write(cr, uid, ids, vals, context=context) + for statement in self.browse(cr, uid, ids, context): + seq = 0 + for line in statement.line_ids: + seq += 1 + if not line.sequence: + self.pool.get('account.bank.statement.line').write(cr, uid, [line.id], {'sequence': seq}, context=context) + return res + def button_import_invoice(self, cr, uid, ids, context=None): mod_obj = self.pool.get('ir.model.data') if context is None: @@ -141,7 +160,7 @@ class account_bank_statement(osv.osv): 'balance_end_real': fields.float('Ending Balance', digits_compute=dp.get_precision('Account'), states={'confirm':[('readonly', True)]}), 'balance_end': fields.function(_end_balance, method=True, string='Balance'), - 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, required=True), + 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True), 'line_ids': fields.one2many('account.bank.statement.line', 'statement_id', 'Statement lines', states={'confirm':[('readonly', True)]}), @@ -711,13 +730,12 @@ class account_bank_statement_line(osv.osv): 'reconcile_amount': fields.function(_reconcile_amount, string='Amount reconciled', method=True, type='float'), 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of bank statement lines."), - 'company_id': fields.related('statement_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, required=True), + 'company_id': fields.related('statement_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True), } _defaults = { 'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement.line'), 'date': lambda *a: time.strftime('%Y-%m-%d'), 'type': lambda *a: 'general', - 'sequence': lambda *a: 10, } account_bank_statement_line() diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index 01d292ce23e..daf2f9ba8f2 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -204,7 +204,6 @@ class account_cash_statement(osv.osv): return res _columns = { - 'company_id':fields.many2one('res.company', 'Company', required=True, states={'draft': [('readonly', False)]}, readonly=True,), 'journal_id': fields.many2one('account.journal', 'Journal', required=True, states={'draft': [('readonly', False)]}, readonly=True, domain=[('type', '=', 'cash')]), 'balance_end_real': fields.float('Closing Balance', digits_compute=dp.get_precision('Account'), states={'confirm':[('readonly', True)]}, help="closing balance entered by the cashbox verifier"), 'state': fields.selection( @@ -224,22 +223,18 @@ class account_cash_statement(osv.osv): 'state': lambda *a: 'draft', 'date': lambda *a:time.strftime("%Y-%m-%d %H:%M:%S"), 'user_id': lambda self, cr, uid, context=None: uid, - 'company_id': _get_company, 'starting_details_ids':_get_cash_open_box_lines, 'ending_details_ids':_get_default_cash_close_box_lines } def create(self, cr, uid, vals, context=None): - company_id = vals and vals.get('company_id',False) - if company_id: - sql = [ - ('company_id', '=', vals['company_id']), + sql = [ ('journal_id', '=', vals['journal_id']), ('state', '=', 'open') - ] - open_jrnl = self.search(cr, uid, sql) - if open_jrnl: - raise osv.except_osv('Error', _('You can not have two open register for the same journal')) + ] + open_jrnl = self.search(cr, uid, sql) + if open_jrnl: + raise osv.except_osv('Error', _('You can not have two open register for the same journal')) if self.pool.get('account.journal').browse(cr, uid, vals['journal_id']).type == 'cash': lines = end_lines = self._get_cash_close_box_lines(cr, uid, [], context) diff --git a/addons/account/account_installer.xml b/addons/account/account_installer.xml index e71dc6f09c8..a9de51c3afb 100644 --- a/addons/account/account_installer.xml +++ b/addons/account/account_installer.xml @@ -14,7 +14,7 @@ Configure Your Accounting Chart - Configure your accounting system. By default, Chart of Account is matching to your country. If there are not chart of account certified for your county, you can install the generic chart of account. + The default Chart of Accounts is matching your country selection. If no certified Chart of Accounts exists for your specified country, a generic one can be installed and will be selected by default. Configure @@ -73,7 +73,7 @@ - From this screen, you can install Other Addons in your accounting Application. Select the Addons to directly install them. If you do not think you need any of these right now, you can easily install them later. + Add extra Accounting Addons to the ones already installed. Remember you can always install them at a later stage. Configure diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 463612e2177..7ddd4ad42f0 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -1117,7 +1117,6 @@ class account_move_line(osv.osv): context['period_id'] = m.period_id.id self._update_journal_check(cr, uid, context['journal_id'], context['period_id'], context) - company_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id move_id = vals.get('move_id', False) journal = self.pool.get('account.journal').browse(cr, uid, context['journal_id']) is_new_move = False @@ -1156,7 +1155,10 @@ class account_move_line(osv.osv): if a.id == vals['account_id']: ok = True break - if (account.currency_id) and 'amount_currency' not in vals and account.currency_id.id <> company_currency: + + # Automatically convert in the account's secondary currency if there is one and + # the provided values were not already multi-currency + if account.currency_id and 'amount_currency' not in vals and account.currency_id.id != account.company_id.currency_id.id: vals['currency_id'] = account.currency_id.id cur_obj = self.pool.get('res.currency') ctx = {} diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index ce4a79c545c..d6532530a91 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -524,15 +524,15 @@ - + + - @@ -546,7 +546,7 @@ - + diff --git a/addons/account/report/account_balance.py b/addons/account/report/account_balance.py index 19b06b10510..f2177f80b3a 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.py @@ -69,19 +69,19 @@ class account_balance(report_sxw.rml_parse, common_report_header): return super(account_balance ,self)._get_account(data) def lines(self, form, ids=[], done=None):#, level=1): - def _process_child(accounts,disp_acc,parent): + def _process_child(accounts, disp_acc, parent): account_rec = [acct for acct in accounts if acct['id']==parent][0] res = { 'id': account_rec['id'], - 'type': account_rec['type'], + 'type': account_rec['type'], 'code': account_rec['code'], 'name': account_rec['name'], 'level': account_rec['level'], 'debit': account_rec['debit'], 'credit': account_rec['credit'], 'balance': account_rec['balance'], - 'parent_id':account_rec['parent_id'], - 'bal_type':'', + 'parent_id': account_rec['parent_id'], + 'bal_type': '', } self.sum_debit += account_rec['debit'] self.sum_credit += account_rec['credit'] @@ -96,7 +96,7 @@ class account_balance(report_sxw.rml_parse, common_report_header): if account_rec['child_id']: for child in account_rec['child_id']: _process_child(accounts,disp_acc,child) - + obj_account = self.pool.get('account.account') if not ids: ids = self.ids @@ -113,6 +113,7 @@ class account_balance(report_sxw.rml_parse, common_report_header): elif form['filter'] == 'filter_date': ctx['date_from'] = form['date_from'] ctx['date_to'] = form['date_to'] + ctx['state'] = form['target_move'] parents = ids child_ids = obj_account._get_children_and_consol(self.cr, self.uid, ids, ctx) if child_ids: diff --git a/addons/account/report/account_general_ledger.py b/addons/account/report/account_general_ledger.py index 2cf9a489a1a..340cb991941 100644 --- a/addons/account/report/account_general_ledger.py +++ b/addons/account/report/account_general_ledger.py @@ -40,6 +40,9 @@ class general_ledger(rml_parse.rml_parse, common_report_header): new_ids = ids self.sortby = data['form'].get('sortby', 'sort_date') self.query = data['form'].get('query_line', '') + self.init_query = data['form']['initial_bal_query'] + self.init_balance = data['form']['initial_balance'] + self.display_account = data['form']['display_account'] if (data['model'] == 'ir.ui.menu'): new_ids = [data['form']['chart_account_id']] objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids) @@ -79,10 +82,10 @@ class general_ledger(rml_parse.rml_parse, common_report_header): "FROM account_move_line l "\ "WHERE l.account_id = %s AND %s" %(account.id, self.query)) sum_currency = self.cr.fetchone()[0] or 0.0 - if form.get('initial_balance', False): + if self.init_balance: self.cr.execute("SELECT sum(l.amount_currency) AS tot_currency "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id, form['initial_bal_query'])) + "WHERE l.account_id = %s AND %s "%(account.id, self.init_query)) sum_currency += self.cr.fetchone()[0] or 0.0 return str(sum_currency) @@ -99,10 +102,10 @@ class general_ledger(rml_parse.rml_parse, common_report_header): num_entry = self.cr.fetchone()[0] or 0 sold_account = self._sum_balance_account(child_account,form) self.sold_accounts[child_account.id] = sold_account - if form['display_account'] == 'bal_movement': + if self.display_account == 'bal_movement': if child_account.type != 'view' and num_entry <> 0 : res.append(child_account) - elif form['display_account'] == 'bal_solde': + elif self.display_account == 'bal_solde': if child_account.type != 'view' and num_entry <> 0 : if ( sold_account <> 0.0): res.append(child_account) @@ -150,7 +153,7 @@ class general_ledger(rml_parse.rml_parse, common_report_header): self.cr.execute(sql, (account.id,)) res_lines = self.cr.dictfetchall() res_init = [] - if res_lines and form['initial_balance']: + if res_lines and self.init_balance: #FIXME: replace the label of lname with a string translatable sql = """ SELECT 0 AS lid, '' AS ldate, '' AS lcode, COALESCE(SUM(l.amount_currency),0.0) AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, '' AS lperiod_id, '' AS lpartner_id, @@ -165,7 +168,7 @@ class general_ledger(rml_parse.rml_parse, common_report_header): LEFT JOIN account_invoice i on (m.id =i.move_id) JOIN account_journal j on (l.journal_id=j.id) WHERE %s AND l.account_id = %%s - """ %(form['initial_bal_query']) + """ %(self.init_query) self.cr.execute(sql, (account.id,)) res_init = self.cr.dictfetchall() @@ -193,10 +196,10 @@ class general_ledger(rml_parse.rml_parse, common_report_header): "FROM account_move_line l "\ "WHERE l.account_id = %s AND %s "%(account.id, self.query)) sum_debit = self.cr.fetchone()[0] or 0.0 - if form.get('initial_balance', False): + if self.init_balance: self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id, form['initial_bal_query'])) + "WHERE l.account_id = %s AND %s "%(account.id, self.init_query)) # Add initial balance to the result sum_debit += self.cr.fetchone()[0] or 0.0 return sum_debit @@ -206,10 +209,10 @@ class general_ledger(rml_parse.rml_parse, common_report_header): "FROM account_move_line l "\ "WHERE l.account_id = %s AND %s "%(account.id, self.query)) sum_credit = self.cr.fetchone()[0] or 0.0 - if form.get('initial_balance', False): + if self.init_balance: self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id, form['initial_bal_query'])) + "WHERE l.account_id = %s AND %s "%(account.id, self.init_query)) # Add initial balance to the result sum_credit += self.cr.fetchone()[0] or 0.0 return sum_credit @@ -219,10 +222,10 @@ class general_ledger(rml_parse.rml_parse, common_report_header): "FROM account_move_line l "\ "WHERE l.account_id = %s AND %s"%(account.id, self.query)) sum_balance = self.cr.fetchone()[0] or 0.0 - if form.get('initial_balance', False): + if self.init_balance: self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_balance "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id, form['initial_bal_query'])) + "WHERE l.account_id = %s AND %s "%(account.id, self.init_query)) # Add initial balance to the result sum_balance += self.cr.fetchone()[0] or 0.0 return sum_balance diff --git a/addons/account/report/account_partner_balance.py b/addons/account/report/account_partner_balance.py index 5d6788f240c..83e9f03e0a4 100644 --- a/addons/account/report/account_partner_balance.py +++ b/addons/account/report/account_partner_balance.py @@ -99,12 +99,12 @@ class partner_balance(report_sxw.rml_parse, common_report_header): def set_context(self, objects, data, ids, report_type=None): ## Compute Code # - self.initial_balance = data['form'].get('initial_balance', True) - self.display_partner = data['form'].get('display_partner', 'non-zero_balance') +# self.initial_balance = data['form'].get('initial_balance', True) + self.display_partner = data['form'].get('display_partner', 'non-zero_balance') self.query = data['form'].get('query_line', '') self.init_query = data['form'].get('initial_bal_query', '') self.result_selection = data['form'].get('result_selection') - + if (self.result_selection == 'customer' ): self.ACCOUNT_TYPE = ('receivable',) elif (self.result_selection == 'supplier'): @@ -150,81 +150,81 @@ class partner_balance(report_sxw.rml_parse, common_report_header): res = self.cr.dictfetchall() #For include intial balance.. - if self.initial_balance: - self.cr.execute( - "SELECT '1' AS type, '' AS ref, l.account_id AS account_id, '' AS account_name, '' AS code, '' AS name, sum(debit) AS debit, sum(credit) AS credit, " \ - "CASE WHEN sum(debit) > sum(credit) " \ - "THEN sum(debit) - sum(credit) " \ - "ELSE 0 " \ - "END AS sdebit, " \ - "CASE WHEN sum(debit) < sum(credit) " \ - "THEN sum(credit) - sum(debit) " \ - "ELSE 0 " \ - "END AS scredit, " \ - "(SELECT sum(debit-credit) " \ - "FROM account_move_line l " \ - "WHERE partner_id = p.id " \ - " AND " + self.init_query + " " \ - "AND blocked = TRUE " \ - ") AS enlitige " \ - "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \ - "JOIN account_account ac ON (l.account_id = ac.id) " \ - "WHERE ac.type IN %s " \ - "AND " + self.init_query + "" \ - "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ - "ORDER BY l.account_id, p.name", - (self.ACCOUNT_TYPE, )) - res1 = self.cr.dictfetchall() - final_init = {} - res_init = {} - debit = credit = 0 - for r in res1: - if final_init.get(r['account_id'], False): - res_init = final_init[r['account_id']] - debit += final_init[r['account_id']]['debit'] - credit += final_init[r['account_id']]['credit'] - res_init['credit'] = credit - res_init['debit'] = debit - res_init['type'] = 3 - res_init['ref'] = '' - res_init['code'] = '' - res_init['name'] = 'Initial Balance' - res_init['balance'] = debit - credit - res_init['enlitige'] = 0.0 # fix me - res_init['account_id'] = final_init[r['account_id']]['account_id'] - else: - res_init = {} - debit = r['debit'] - credit = r['credit'] - res_init['credit'] = credit - res_init['debit'] = debit - res_init['type'] = 3 - res_init['ref'] = '' - res_init['code'] = '' - res_init['name'] = 'Initial Balance' - res_init['balance'] = debit - credit - res_init['enlitige'] = 0.0 # fix me - res_init['account_id'] = r['account_id'] - final_init[r['account_id']] = res_init - +# if self.initial_balance: +# self.cr.execute( +# "SELECT '1' AS type, '' AS ref, l.account_id AS account_id, '' AS account_name, '' AS code, '' AS name, sum(debit) AS debit, sum(credit) AS credit, " \ +# "CASE WHEN sum(debit) > sum(credit) " \ +# "THEN sum(debit) - sum(credit) " \ +# "ELSE 0 " \ +# "END AS sdebit, " \ +# "CASE WHEN sum(debit) < sum(credit) " \ +# "THEN sum(credit) - sum(debit) " \ +# "ELSE 0 " \ +# "END AS scredit, " \ +# "(SELECT sum(debit-credit) " \ +# "FROM account_move_line l " \ +# "WHERE partner_id = p.id " \ +# " AND " + self.init_query + " " \ +# "AND blocked = TRUE " \ +# ") AS enlitige " \ +# "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \ +# "JOIN account_account ac ON (l.account_id = ac.id) " \ +# "WHERE ac.type IN %s " \ +# "AND " + self.init_query + "" \ +# "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ +# "ORDER BY l.account_id, p.name", +# (self.ACCOUNT_TYPE, )) +# res1 = self.cr.dictfetchall() +# final_init = {} +# res_init = {} +# debit = credit = 0 +# for r in res1: +# if final_init.get(r['account_id'], False): +# res_init = final_init[r['account_id']] +# debit += final_init[r['account_id']]['debit'] +# credit += final_init[r['account_id']]['credit'] +# res_init['credit'] = credit +# res_init['debit'] = debit +# res_init['type'] = 3 +# res_init['ref'] = '' +# res_init['code'] = '' +# res_init['name'] = 'Initial Balance' +# res_init['balance'] = debit - credit +# res_init['enlitige'] = 0.0 # fix me +# res_init['account_id'] = final_init[r['account_id']]['account_id'] +# else: +# res_init = {} +# debit = r['debit'] +# credit = r['credit'] +# res_init['credit'] = credit +# res_init['debit'] = debit +# res_init['type'] = 3 +# res_init['ref'] = '' +# res_init['code'] = '' +# res_init['name'] = 'Initial Balance' +# res_init['balance'] = debit - credit +# res_init['enlitige'] = 0.0 # fix me +# res_init['account_id'] = r['account_id'] +# final_init[r['account_id']] = res_init + if self.display_partner == 'non-zero_balance': full_account = [r for r in res if r['sdebit'] > 0 or r['scredit'] > 0] else: full_account = [r for r in res] - + ## We will now compute Total subtotal_row = self._add_subtotal(full_account) - if not self.initial_balance: - return subtotal_row - - #If include initial balance is selected.. - subtotal = copy.deepcopy(subtotal_row) - init_acnt = [] - for row in subtotal_row: - if final_init and row.get('account_id', False) and not row['account_id'] in init_acnt and final_init.get(row['account_id'], False): - subtotal.insert(subtotal.index(row), final_init[row['account_id']]) - init_acnt.append(row['account_id']) - return subtotal +# if not self.initial_balance: +# return subtotal_row +# +# #If include initial balance is selected.. +# subtotal = copy.deepcopy(subtotal_row) +# init_acnt = [] +# for row in subtotal_row: +# if final_init and row.get('account_id', False) and not row['account_id'] in init_acnt and final_init.get(row['account_id'], False): +# subtotal.insert(subtotal.index(row), final_init[row['account_id']]) +# init_acnt.append(row['account_id']) + return subtotal_row def _add_subtotal(self, cleanarray): i = 0 @@ -354,14 +354,14 @@ class partner_balance(report_sxw.rml_parse, common_report_header): "AND " + self.query + "" , (tuple(self.account_ids), )) temp_res = float(self.cr.fetchone()[0] or 0.0) - if self.initial_balance: - self.cr.execute( - "SELECT sum(debit) " \ - "FROM account_move_line AS l " \ - "WHERE l.account_id IN %s " \ - "AND " + self.init_query + "" , - (tuple(self.account_ids), )) - temp_res += float(self.cr.fetchone()[0] or 0.0) +# if self.initial_balance: +# self.cr.execute( +# "SELECT sum(debit) " \ +# "FROM account_move_line AS l " \ +# "WHERE l.account_id IN %s " \ +# "AND " + self.init_query + "" , +# (tuple(self.account_ids), )) +# temp_res += float(self.cr.fetchone()[0] or 0.0) return temp_res def _sum_credit(self): @@ -375,14 +375,14 @@ class partner_balance(report_sxw.rml_parse, common_report_header): "AND " + self.query + "" , (tuple(self.account_ids),)) temp_res = float(self.cr.fetchone()[0] or 0.0) - if self.initial_balance: - self.cr.execute( - "SELECT sum(credit) " \ - "FROM account_move_line AS l " \ - "WHERE l.account_id IN %s " \ - "AND " + self.init_query + "" , - (tuple(self.account_ids),)) - temp_res += float(self.cr.fetchone()[0] or 0.0) +# if self.initial_balance: +# self.cr.execute( +# "SELECT sum(credit) " \ +# "FROM account_move_line AS l " \ +# "WHERE l.account_id IN %s " \ +# "AND " + self.init_query + "" , +# (tuple(self.account_ids),)) +# temp_res += float(self.cr.fetchone()[0] or 0.0) return temp_res def _sum_litige(self): @@ -397,15 +397,15 @@ class partner_balance(report_sxw.rml_parse, common_report_header): "AND l.blocked=TRUE ", (tuple(self.account_ids), )) temp_res = float(self.cr.fetchone()[0] or 0.0) - if self.initial_balance: - self.cr.execute( - "SELECT sum(debit-credit) " \ - "FROM account_move_line AS l " \ - "WHERE l.account_id IN %s " \ - "AND l.blocked=TRUE "\ - "AND " + self.init_query + "" , - (tuple(self.account_ids), )) - temp_res += float(self.cr.fetchone()[0] or 0.0) +# if self.initial_balance: +# self.cr.execute( +# "SELECT sum(debit-credit) " \ +# "FROM account_move_line AS l " \ +# "WHERE l.account_id IN %s " \ +# "AND l.blocked=TRUE "\ +# "AND " + self.init_query + "" , +# (tuple(self.account_ids), )) +# temp_res += float(self.cr.fetchone()[0] or 0.0) return temp_res def _sum_sdebit(self): diff --git a/addons/account/security/ir.model.access.csv b/addons/account/security/ir.model.access.csv index 903001a2b30..b87f0e45cd3 100644 --- a/addons/account/security/ir.model.access.csv +++ b/addons/account/security/ir.model.access.csv @@ -198,3 +198,8 @@ "access_account_analytic_line_accounting_accountant","account.analytic.line","analytic.model_account_analytic_line","account.group_accounting_accountant",1,0,0,0 "access_account_analytic_journal_accounting_accountant","account.analytic.journal","model_account_analytic_journal","account.group_accounting_accountant",1,0,0,0 "access_account_bank_statement_reconcile_accounting_accountant","account.bank.statement.reconcile","model_account_bank_statement_reconcile","account.group_accounting_accountant",1,1,1,1 +"access_account_analytic_journal_analytic_accounting","account.analytic.journal","model_account_analytic_journal","analytic.group_analytic_accounting",1,1,1,1 +"access_account_account_analytic_accounting","account.account","model_account_account","analytic.group_analytic_accounting",1,0,0,0 +"access_product_product_analytic_accounting","product.product","product.model_product_product","analytic.group_analytic_accounting",1,0,0,0 +"access_product_category_analytic_accounting","product.category","product.model_product_category","analytic.group_analytic_accounting",1,0,0,0 +"access_product_template_analytic_accounting","product.template","product.model_product_template","analytic.group_analytic_accounting",1,0,0,0 diff --git a/addons/account/wizard/account_chart.py b/addons/account/wizard/account_chart.py index 3d5f308f7bd..84683d17b30 100644 --- a/addons/account/wizard/account_chart.py +++ b/addons/account/wizard/account_chart.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # ############################################################################## - +import time from osv import fields, osv from tools.translate import _ @@ -29,16 +29,55 @@ class account_chart(osv.osv_memory): _name = "account.chart" _description = "Account chart" _columns = { - 'fiscalyear': fields.many2one('account.fiscalyear', \ + 'fiscalyear': fields.many2one('account.fiscalyear', \ 'Fiscal year', \ help = 'Keep empty for all open fiscal years'), - 'target_move': fields.selection([('all', 'All Entries'), + 'period_from': fields.many2one('account.period', 'Start period'), + 'period_to': fields.many2one('account.period', 'End period'), + 'target_move': fields.selection([('all', 'All Entries'), ('posted', 'All Posted Entries')], 'Target Moves', required = True), } def _get_fiscalyear(self, cr, uid, context=None): """Return default Fiscalyear value""" - return self.pool.get('account.fiscalyear').find(cr, uid) + now = time.strftime('%Y-%m-%d') + fiscalyears = self.pool.get('account.fiscalyear').search(cr, uid, [('date_start', '<', now), ('date_stop', '>', now)], limit=1 ) + return fiscalyears and fiscalyears[0] or False + + def _build_periods(self, cr, uid, period_from, period_to): + period_obj = self.pool.get('account.period') + period_date_start = period_obj.read(cr, uid, period_from, ['date_start'])['date_start'] + period_date_stop = period_obj.read(cr, uid, period_to, ['date_stop'])['date_stop'] + if period_date_start > period_date_stop: + raise osv.except_osv(_('Error'),_('Start period should be smaller then End period')) + return period_obj.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop)]) + + def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None): + res = {} + res['value'] = {'period_from': False, 'period_to': False} + if fiscalyear_id: + start_period = end_period = False + cr.execute(''' + SELECT * FROM (SELECT p.id + FROM account_period p + LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id) + WHERE f.id = %s + ORDER BY p.date_start ASC + LIMIT 1) AS period_start + UNION + SELECT * FROM (SELECT p.id + FROM account_period p + LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id) + WHERE f.id = %s + AND p.date_start < NOW() + ORDER BY p.date_stop DESC + LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id)) + periods = [i[0] for i in cr.fetchall()] + if periods and len(periods) > 1: + start_period = periods[0] + end_period = periods[1] + res['value'] = {'period_from': start_period, 'period_to': end_period} + return res def account_chart_open_window(self, cr, uid, ids, context=None): """ @@ -56,7 +95,10 @@ class account_chart(osv.osv_memory): result = mod_obj._get_id(cr, uid, 'account', 'action_account_tree') id = mod_obj.read(cr, uid, [result], ['res_id'], context=context)[0]['res_id'] result = act_obj.read(cr, uid, [id], context=context)[0] - result['context'] = str({'fiscalyear': data['fiscalyear'], \ + result['periods'] = [] + if data['period_from'] and data['period_to']: + result['periods'] = self._build_periods(cr, uid, data['period_from'], data['period_to']) + result['context'] = str({'fiscalyear': data['fiscalyear'], 'periods': result['periods'], \ 'state': data['target_move']}) if data['fiscalyear']: result['name'] += ':' + self.pool.get('account.fiscalyear').read(cr, uid, [data['fiscalyear']], context=context)[0]['code'] diff --git a/addons/account/wizard/account_chart_view.xml b/addons/account/wizard/account_chart_view.xml index 62f5c225a81..eb662058f32 100644 --- a/addons/account/wizard/account_chart_view.xml +++ b/addons/account/wizard/account_chart_view.xml @@ -7,16 +7,18 @@ form
- - -