diff options
| author | Vijaykumar Baladaniya <vba@tinyerp.com> | 2012-07-09 18:31:13 +0530 |
|---|---|---|
| committer | Vijaykumar Baladaniya <vba@tinyerp.com> | 2012-07-09 18:31:13 +0530 |
| commit | be2e95656aaa113addea2b510fcdcf2f890eaaa4 (patch) | |
| tree | abcb3dd4ef350a1b8ad0eaffdd2b9a1cb91521af /addons/analytic_contract_hr_expense | |
| parent | b982ea278b33132def3927417b7a854b98b5028a (diff) | |
| parent | 3925f76ce85854e5d4834902a05f57bcfc5ace85 (diff) | |
[MERGE]merged with trunk-survey-layout-tta
bzr revid: vba@tinyerp.com-20120709130113-3lchipgil9oqpglg
Diffstat (limited to 'addons/analytic_contract_hr_expense')
4 files changed, 289 insertions, 0 deletions
diff --git a/addons/analytic_contract_hr_expense/__init__.py b/addons/analytic_contract_hr_expense/__init__.py new file mode 100644 index 00000000000..ca4044b0584 --- /dev/null +++ b/addons/analytic_contract_hr_expense/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). +# +# 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 <http://www.gnu.org/licenses/>. +# +############################################################################## + +import analytic_contract_hr_expense + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/analytic_contract_hr_expense/__openerp__.py b/addons/analytic_contract_hr_expense/__openerp__.py new file mode 100644 index 00000000000..981f7226d6a --- /dev/null +++ b/addons/analytic_contract_hr_expense/__openerp__.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). +# +# 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 <http://www.gnu.org/licenses/>. +# +############################################################################## + + +{ + 'name': 'Contracts Management: hr_expense link', + 'version': '1.1', + 'category': 'Sales Management', + 'description': """ +This module is for modifying account analytic view to show some data related to the hr_expense module. +====================================================================================================== + +""", + "author": "OpenERP S.A.", + "website": "http://www.openerp.com/", + "depends": ["hr_expense","account_analytic_analysis"], + "init_xml": [], + "update_xml": [ + "analytic_contract_hr_expense_view.xml", + ], + 'demo_xml': [], + "css" : [ + ], + 'installable': True, + 'auto_install': True, + 'certificate': '', +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py new file mode 100644 index 00000000000..8f24f12808b --- /dev/null +++ b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). +# +# 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 <http://www.gnu.org/licenses/>. +# +############################################################################## + +from osv import osv, fields +from osv.orm import intersect, except_orm +import tools.sql +from tools.translate import _ +from decimal_precision import decimal_precision as dp + + +class account_analytic_account(osv.osv): + _name = "account.analytic.account" + _inherit = "account.analytic.account" + + def _get_total_estimation(self, account): + tot_est = super(account_analytic_account, self)._get_total_estimation(account) + if account.charge_expenses: + tot_est += account.est_expenses + return tot_est + + def _get_total_invoiced(self, account): + total_invoiced = super(account_analytic_account, self)._get_total_invoiced(account) + if account.charge_expenses: + total_invoiced += account.expense_invoiced + return total_invoiced + + def _get_total_remaining(self, account): + total_remaining = super(account_analytic_account, self)._get_total_remaining(account) + if account.charge_expenses: + total_remaining += account.remaining_expense + return total_remaining + + def _get_total_toinvoice(self, account): + total_toinvoice = super(account_analytic_account, self)._get_total_toinvoice(account) + if account.charge_expenses: + total_toinvoice += account.expense_to_invoice + return total_toinvoice + + def _remaining_expnse_calc(self, cr, uid, ids, name, arg, context=None): + res = {} + for account in self.browse(cr, uid, ids, context=context): + if account.est_expenses != 0: + res[account.id] = max(account.est_expenses - account.expense_invoiced, account.expense_to_invoice) + else: + res[account.id]=0.0 + return res + + def _expense_to_invoice_calc(self, cr, uid, ids, name, arg, context=None): + res = {} + res_final = {} + child_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy. + for i in child_ids: + res[i] = 0.0 + if not child_ids: + return res + + if child_ids: + cr.execute("""SELECT account_analytic_account.id, \ + COALESCE(SUM (product_template.list_price * \ + account_analytic_line.unit_amount * \ + ((100-hr_timesheet_invoice_factor.factor)/100)), 0.0) \ + AS ca_to_invoice \ + FROM product_template \ + JOIN product_product \ + ON product_template.id = product_product.product_tmpl_id \ + JOIN account_analytic_line \ + ON account_analytic_line.product_id = product_product.id \ + JOIN account_analytic_journal \ + ON account_analytic_line.journal_id = account_analytic_journal.id \ + JOIN account_analytic_account \ + ON account_analytic_account.id = account_analytic_line.account_id \ + JOIN hr_timesheet_invoice_factor \ + ON hr_timesheet_invoice_factor.id = account_analytic_account.to_invoice \ + WHERE account_analytic_account.id IN %s \ + AND account_analytic_line.invoice_id IS NULL \ + AND account_analytic_line.to_invoice IS NOT NULL \ + AND account_analytic_journal.type = 'purchase' \ + GROUP BY account_analytic_account.id;""",(child_ids,)) + for account_id, sum in cr.fetchall(): + res[account_id] = sum + res_final = res + return res_final + + def _expense_invoiced_calc(self, cr, uid, ids, name, arg, context=None): + lines_obj = self.pool.get('account.analytic.line') + res = {} + for account in self.browse(cr, uid, ids, context=context): + res[account.id] = 0.0 + line_ids = lines_obj.search(cr, uid, [('account_id','=', account.id), ('invoice_id','!=',False), ('to_invoice','!=', False), ('journal_id.type', '=', 'purchase')], context=context) + for line in lines_obj.browse(cr, uid, line_ids, context=context): + res[account.id] += line.invoice_id.amount_untaxed + return res + + + _columns = { + 'charge_expenses' : fields.boolean('Charge Expenses'), + 'expense_invoiced' : fields.function(_expense_invoiced_calc, type="float"), + 'expense_to_invoice' : fields.function(_expense_to_invoice_calc, type='float'), + 'remaining_expense' : fields.function(_remaining_expnse_calc, type="float"), + 'est_expenses': fields.float('Estimation of Expenses to Invoice'), + } + + def on_change_template(self, cr, uid, id, template_id, context=None): + res = super(account_analytic_account, self).on_change_template(cr, uid, id, template_id, context=context) + if template_id and 'value' in res: + template = self.browse(cr, uid, template_id, context=context) + res['value']['charge_expenses'] = template.charge_expenses + res['value']['est_expenses'] = template.est_expenses + return res + + def open_hr_expense(self, cr, uid, ids, context=None): + line_ids = self.pool.get('hr.expense.line').search(cr,uid,[('analytic_account', 'in', ids)]) + domain = [('line_ids', 'in', line_ids)] + names = [record.name for record in self.browse(cr, uid, ids, context=context)] + name = _('Expenses of %s') % ','.join(names) + return { + 'type': 'ir.actions.act_window', + 'name': name, + 'view_type': 'form', + 'view_mode': 'tree,form', + 'domain' : domain, + 'res_model': 'hr.expense.expense', + 'nodestroy': True, + } + + def hr_to_invoice_expense(self, cr, uid, ids, context=None): + domain = [('invoice_id','=',False),('to_invoice','!=',False), ('journal_id.type', '=', 'purchase'), ('account_id', 'in', ids)] + names = [record.name for record in self.browse(cr, uid, ids, context=context)] + name = _('Expenses to Invoice of %s') % ','.join(names) + return { + 'type': 'ir.actions.act_window', + 'name': name, + 'view_type': 'form', + 'view_mode': 'tree,form', + 'domain' : domain, + 'res_model': 'account.analytic.line', + 'nodestroy': True, + } + +account_analytic_account() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/analytic_contract_hr_expense/analytic_contract_hr_expense_view.xml b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense_view.xml new file mode 100644 index 00000000000..0148c05d0b4 --- /dev/null +++ b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense_view.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + <record id="account_analytic_account_form_expense_form" model="ir.ui.view"> + <field name="name">account.analytic.account.form.expense.inherit</field> + <field name="model">account.analytic.account</field> + <field name="type">form</field> + <field eval="60" name="priority"/> + <field name="arch" type="xml"> + <xpath expr='//tr[@name="total"]' position='before'> + <tr> + <td> + <label for="charge_expenses"/> + </td><td> + <field name="charge_expenses"/> + </td><td> + <field class="oe_form_inline" name="est_expenses" attrs="{'invisible': [('charge_expenses','=',False)]}"/> + </td><td> + <field class="oe_form_inline" name="expense_invoiced" attrs="{'invisible': [('charge_expenses','=',False)]}"/> + </td><td> + <field class="oe_form_inline" name="remaining_expense" attrs="{'invisible': [('charge_expenses','=',False)]}"/> + </td><td> + <field class="oe_form_inline" name="expense_to_invoice" attrs="{'invisible': [('charge_expenses','=',False)]}"/> + </td><td> + <group> + <button name="open_hr_expense" string="All Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',False)]}"/> + <button name="hr_to_invoice_expense" string="Expenses to Invoice" type="object" attrs="{'invisible': [('charge_expenses','=',False)]}"/> + </group> + </td> + </tr> + </xpath> + </field> + </record> + + <!--<record id="project_form_expense_form" model="ir.ui.view"> + <field name="name">project.project.form.expense.inherit</field> + <field name="model">project.project</field> + <field name="type">form</field> + <field name="inherit_id" ref="analytic_contract_project.project_account_analytic_account_form"/> + <field eval="20" name="priority"/> + <field name="arch" type="xml"> + <xpath expr='//div[@name="end_of_tabl_hook"]' position='before'> + <tr> + <th class="oe_border_right">Charge Expenses</th> + <td><field name="charge_expenses" nolabel="1"/></td> + <td><field class="oe_th_110px" name="est_expenses" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td> + <td class="oe_th_110px"><field name="expense_invoiced" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td> + <td class="oe_th_110px oe_border_right"><field name="remaining_expense" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td> + <td class="oe_th_110px"><field name="expense_to_invoice" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td> + <td width="10px"></td> + <td><button icon="gtk-select-all" class= "oe_btn_width" name="open_hr_expense" string="Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td> + <td><button icon="terp-dolar" class= "oe_btn_width" name="hr_to_invoiced_expense" string="Invoice Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td> + </tr> + </xpath> + </field> + </record>--> + </data> +</openerp> |
