diff --git a/addons/hr_timesheet_invoice/__openerp__.py b/addons/hr_timesheet_invoice/__openerp__.py index 9e8af9aa736..7e11fdad723 100644 --- a/addons/hr_timesheet_invoice/__openerp__.py +++ b/addons/hr_timesheet_invoice/__openerp__.py @@ -42,7 +42,6 @@ reports, etc.""", 'hr_timesheet_invoice_report.xml', 'report/report_analytic_view.xml', 'report/hr_timesheet_invoice_report_view.xml', - 'wizard/hr_timesheet_invoice_analytic_cost_ledger_view.xml', 'wizard/hr_timesheet_analytic_profit_view.xml', 'wizard/hr_timesheet_invoice_create_view.xml', 'wizard/hr_timesheet_invoice_create_final_view.xml', diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice_report.xml b/addons/hr_timesheet_invoice/hr_timesheet_invoice_report.xml index cc8028a8a0a..473820d5123 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice_report.xml +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice_report.xml @@ -1,8 +1,6 @@ - - ). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -import pooler -import time -from report import report_sxw - - -class account_analytic_cost_ledger(report_sxw.rml_parse): - def __init__(self, cr, uid, name, context): - super(account_analytic_cost_ledger, self).__init__(cr, uid, name, context=context) - self.sum_revenue={} - self.account_sum_revenue={} - self.localcontext.update( { - 'time': time, - 'lines_g': self._lines_g, - 'lines_a': self._lines_a, - 'account_sum_debit': self._account_sum_debit, - 'account_sum_credit': self._account_sum_credit, - 'account_sum_balance': self._account_sum_balance, - 'account_sum_qty': self._account_sum_qty, - 'account_sum_revenue': self._account_sum_revenue, - 'account_g_sum_revenue': self._account_g_sum_revenue, - 'sum_debit': self._sum_debit, - 'sum_credit': self._sum_credit, - 'sum_balance': self._sum_balance, - 'sum_qty': self._sum_qty, - 'sum_revenue': self._sum_revenue, - }) - - def _lines_g(self, account_id, date1, date2): - self.cr.execute("SELECT sum(aal.amount) AS balance, aa.code AS code, aa.name AS name, aa.id AS id, sum(aal.unit_amount) AS quantity \ - FROM account_account AS aa, account_analytic_line AS aal \ - WHERE (aal.account_id=%s) AND (aal.date>=%s) AND (aal.date<=%s) AND (aal.general_account_id=aa.id) AND aa.active \ - GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", (account_id, date1, date2)) - res = self.cr.dictfetchall() - - for r in res: - if r['balance'] > 0: - r['debit'] = r['balance'] - r['credit'] = 0.0 - elif r['balance'] < 0: - r['debit'] = 0.0 - r['credit'] = -r['balance'] - else: - r['debit'] = 0.0 - r['credit'] = 0.0 - return res - - def _lines_a(self, general_account_id, account_id, date1, date2): - self.cr.execute("SELECT aal.id AS id, aal.name AS name, aal.code AS code, aal.amount AS balance, aal.date AS date, aaj.code AS cj, aal.unit_amount AS quantity \ - FROM account_analytic_line AS aal, account_analytic_journal AS aaj \ - WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) AND (aal.date>=%s) AND (aal.date<=%s) \ - AND (aal.journal_id=aaj.id) \ - ORDER BY aal.date, aaj.code, aal.code", (general_account_id, account_id, date1, date2)) - res = self.cr.dictfetchall() - - line_obj = self.pool.get('account.analytic.line') - price_obj = self.pool.get('product.pricelist') - lines = {} - for l in line_obj.browse(self.cr, self.uid, [ x['id'] for x in res]): - lines[l.id] = l - if not account_id in self.sum_revenue: - self.sum_revenue[account_id] = 0.0 - if not general_account_id in self.account_sum_revenue: - self.account_sum_revenue[general_account_id] = 0.0 - for r in res: - id = r['id'] - revenue = 0.0 - if lines[id].amount < 0 and lines[id].product_id and lines[id].product_uom_id and lines[id].account_id.pricelist_id: - ctx = {'uom': lines[id].product_uom_id.id} - price = price_obj.price_get(self.cr, self.uid, [lines[id].account_id.pricelist_id.id], lines[id].product_id.id, lines[id].unit_amount, False, context=ctx)[lines[id].account_id.pricelist_id.id] - revenue = round(price * lines[id].unit_amount, 2) - r['revenue'] = revenue - self.sum_revenue[account_id] += revenue - self.account_sum_revenue[general_account_id] += revenue - if r['balance'] > 0: - r['debit'] = r['balance'] - r['credit'] = 0.0 - elif r['balance'] < 0: - r['debit'] = 0.0 - r['credit'] = -r['balance'] - else: - r['debit'] = 0.0 - r['credit'] = 0.0 - return res - - def _account_sum_debit(self, account_id, date1, date2): - self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id=%s AND date>=%s AND date<=%s AND amount>0", (account_id, date1, date2)) - return self.cr.fetchone()[0] or 0.0 - - def _account_sum_credit(self, account_id, date1, date2): - self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id=%s AND date>=%s AND date<=%s AND amount<0", (account_id, date1, date2)) - return self.cr.fetchone()[0] or 0.0 - - def _account_sum_balance(self, account_id, date1, date2): - debit = self._account_sum_debit(account_id, date1, date2) - credit = self._account_sum_credit(account_id, date1, date2) - return (debit-credit) - - def _account_sum_qty(self, account_id, date1, date2): - self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line WHERE account_id=%s AND date>=%s AND date<=%s", (account_id, date1, date2)) - return self.cr.fetchone()[0] or 0.0 - - def _account_sum_revenue(self, account_id): - return self.sum_revenue.get(account_id, 0.0) - - def _account_g_sum_revenue(self, general_account_id): - return self.account_sum_revenue.get(general_account_id, 0.0) - - def _sum_debit(self, accounts, date1, date2): - ids = map(lambda x: x.id, accounts) - if not ids: - return 0.0 - self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids,date1, date2)) - return self.cr.fetchone()[0] or 0.0 - - def _sum_credit(self, accounts, date1, date2): - ids = map(lambda x: x.id, accounts) - if not ids: - return 0.0 - ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids, date1, date2)) - return self.cr.fetchone()[0] or 0.0 - - def _sum_balance(self, accounts, date1, date2): - debit = self._sum_debit(accounts, date1, date2) or 0.0 - credit = self._sum_credit(accounts, date1, date2) or 0.0 - return (debit-credit) - - def _sum_qty(self, accounts, date1, date2): - ids = map(lambda x: x.id, accounts) - if not ids: - return 0.0 - ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", (ids,date1, date2)) - return self.cr.fetchone()[0] or 0.0 - - def _sum_revenue(self, accounts): - ids = map(lambda x: x.id, accounts) - if not ids: - return 0.0 - res = 0.0 - for id in ids: - res += self.sum_revenue.get(id, 0.0) - return res - -report_sxw.report_sxw( - 'report.hr.timesheet.invoice.account.analytic.account.cost_ledger', - 'account.analytic.account', - 'addons/hr_timesheet_invoice/report/cost_ledger.rml', - parser=account_analytic_cost_ledger, header='internal') - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/hr_timesheet_invoice/report/cost_ledger.rml b/addons/hr_timesheet_invoice/report/cost_ledger.rml deleted file mode 100644 index d014dd49927..00000000000 --- a/addons/hr_timesheet_invoice/report/cost_ledger.rml +++ /dev/null @@ -1,404 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [[ company.name ]] - - - Cost Ledger - - - - - - - - - - - - - - - - - - - - - Period from startdate - - - Period to enddate - - - Currency - - - Printing date - - - - - - - [[ data['form']['date1'] ]] - - - [[ data['form']['date2'] ]] - - - [[ company.currency_id.name ]] - - - [[ time.strftime('%Y-%m-%d') ]] at [[ time.strftime('%H:%M:%S') ]] - - - - - - - - - - - - - Date - - - J.C. - - - Code - - - Move name - - - Debit - - - Credit - - - Balance - - - - - - - [[ repeatIn(objects,'o') ]] -
- - - - [[ o.code ]] [[ o.complete_name ]] - - - - - - -
- - - - [[ repeatIn(lines_g(o.id,data['form']['date1'],data['form']['date2']),'move_g') ]] - - - - [[ move_g['code'] ]] [[ move_g['name'] ]] - - - - - - - [[ repeatIn(lines_a(move_g['id'],o.id,data['form']['date1'],data['form']['date2']),'move_a') ]] - [[ move_a['date'] ]] - - - [[ move_a['cj'] ]] - - - [[ move_a['code'] ]] - - - [[ move_a['name'] ]] - - - [[ '%.2f' % move_a['debit'] ]] - - - [[ '%.2f' % move_a['credit'] ]] - - - [[ '%.2f' % move_a['balance'] ]] - - - - - - - - - - Total ([[ move_g['code'] ]]) - - - [[ '%.2f' % move_g['debit'] ]] - - - [[ '%.2f' % move_g['credit'] ]] - - - [[ '%.2f' % move_g['balance'] ]] - - - - - - -
- - - - Total ([[ o.code ]]) - - - [[ '%.2f' % (account_sum_debit(o.id,data['form']['date1'],data['form']['date2']) or 0.0) ]] - - - [[ '%.2f' % (account_sum_credit(o.id,data['form']['date1'],data['form']['date2']) or 0.0) ]] - - - [[ '%.2f' % (account_sum_balance(o.id,data['form']['date1'],data['form']['date2']) or 0.0)]] - - - -
- - - - Total - - - [[ '%.2f' % (sum_debit(objects,data['form']['date1'],data['form']['date2']) or 0.0) ]] - - - [[ '%.2f' % (sum_credit(objects,data['form']['date1'],data['form']['date2']) or 0.0) ]] - - - [[ '%.2f' % (sum_balance(objects,data['form']['date1'],data['form']['date2']) or 0.0) ]] - - - - - - -
-
\ No newline at end of file diff --git a/addons/hr_timesheet_invoice/test/hr_timesheet_invoice_report.yml b/addons/hr_timesheet_invoice/test/hr_timesheet_invoice_report.yml index 2340d18e3f8..adce0e97fa3 100644 --- a/addons/hr_timesheet_invoice/test/hr_timesheet_invoice_report.yml +++ b/addons/hr_timesheet_invoice/test/hr_timesheet_invoice_report.yml @@ -7,14 +7,3 @@ (data, format) = netsvc.LocalService('report.account.analytic.profit').create(cr, uid, [], data_dict, {}) if tools.config['test_report_directory']: file(os.path.join(tools.config['test_report_directory'], 'hr_timesheet_invoice-account_analytic_profit_report.'+format), 'wb+').write(data) -- - Print the HR Cost Ledger report through the wizard -- - !python {model: account.analytic.account}: | - import netsvc, tools, os, time - ctx={} - acc_ids = [ref('account.analytic_absences'),ref('account.analytic_internal'),ref('account.analytic_sednacom'),ref('account.analytic_thymbra'),ref('account.analytic_partners_camp_to_camp')] - ctx.update({'model': 'ir.ui.menu','active_ids': acc_ids}) - data_dict = {'date1': time.strftime('%Y-01-01'), 'date2': time.strftime('%Y-%m-%d')} - from tools import test_reports - test_reports.try_report_action(cr, uid, 'action_hr_timesheet_invoice_cost_ledger',wiz_data=data_dict, context=ctx, our_module='hr_timesheet_invoice') diff --git a/addons/hr_timesheet_invoice/wizard/__init__.py b/addons/hr_timesheet_invoice/wizard/__init__.py index 6dce6a7b651..b718be1acbb 100644 --- a/addons/hr_timesheet_invoice/wizard/__init__.py +++ b/addons/hr_timesheet_invoice/wizard/__init__.py @@ -22,7 +22,6 @@ import hr_timesheet_invoice_create import hr_timesheet_analytic_profit import hr_timesheet_final_invoice_create -import hr_timesheet_analytic_cost_ledger_report # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_cost_ledger_report.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_cost_ledger_report.py deleted file mode 100644 index 892c93252ee..00000000000 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_cost_ledger_report.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -import time - -from osv import osv, fields - -class hr_timesheet_analytic_cost_ledger(osv.osv_memory): - _name = 'hr.timesheet.analytic.cost.ledger' - _description = 'hr.timesheet.analytic.cost.ledger' - _columns = { - 'date1': fields.date('Start of period', required=True), - 'date2': fields.date('End of period', required=True) - } - _defaults = { - 'date1': lambda *a: time.strftime('%Y-01-01'), - 'date2': lambda *a: time.strftime('%Y-%m-%d') - } - def print_report(self, cr, uid, ids, context=None): - if context is None: - context = {} - datas = { - 'ids': 'active_ids' in context and context['active_ids'] or [], - 'model': 'account.analytic.account', - 'form': self.read(cr, uid, ids, context=context)[0] - } - return { - 'type': 'ir.actions.report.xml', - 'report_name': 'hr.timesheet.invoice.account.analytic.account.cost_ledger', - 'datas': datas, - } - -hr_timesheet_analytic_cost_ledger() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_analytic_cost_ledger_view.xml b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_analytic_cost_ledger_view.xml deleted file mode 100644 index 71706d9cdfe..00000000000 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_analytic_cost_ledger_view.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - Cost Ledger - hr.timesheet.analytic.cost.ledger - form - -
- - - - - - -