diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 9d6db6bdaca..662fdda69d5 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -31,10 +31,11 @@ class account_bank_statement(osv.osv): def create(self, cr, uid, vals, context=None): seq = 0 - for line in vals['line_ids']: - seq += 1 - line[2]['sequence'] = seq - vals[seq - 1] = line + 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): diff --git a/addons/account/report/account_aged_partner_balance.py b/addons/account/report/account_aged_partner_balance.py index 119c1edef1a..77c64176330 100644 --- a/addons/account/report/account_aged_partner_balance.py +++ b/addons/account/report/account_aged_partner_balance.py @@ -132,7 +132,7 @@ class aged_trial_report(rml_parse.rml_parse, common_report_header): history = [] for i in range(5): args_list = (tuple(self.ACCOUNT_TYPE), tuple(partner_ids) ,self.date_from,) - dates_query = '(COALESCE(date_maturity,date)' + dates_query = "(COALESCE(date_maturity,date)" if form[str(i)]['start'] and form[str(i)]['stop']: dates_query += ' BETWEEN %s AND %s)' args_list += (form[str(i)]['start'], form[str(i)]['stop']) @@ -255,17 +255,30 @@ class aged_trial_report(rml_parse.rml_parse, common_report_header): for i in t: future_past['No Partner Defined'] = i[0] history = [] + for i in range(5): + args_list = (tuple(self.ACCOUNT_TYPE), self.date_from) + dates_query = "(COALESCE(date_maturity,date)" + if form[str(i)]['start'] and form[str(i)]['stop']: + dates_query += ' BETWEEN %s AND %s)' + args_list += (form[str(i)]['start'], form[str(i)]['stop']) + elif form[str(i)]['start']: + dates_query += ' > %s)' + args_list += (form[str(i)]['start'],) + else: + dates_query += ' < %s)' + args_list += (form[str(i)]['stop'],) + self.cr.execute('SELECT SUM(debit-credit)\ FROM account_move_line AS l, account_account\ WHERE (l.account_id = account_account.id)\ AND (l.partner_id IS NULL)\ AND (account_account.type IN %s)\ - AND (COALESCE(date_maturity,date) BETWEEN %s AND %s)\ AND ((reconcile_id IS NULL)\ OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))\ AND '+ self.query + '\ - AND account_account.active ' , (tuple(self.ACCOUNT_TYPE), form[str(i)]['start'], form[str(i)]['stop'], self.date_from,)) + AND '+ dates_query + '\ + AND account_account.active ' , args_list) t = self.cr.fetchall() d = {} for i in t: 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/report/account_partner_ledger.py b/addons/account/report/account_partner_ledger.py index db69e51ecf5..4211a516aa7 100644 --- a/addons/account/report/account_partner_ledger.py +++ b/addons/account/report/account_partner_ledger.py @@ -123,11 +123,12 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header): else: RECONCILE_TAG = "AND l.reconcile_id IS NULL" self.cr.execute( - "SELECT l.id,l.date,j.code, l.ref, l.name, l.debit, l.credit,l.amount_currency,c.code AS currency_code " \ + "SELECT l.id,l.date,j.code, l.ref, m.name as move_name, l.name, l.debit, l.credit,l.amount_currency,c.code AS currency_code " \ "FROM account_move_line l " \ "LEFT JOIN account_journal j " \ "ON (l.journal_id = j.id) " \ "LEFT JOIN res_currency c on (l.currency_id=c.id)" \ + "LEFT JOIN account_move m on (m.id=l.move_id)" \ "WHERE l.partner_id = %s " \ "AND l.account_id IN %s AND " + self.query +" " \ " " + RECONCILE_TAG + " "\ @@ -313,4 +314,4 @@ report_sxw.report_sxw('report.account.third_party_ledger_other', 'res.partner', 'addons/account/report/account_partner_ledger_other.rml',parser=third_party_ledger, header='internal') -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/report/account_partner_ledger.rml b/addons/account/report/account_partner_ledger.rml index 57ebc6f44e3..4136fdcc727 100644 --- a/addons/account/report/account_partner_ledger.rml +++ b/addons/account/report/account_partner_ledger.rml @@ -362,10 +362,10 @@ [[ line['code'] ]] - [[ line['ref'] ]] + [[ line['move_name'] ]] - [[ line['name'] ]] + b[[ (line['ref'] or '') + ' ' + line['name'] ]] [[ formatLang((line['debit'])) ]] @@ -487,10 +487,10 @@ [[ line['code'] ]] - [[ line['ref'] ]] + [[ line['move_name'] ]] - [[ line['name'] ]] + a[[ (line['ref'] or '') + ' ' + line['name'] ]] [[ formatLang((line['debit'])) ]] diff --git a/addons/account/report/account_partner_ledger_other.rml b/addons/account/report/account_partner_ledger_other.rml index 1869144cfc9..d34ffdbb7c7 100644 --- a/addons/account/report/account_partner_ledger_other.rml +++ b/addons/account/report/account_partner_ledger_other.rml @@ -431,7 +431,7 @@ - [[ display_currency(data) == False or removeParentNode('blockTable') ]] + [[ display_currency(data) == False or removeParentNode('blockTable') ]] Date @@ -508,7 +508,7 @@
[[ repeatIn(lines(p), 'line') ]] - [[ display_currency(data) == False or removeParentNode('blockTable') ]] + [[ display_currency(data) == False or removeParentNode('blockTable') ]] [[ formatLang(line['date'],date=True) ]] @@ -517,10 +517,10 @@ [[ line['code'] ]] - [[ line['ref'] ]] + [[ line['move_name'] ]] - [[ line['name'] ]] + [[ (line['ref'] or '')+ ' ' + line['name'] ]] [[ formatLang((line['debit'])) ]] @@ -628,7 +628,7 @@
[[ repeatIn(lines(p), 'line') ]] - [[ display_currency(data) == True or removeParentNode('blockTable') ]] + [[ display_currency(data) == True or removeParentNode('blockTable') ]] [[ formatLang(line['date'],date=True) ]] @@ -637,10 +637,10 @@ [[ line['code'] ]] - [[ line['ref'] ]] + [[ line['move_name'] ]] - [[ line['name'] ]] + [[ (line['ref'] or '') + ' ' + line['name'] ]] [[ formatLang((line['debit'])) ]] @@ -662,4 +662,4 @@
- \ No newline at end of file + 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
- - -