From 4ecf6fef06226e3841ce449e408d65a68675ad7c Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Wed, 11 Jul 2012 18:43:47 +0530 Subject: [PATCH 01/40] [IMP] hr_expense : After the confirmation of the expense, the button should create an account.voucher (instead of an invoice) and confirmed it. It must creates the accounting entries exactly as the current invoice does. bzr revid: mdi@tinyerp.com-20120711131347-4uj73ojgrrfcdjd1 --- addons/hr_expense/__openerp__.py | 2 +- addons/hr_expense/hr_expense.py | 83 +++++++++---------- addons/hr_expense/hr_expense_view.xml | 2 +- addons/hr_expense/hr_expense_workflow.xml | 6 +- addons/hr_expense/report/hr_expense_report.py | 8 +- .../report/hr_expense_report_view.xml | 2 +- 6 files changed, 47 insertions(+), 56 deletions(-) diff --git a/addons/hr_expense/__openerp__.py b/addons/hr_expense/__openerp__.py index 2a1d302e094..d0265372b0c 100644 --- a/addons/hr_expense/__openerp__.py +++ b/addons/hr_expense/__openerp__.py @@ -43,7 +43,7 @@ re-invoice your customer's expenses if your work by project. 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', 'images': ['images/hr_expenses_analysis.jpeg', 'images/hr_expenses.jpeg'], - 'depends': ['hr', 'account'], + 'depends': ['hr', 'account_voucher'], 'init_xml': [], 'update_xml': [ 'security/ir.model.access.csv', diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index b1192701dfb..d5f816268cb 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -73,7 +73,7 @@ class hr_expense_expense(osv.osv): 'line_ids': fields.one2many('hr.expense.line', 'expense_id', 'Expense Lines', readonly=True, states={'draft':[('readonly',False)]} ), 'note': fields.text('Note'), 'amount': fields.function(_amount, string='Total Amount'), - 'invoice_id': fields.many2one('account.invoice', "Employee's Invoice"), + 'voucher_id': fields.many2one('account.voucher', "Employee's Voucher"), 'currency_id': fields.many2one('res.currency', 'Currency', required=True), 'department_id':fields.many2one('hr.department','Department'), 'company_id': fields.many2one('res.company', 'Company', required=True), @@ -131,95 +131,86 @@ class hr_expense_expense(osv.osv): return True def invoice(self, cr, uid, ids, context=None): - wf_service = netsvc.LocalService("workflow") mod_obj = self.pool.get('ir.model.data') - res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_supplier_form') - inv_ids = [] + wkf_service = netsvc.LocalService("workflow") + + if not ids: return [] + exp = self.browse(cr, uid, ids[0], context=context) + + voucher_ids = [] for id in ids: - wf_service.trg_validate(uid, 'hr.expense.expense', id, 'invoice', cr) - inv_ids.append(self.browse(cr, uid, id).invoice_id.id) + wkf_service.trg_validate(uid, 'hr.expense.expense', id, 'invoice', cr) + voucher_ids.append(self.browse(cr, uid, id, context=context).voucher_id.id) + res = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_purchase_receipt_form') + res_id = res and res[1] or False return { - 'name': _('Supplier Invoices'), 'view_type': 'form', 'view_mode': 'form', - 'view_id': [res and res[1] or False], - 'res_model': 'account.invoice', - 'context': "{'type':'out_invoice', 'journal_type': 'purchase'}", + 'res_model': 'account.voucher', + 'views': [(res_id, 'form')], + 'view_id': res_id, 'type': 'ir.actions.act_window', + 'target': 'new', 'nodestroy': True, - 'target': 'current', - 'res_id': inv_ids and inv_ids[0] or False, + 'res_id': voucher_ids and voucher_ids[0] or False, + 'close_after_process': True, } - - def action_invoice_create(self, cr, uid, ids): + def action_voucher_create(self, cr, uid, ids, context=None): res = False invoice_obj = self.pool.get('account.invoice') property_obj = self.pool.get('ir.property') sequence_obj = self.pool.get('ir.sequence') - analytic_journal_obj = self.pool.get('account.analytic.journal') account_journal = self.pool.get('account.journal') - for exp in self.browse(cr, uid, ids): + voucher_obj = self.pool.get('account.voucher') + + for exp in self.browse(cr, uid, ids, context=None): company_id = exp.company_id.id lines = [] + total = 0.0 for l in exp.line_ids: - tax_id = [] if l.product_id: acc = l.product_id.product_tmpl_id.property_account_expense if not acc: acc = l.product_id.categ_id.property_account_expense_categ - tax_id = [x.id for x in l.product_id.supplier_taxes_id] else: acc = property_obj.get(cr, uid, 'property_account_expense_categ', 'product.category', context={'force_company': company_id}) if not acc: raise osv.except_osv(_('Error !'), _('Please configure Default Expense account for Product purchase, `property_account_expense_categ`')) + lines.append((0, False, { 'name': l.name, 'account_id': acc.id, - 'price_unit': l.unit_amount, - 'quantity': l.unit_quantity, - 'uos_id': l.uom_id.id, - 'product_id': l.product_id and l.product_id.id or False, - 'invoice_line_tax_id': tax_id and [(6, 0, tax_id)] or False, - 'account_analytic_id': l.analytic_account.id, + 'amount': l.unit_amount, + 'type': 'dr' })) + total += l.unit_amount if not exp.employee_id.address_home_id: raise osv.except_osv(_('Error !'), _('The employee must have a Home address.')) acc = exp.employee_id.address_home_id.property_account_payable.id - payment_term_id = exp.employee_id.address_home_id.property_payment_term.id - inv = { + voucher = { 'name': exp.name, - 'reference': sequence_obj.get(cr, uid, 'hr.expense.invoice'), + 'number': sequence_obj.get(cr, uid, 'hr.expense.invoice'), 'account_id': acc, - 'type': 'in_invoice', + 'type': 'purchase', 'partner_id': exp.employee_id.address_home_id.id, 'company_id': company_id, - 'origin': exp.name, - 'invoice_line': lines, + # 'origin': exp.name, + 'line_ids': lines, 'currency_id': exp.currency_id.id, - 'payment_term': payment_term_id, - 'fiscal_position': exp.employee_id.address_home_id.property_account_position.id + 'amount': total } - if payment_term_id: - to_update = invoice_obj.onchange_payment_term_date_invoice(cr, uid, [], payment_term_id, None) - if to_update: - inv.update(to_update['value']) journal = False if exp.journal_id: - inv['journal_id']=exp.journal_id.id + voucher['journal_id'] = exp.journal_id.id journal = exp.journal_id else: journal_id = invoice_obj._get_journal(cr, uid, context={'type': 'in_invoice', 'company_id': company_id}) if journal_id: - inv['journal_id'] = journal_id + voucher['journal_id'] = journal_id journal = account_journal.browse(cr, uid, journal_id) - if journal and not journal.analytic_journal_id: - analytic_journal_ids = analytic_journal_obj.search(cr, uid, [('type','=','purchase')]) - if analytic_journal_ids: - account_journal.write(cr, uid, [journal.id],{'analytic_journal_id':analytic_journal_ids[0]}) - inv_id = invoice_obj.create(cr, uid, inv, {'type': 'in_invoice'}) - invoice_obj.button_compute(cr, uid, [inv_id], {'type': 'in_invoice'}, set_total=True) - self.write(cr, uid, [exp.id], {'invoice_id': inv_id, 'state': 'invoiced'}) - res = inv_id + voucher_id = voucher_obj.create(cr, uid, voucher, context) + aaa = self.write(cr, uid, [exp.id], {'voucher_id': voucher_id, 'state': 'invoiced'}) + res = voucher_id return res hr_expense_expense() diff --git a/addons/hr_expense/hr_expense_view.xml b/addons/hr_expense/hr_expense_view.xml index b8868c3319f..f5967c39e21 100644 --- a/addons/hr_expense/hr_expense_view.xml +++ b/addons/hr_expense/hr_expense_view.xml @@ -116,7 +116,7 @@ - + diff --git a/addons/hr_expense/hr_expense_workflow.xml b/addons/hr_expense/hr_expense_workflow.xml index 328a07879a4..730e6d21e5d 100644 --- a/addons/hr_expense/hr_expense_workflow.xml +++ b/addons/hr_expense/hr_expense_workflow.xml @@ -51,8 +51,8 @@ invoice subflow - - action_invoice_create() + + action_voucher_create() @@ -99,7 +99,7 @@ - subflow.paid + subflow.done diff --git a/addons/hr_expense/report/hr_expense_report.py b/addons/hr_expense/report/hr_expense_report.py index adef11f5269..52f155a8e9e 100644 --- a/addons/hr_expense/report/hr_expense_report.py +++ b/addons/hr_expense/report/hr_expense_report.py @@ -43,7 +43,7 @@ class hr_expense_report(osv.osv): 'employee_id': fields.many2one('hr.employee', "Employee's Name", readonly=True), 'date_confirm': fields.date('Confirmation Date', readonly=True), 'date_valid': fields.date('Validation Date', readonly=True), - 'invoice_id': fields.many2one('account.invoice', 'Invoice', readonly=True), + 'voucher_id': fields.many2one('account.voucher', 'Voucher', readonly=True), 'department_id':fields.many2one('hr.department','Department', readonly=True), 'company_id':fields.many2one('res.company', 'Company', readonly=True), 'user_id':fields.many2one('res.users', 'Validation User', readonly=True), @@ -78,8 +78,8 @@ class hr_expense_report(osv.osv): s.currency_id, to_date(to_char(s.date_confirm, 'dd-MM-YYYY'),'dd-MM-YYYY') as date_confirm, to_date(to_char(s.date_valid, 'dd-MM-YYYY'),'dd-MM-YYYY') as date_valid, - s.invoice_id, - count(s.invoice_id) as invoiced, + s.voucher_id, + count(s.voucher_id) as invoiced, s.user_valid as user_id, s.department_id, to_char(date_trunc('day',s.create_date), 'YYYY') as year, @@ -109,7 +109,7 @@ class hr_expense_report(osv.osv): to_date(to_char(s.date_valid, 'dd-MM-YYYY'),'dd-MM-YYYY'), l.product_id, l.analytic_account, - s.invoice_id, + s.voucher_id, s.currency_id, s.user_valid, s.department_id, diff --git a/addons/hr_expense/report/hr_expense_report_view.xml b/addons/hr_expense/report/hr_expense_report_view.xml index 7877edf4b3a..bfd73f8ed7d 100644 --- a/addons/hr_expense/report/hr_expense_report_view.xml +++ b/addons/hr_expense/report/hr_expense_report_view.xml @@ -13,7 +13,7 @@ - + From 7ceed2bb9b25b516caa5128c21fab424a797dbc0 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Thu, 12 Jul 2012 12:24:55 +0530 Subject: [PATCH 02/40] [IMP] hr_expense : Improved the test cases in accordance with voucher. bzr revid: mdi@tinyerp.com-20120712065455-0xhhss2jcoo4cyxp --- addons/hr_expense/hr_expense.py | 2 +- addons/hr_expense/test/expense_process.yml | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index d5f816268cb..5c8aed03d79 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -183,7 +183,7 @@ class hr_expense_expense(osv.osv): 'amount': l.unit_amount, 'type': 'dr' })) - total += l.unit_amount + total += l.total_amount if not exp.employee_id.address_home_id: raise osv.except_osv(_('Error !'), _('The employee must have a Home address.')) acc = exp.employee_id.address_home_id.property_account_payable.id diff --git a/addons/hr_expense/test/expense_process.yml b/addons/hr_expense/test/expense_process.yml index 5c8a9d53f7c..2f8fffb786d 100644 --- a/addons/hr_expense/test/expense_process.yml +++ b/addons/hr_expense/test/expense_process.yml @@ -17,22 +17,20 @@ !assert {model: hr.expense.expense, id: sep_expenses, severity: error, string: Expense should be in Approved state}: - state == 'accepted' - - I make Invoice for the expense. + I make Voucher for the expense. - !python {model: hr.expense.expense}: | self.invoice(cr, uid, [ref('sep_expenses')]) - - I check invoice details. + I check voucher details. - !python {model: hr.expense.expense}: | sep_expenses = self.browse(cr, uid, ref("sep_expenses"), context=context) assert sep_expenses.state == 'invoiced', "Expense should be in 'Invoiced' state." - assert sep_expenses.invoice_id, "Expense should have link of Invoice." - assert sep_expenses.invoice_id.currency_id == sep_expenses.currency_id,"Invoice currency is not correspond with supplier invoice currency" - assert sep_expenses.invoice_id.origin == sep_expenses.name,"Invoice origin is not correspond with supplier invoice" - assert sep_expenses.invoice_id.type == 'in_invoice', "Invoice type is not supplier invoice" - assert sep_expenses.invoice_id.amount_total == sep_expenses.amount,"Invoice total amount is not correspond with supplier invoice total" - assert len(sep_expenses.invoice_id.invoice_line) == len(sep_expenses.line_ids),"Lines of Invoice and supplier invoice Line are not correspond" + assert sep_expenses.voucher_id.name == sep_expenses.name,"Voucher name is not correspond with expense name." + assert sep_expenses.voucher_id.type == 'purchase', "Voucher type is not purchase voucher." + assert sep_expenses.voucher_id.amount == sep_expenses.amount,"Voucher total amount is not correspond with expense total." + assert len(sep_expenses.voucher_id.line_dr_ids) == len(sep_expenses.line_ids),"Lines of Voucher and expense line are not correspond." #TODO: check invoice line details with Expenses lines - I pay the expenses. From 3512fd1be0b0aa640b8969e37de3348624c23828 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Thu, 12 Jul 2012 14:14:07 +0530 Subject: [PATCH 03/40] [IMP] hr_expense : Added 'Total Amount' field in form view. bzr revid: mdi@tinyerp.com-20120712084407-s78a0udwp3ww4npd --- addons/hr_expense/hr_expense_view.xml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/hr_expense/hr_expense_view.xml b/addons/hr_expense/hr_expense_view.xml index f5967c39e21..a143a746667 100644 --- a/addons/hr_expense/hr_expense_view.xml +++ b/addons/hr_expense/hr_expense_view.xml @@ -109,8 +109,15 @@ - - + +
+ + +
+ + + +
From 85cf7c94fd69de1fd8bedbeba85ff7920709010d Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Thu, 12 Jul 2012 14:18:25 +0530 Subject: [PATCH 04/40] [IMP] hr_expense : Improved the code. bzr revid: mdi@tinyerp.com-20120712084825-enistrb9u1fum2at --- addons/hr_expense/hr_expense.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index 5c8aed03d79..3b8129914f3 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -180,7 +180,7 @@ class hr_expense_expense(osv.osv): lines.append((0, False, { 'name': l.name, 'account_id': acc.id, - 'amount': l.unit_amount, + 'amount': l.total_amount, 'type': 'dr' })) total += l.total_amount @@ -196,7 +196,6 @@ class hr_expense_expense(osv.osv): 'company_id': company_id, # 'origin': exp.name, 'line_ids': lines, - 'currency_id': exp.currency_id.id, 'amount': total } journal = False From a4e5ec5ce20ed54f5bdb7f71b948ffea90096ca9 Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Thu, 12 Jul 2012 15:16:45 +0530 Subject: [PATCH 05/40] [IMP] hr_recruitment : Opens the purchase receipt form on voucher_id field. bzr revid: mdi@tinyerp.com-20120712094645-4m86lvzxz4d4wjmx --- addons/account_voucher/voucher_sales_purchase_view.xml | 2 +- addons/hr_expense/hr_expense_view.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account_voucher/voucher_sales_purchase_view.xml b/addons/account_voucher/voucher_sales_purchase_view.xml index adb078fac22..2c3399da31c 100644 --- a/addons/account_voucher/voucher_sales_purchase_view.xml +++ b/addons/account_voucher/voucher_sales_purchase_view.xml @@ -222,7 +222,7 @@ account.voucher form -
+
diff --git a/addons/hr_expense/hr_expense_workflow.xml b/addons/hr_expense/hr_expense_workflow.xml index 730e6d21e5d..58eed45b1d2 100644 --- a/addons/hr_expense/hr_expense_workflow.xml +++ b/addons/hr_expense/hr_expense_workflow.xml @@ -47,12 +47,12 @@ expense_canceled() - + - invoice + receipt subflow - action_voucher_create() + action_receipt_create() @@ -91,13 +91,13 @@ - - invoice + + receipt - + subflow.done diff --git a/addons/hr_expense/test/expense_process.yml b/addons/hr_expense/test/expense_process.yml index 2f8fffb786d..0ddbca537bf 100644 --- a/addons/hr_expense/test/expense_process.yml +++ b/addons/hr_expense/test/expense_process.yml @@ -20,18 +20,18 @@ I make Voucher for the expense. - !python {model: hr.expense.expense}: | - self.invoice(cr, uid, [ref('sep_expenses')]) + self.receipt(cr, uid, [ref('sep_expenses')]) - I check voucher details. - !python {model: hr.expense.expense}: | sep_expenses = self.browse(cr, uid, ref("sep_expenses"), context=context) - assert sep_expenses.state == 'invoiced', "Expense should be in 'Invoiced' state." + assert sep_expenses.state == 'receipted', "Expense should be in 'Receipted' state." assert sep_expenses.voucher_id.name == sep_expenses.name,"Voucher name is not correspond with expense name." assert sep_expenses.voucher_id.type == 'purchase', "Voucher type is not purchase voucher." assert sep_expenses.voucher_id.amount == sep_expenses.amount,"Voucher total amount is not correspond with expense total." assert len(sep_expenses.voucher_id.line_dr_ids) == len(sep_expenses.line_ids),"Lines of Voucher and expense line are not correspond." - #TODO: check invoice line details with Expenses lines + - I pay the expenses. - From 0fee0b9527a0e46bc55e04570a9570df4e4b174b Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Fri, 13 Jul 2012 17:17:17 +0530 Subject: [PATCH 10/40] [IMP] hr_expense : Improved the code. bzr revid: mdi@tinyerp.com-20120713114717-1gg9xygu4ut3nl64 --- addons/hr_expense/hr_expense.py | 20 ++++++++++---------- addons/hr_expense/test/expense_process.yml | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index d4c2dfbbf7d..0e413c8e1fe 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -146,7 +146,7 @@ class hr_expense_expense(osv.osv): res = mod_obj.get_object_reference(cr, uid, 'account_voucher', 'view_purchase_receipt_form') res_id = res and res[1] or False return { - 'name': _('Purchase Receipt'), + 'name': _('Expense Receipt'), 'view_type': 'form', 'view_mode': 'form', 'res_model': 'account.voucher', @@ -169,23 +169,23 @@ class hr_expense_expense(osv.osv): company_id = exp.company_id.id lines = [] total = 0.0 - for l in exp.line_ids: - if l.product_id: - acc = l.product_id.product_tmpl_id.property_account_expense + for line in exp.line_ids: + if line.product_id: + acc = line.product_id.product_tmpl_id.property_account_expense if not acc: - acc = l.product_id.categ_id.property_account_expense_categ + acc = line.product_id.categ_id.property_account_expense_categ else: acc = property_obj.get(cr, uid, 'property_account_expense_categ', 'product.category', context={'force_company': company_id}) if not acc: raise osv.except_osv(_('Error !'), _('Please configure Default Expense account for Product purchase, `property_account_expense_categ`')) lines.append((0, False, { - 'name': l.name, + 'name': line.name, 'account_id': acc.id, - 'amount': l.total_amount, + 'amount': line.total_amount, 'type': 'dr' })) - total += l.total_amount + total += line.total_amount if not exp.employee_id.address_home_id: raise osv.except_osv(_('Error !'), _('The employee must have a Home address.')) acc = exp.employee_id.address_home_id.property_account_payable.id @@ -207,9 +207,9 @@ class hr_expense_expense(osv.osv): journal_id = voucher_obj._get_journal(cr, uid, context={'type': 'purchase', 'company_id': company_id}) if journal_id: voucher['journal_id'] = journal_id - journal = account_journal.browse(cr, uid, journal_id) + journal = account_journal.browse(cr, uid, journal_id, context=context) voucher_id = voucher_obj.create(cr, uid, voucher, context) - self.write(cr, uid, [exp.id], {'voucher_id': voucher_id, 'state': 'receipted'}) + self.write(cr, uid, [exp.id], {'voucher_id': voucher_id, 'state': 'receipted'}, context=context) res = voucher_id return res diff --git a/addons/hr_expense/test/expense_process.yml b/addons/hr_expense/test/expense_process.yml index 0ddbca537bf..65359de95ff 100644 --- a/addons/hr_expense/test/expense_process.yml +++ b/addons/hr_expense/test/expense_process.yml @@ -17,20 +17,20 @@ !assert {model: hr.expense.expense, id: sep_expenses, severity: error, string: Expense should be in Approved state}: - state == 'accepted' - - I make Voucher for the expense. + I make Receipt for the expense. - !python {model: hr.expense.expense}: | self.receipt(cr, uid, [ref('sep_expenses')]) - - I check voucher details. + I check receipt details. - !python {model: hr.expense.expense}: | sep_expenses = self.browse(cr, uid, ref("sep_expenses"), context=context) assert sep_expenses.state == 'receipted', "Expense should be in 'Receipted' state." - assert sep_expenses.voucher_id.name == sep_expenses.name,"Voucher name is not correspond with expense name." - assert sep_expenses.voucher_id.type == 'purchase', "Voucher type is not purchase voucher." - assert sep_expenses.voucher_id.amount == sep_expenses.amount,"Voucher total amount is not correspond with expense total." - assert len(sep_expenses.voucher_id.line_dr_ids) == len(sep_expenses.line_ids),"Lines of Voucher and expense line are not correspond." + assert sep_expenses.voucher_id.name == sep_expenses.name,"Receipt name is not correspond with expense name." + assert sep_expenses.voucher_id.type == 'purchase', "Receipt type is not purchase receipt." + assert sep_expenses.voucher_id.amount == sep_expenses.amount,"Receipt total amount is not correspond with expense total." + assert len(sep_expenses.voucher_id.line_dr_ids) == len(sep_expenses.line_ids),"Lines of Receipt and expense line are not correspond." - I pay the expenses. From e068186c172120a210c0a3bd1194ccf0f95f19ea Mon Sep 17 00:00:00 2001 From: "Divyesh Makwana (Open ERP)" Date: Fri, 13 Jul 2012 18:09:52 +0530 Subject: [PATCH 11/40] [IMP] hr_improvement : Added 'Open Receipt' button to open the receipt in 'receipted' state. bzr revid: mdi@tinyerp.com-20120713123952-gr48p943v6rjon57 --- addons/hr_expense/hr_expense.py | 19 +++++++++++++++++++ addons/hr_expense/hr_expense_view.xml | 1 + 2 files changed, 20 insertions(+) diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index 0e413c8e1fe..ee2c92cf483 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -212,6 +212,25 @@ class hr_expense_expense(osv.osv): self.write(cr, uid, [exp.id], {'voucher_id': voucher_id, 'state': 'receipted'}, context=context) res = voucher_id return res + + def action_view_receipt(self, cr, uid, ids, context=None): + ''' + This function returns an action that display existing receipt of given expense ids. + ''' + voucher_id = self.browse(cr, uid, ids[0], context=context).voucher_id.id + res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_voucher', 'view_purchase_receipt_form') + result = { + 'name': _('Expense Receipt'), + 'view_type': 'form', + 'view_mode': 'form', + 'view_id': res and res[1] or False, + 'res_model': 'account.voucher', + 'type': 'ir.actions.act_window', + 'nodestroy': True, + 'target': 'current', + 'res_id': voucher_id, + } + return result hr_expense_expense() diff --git a/addons/hr_expense/hr_expense_view.xml b/addons/hr_expense/hr_expense_view.xml index c45c743c1c8..78fa22db4d4 100644 --- a/addons/hr_expense/hr_expense_view.xml +++ b/addons/hr_expense/hr_expense_view.xml @@ -69,6 +69,7 @@