From 7dd22ed5456086e5031503879655dbd78b963664 Mon Sep 17 00:00:00 2001 From: "mra (Open ERP)" Date: Thu, 22 Apr 2010 12:06:01 +0530 Subject: [PATCH] [ADD] hr_timesheet_invoice: Account Analytic Profit=> Osv memory convert bzr revid: mra@tinyerp.com-20100422063601-16jjmsd0ryzlx6yt --- addons/hr_timesheet_invoice/__openerp__.py | 1 + .../hr_timesheet_invoice_report.xml | 4 +- .../hr_timesheet_invoice/wizard/__init__.py | 2 +- .../wizard/account_analytic_profit.py | 99 ------------------- .../wizard/hr_timesheet_analytic_profit.py | 79 +++++++++++++++ .../hr_timesheet_analytic_profit_view.xml | 40 ++++++++ 6 files changed, 123 insertions(+), 102 deletions(-) delete mode 100644 addons/hr_timesheet_invoice/wizard/account_analytic_profit.py create mode 100644 addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit.py create mode 100644 addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit_view.xml diff --git a/addons/hr_timesheet_invoice/__openerp__.py b/addons/hr_timesheet_invoice/__openerp__.py index 3f4aecb9d3f..c41ede0ffe8 100644 --- a/addons/hr_timesheet_invoice/__openerp__.py +++ b/addons/hr_timesheet_invoice/__openerp__.py @@ -40,6 +40,7 @@ reports, eso.""", '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', ], 'demo_xml': ['hr_timesheet_invoice_demo.xml'], 'installable': True, diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice_report.xml b/addons/hr_timesheet_invoice/hr_timesheet_invoice_report.xml index bed54ff7d0d..f2d9f5a8c4a 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice_report.xml +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice_report.xml @@ -24,7 +24,7 @@ rml="hr_timesheet_invoice/report/account_analytic_profit.rml" string="Timesheet Profit"/> - + groups="hr.group_hr_manager"/>--> diff --git a/addons/hr_timesheet_invoice/wizard/__init__.py b/addons/hr_timesheet_invoice/wizard/__init__.py index b3921b01008..6dce6a7b651 100644 --- a/addons/hr_timesheet_invoice/wizard/__init__.py +++ b/addons/hr_timesheet_invoice/wizard/__init__.py @@ -20,7 +20,7 @@ ############################################################################## import hr_timesheet_invoice_create -import account_analytic_profit +import hr_timesheet_analytic_profit import hr_timesheet_final_invoice_create import hr_timesheet_analytic_cost_ledger_report diff --git a/addons/hr_timesheet_invoice/wizard/account_analytic_profit.py b/addons/hr_timesheet_invoice/wizard/account_analytic_profit.py deleted file mode 100644 index 90861b6f5a9..00000000000 --- a/addons/hr_timesheet_invoice/wizard/account_analytic_profit.py +++ /dev/null @@ -1,99 +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 wizard -import datetime -import pooler -from tools.translate import _ - -form=''' -
- - - - -''' - -class wizard_report(wizard.interface): - def _date_from(*a): - return datetime.datetime.today().strftime('%Y-%m-1') - - def _date_to(*a): - return datetime.datetime.today().strftime('%Y-%m-%d') - - def _check(self, cr, uid, data, context): - pool = pooler.get_pool(cr.dbname) - line_obj = pool.get('account.analytic.line') - product_obj = pool.get('product.product') - price_obj = pool.get('product.pricelist') - ids = line_obj.search(cr, uid, [ - ('date', '>=', data['form']['date_from']), - ('date', '<=', data['form']['date_to']), - ('journal_id', 'in', data['form']['journal_ids'][0][2]), - ('user_id', 'in', data['form']['employee_ids'][0][2]), - ]) - if not ids: - raise wizard.except_wizard(_('Data Insufficient!'), _('No Records Found for Report!')) - - return data['form'] - - - fields={ - 'date_from':{ - 'string':'From', - 'type':'date', - 'required':True, - 'default':_date_from, - }, - 'date_to':{ - 'string':'To', - 'type':'date', - 'required':True, - 'default':_date_to, - }, - 'journal_ids':{ - 'string':'Journal', - 'type':'many2many', - 'relation':'account.analytic.journal', - 'required':True, - }, - 'employee_ids':{ - 'string':'Employee', - 'type':'many2many', - 'relation':'res.users', - 'required':True, - }, - } - - states={ - 'init':{ - 'actions':[], - 'result':{'type':'form', 'arch':form, 'fields':fields, 'state':[('end', 'Cancel', 'gtk-cancel'), ('report', 'Print', 'gtk-ok')]} - }, - 'report':{ - 'actions':[_check], - 'result':{'type':'print', 'report':'account.analytic.profit', 'state':'end'} - } - } -wizard_report('account.analytic.profit') - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit.py new file mode 100644 index 00000000000..f5b37256a02 --- /dev/null +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit.py @@ -0,0 +1,79 @@ +# -*- 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 datetime + +from osv import osv, fields +from tools.translate import _ + +class account_analytic_profit(osv.osv_memory): + _name = 'hr.timesheet.analytic.profit' + _description = 'Print Timesheet Profit' + _columns = { + 'date_from': fields.date('From', required=True), + 'date_to': fields.date('To', required=True), + 'journal_ids': fields.many2many('account.analytic.journal', 'analytic_profit_journal_rel', 'analytic_id', 'journal_id', 'Journal', required=True), + 'employee_ids': fields.many2many('res.users', 'analytic_profit_emp_rel', 'analytic_id', 'emp_id', 'Employee', required=True), + } + + def _date_from(*a): + return datetime.datetime.today().strftime('%Y-%m-1') + + def _date_to(*a): + return datetime.datetime.today().strftime('%Y-%m-%d') + + _defaults = { + 'date_from': _date_from, + 'date_to': _date_to + } + + def print_report(self, cr, uid, ids, context=None): + line_obj = self.pool.get('account.analytic.line') + product_obj = self.pool.get('product.product') + price_obj = self.pool.get('product.pricelist') + data = {} + data['form'] = self.read(cr, uid , ids, [], context=context)[0] + if context is None: + context = {} + ids_chk = line_obj.search(cr, uid, [ + ('date', '>=', data['form']['date_from']), + ('date', '<=', data['form']['date_to']), + ('journal_id', 'in', data['form']['journal_ids']), + ('user_id', 'in', data['form']['employee_ids']), + ]) + if not ids_chk: + raise osv.except_osv(_('Data Insufficient!'), _('No Records Found for Report!')) + + data['form']['journal_ids'] = [(6, 0, data['form']['journal_ids'])] # Improve me => Change the rml/sxw so that it can support withou [0][2] + data['form']['employee_ids'] = [(6, 0, data['form']['employee_ids'])] + datas = { + 'ids': [], + 'model': 'account.analytic.line', + 'form': data['form'] + } + return { + 'type': 'ir.actions.report.xml', + 'report_name': 'account.analytic.profit', + 'datas': datas, + } + +account_analytic_profit() + +# 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_analytic_profit_view.xml b/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit_view.xml new file mode 100644 index 00000000000..f79cae2eef8 --- /dev/null +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_analytic_profit_view.xml @@ -0,0 +1,40 @@ + + + + + + Timesheet Profit + hr.timesheet.analytic.profit + form + +
+ + + + + + + + +