From d2f12bd8151588f31c60fd03b5cc07f63730502a Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 23 Apr 2018 09:54:32 -0700 Subject: [PATCH 1/6] Initial commit `hr_expense_vendor` for 11.0 --- hr_expense_vendor/__init__.py | 1 + hr_expense_vendor/__manifest__.py | 19 ++++++++++ hr_expense_vendor/models/__init__.py | 1 + hr_expense_vendor/models/hr_expense.py | 24 ++++++++++++ hr_expense_vendor/tests/__init__.py | 1 + hr_expense_vendor/tests/test_expenses.py | 40 ++++++++++++++++++++ hr_expense_vendor/views/hr_expense_views.xml | 26 +++++++++++++ 7 files changed, 112 insertions(+) create mode 100644 hr_expense_vendor/__init__.py create mode 100644 hr_expense_vendor/__manifest__.py create mode 100644 hr_expense_vendor/models/__init__.py create mode 100644 hr_expense_vendor/models/hr_expense.py create mode 100644 hr_expense_vendor/tests/__init__.py create mode 100644 hr_expense_vendor/tests/test_expenses.py create mode 100644 hr_expense_vendor/views/hr_expense_views.xml diff --git a/hr_expense_vendor/__init__.py b/hr_expense_vendor/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/hr_expense_vendor/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_expense_vendor/__manifest__.py b/hr_expense_vendor/__manifest__.py new file mode 100644 index 00000000..dee0c40e --- /dev/null +++ b/hr_expense_vendor/__manifest__.py @@ -0,0 +1,19 @@ +{ + 'name': 'HR Expense Vendor', + 'version': '11.0.1.0.0', + 'author': 'Hibou Corp. ', + 'category': 'Human Resources', + 'summary': 'Record the vendor paid on expenses.', + 'description': """ +Record the vendor paid on expenses. +""", + 'website': 'https://hibou.io/', + 'depends': [ + 'hr_expense', + ], + 'data': [ + 'views/hr_expense_views.xml', + ], + 'installable': True, + 'auto_install': False, +} diff --git a/hr_expense_vendor/models/__init__.py b/hr_expense_vendor/models/__init__.py new file mode 100644 index 00000000..86b1ea31 --- /dev/null +++ b/hr_expense_vendor/models/__init__.py @@ -0,0 +1 @@ +from . import hr_expense diff --git a/hr_expense_vendor/models/hr_expense.py b/hr_expense_vendor/models/hr_expense.py new file mode 100644 index 00000000..e2ef8b8e --- /dev/null +++ b/hr_expense_vendor/models/hr_expense.py @@ -0,0 +1,24 @@ +from odoo import api, fields, models +from odoo.exceptions import ValidationError + + +class HRExpense(models.Model): + _inherit = 'hr.expense' + + vendor_id = fields.Many2one('res.partner', string='Vendor') + + def _prepare_move_line(self, line): + values = super(HRExpense, self)._prepare_move_line(line) + if self.payment_mode == 'company_account': + if not self.vendor_id: + raise ValidationError('You must have an assigned vendor to process a Company Paid Expense') + values['partner_id'] = self.vendor_id.id + name = values['name'] + (' - ' + str(self.reference) if self.reference else '') + values['name'] = name[:64] + return values + + +class HRExpenseSheet(models.Model): + _inherit = 'hr.expense.sheet' + + expense_line_ids = fields.One2many(states={'done': [('readonly', True)], 'post': [('readonly', True)]}) diff --git a/hr_expense_vendor/tests/__init__.py b/hr_expense_vendor/tests/__init__.py new file mode 100644 index 00000000..bf77393e --- /dev/null +++ b/hr_expense_vendor/tests/__init__.py @@ -0,0 +1 @@ +from . import test_expenses diff --git a/hr_expense_vendor/tests/test_expenses.py b/hr_expense_vendor/tests/test_expenses.py new file mode 100644 index 00000000..2cceb774 --- /dev/null +++ b/hr_expense_vendor/tests/test_expenses.py @@ -0,0 +1,40 @@ +from odoo.addons.hr_expense.tests.test_expenses import TestCheckJournalEntry +from odoo.exceptions import ValidationError + + +class TestCheckVendor(TestCheckJournalEntry): + + def setUp(self): + super(TestCheckVendor, self).setUp() + self.vendor_id = self.env.ref('base.res_partner_3') + + def test_journal_entry_vendor(self): + # Non company_account is handled by the super class's `test_journal_entry_ + self.expense.payment_mode = 'company_account' + self.expense_line.payment_mode = 'company_account' + + # Submitted to Manager + self.assertEquals(self.expense.state, 'submit', 'Expense is not in Reported state') + # Approve + self.expense.approve_expense_sheets() + self.assertEquals(self.expense.state, 'approve', 'Expense is not in Approved state') + # Create Expense Entries + with self.assertRaises(ValidationError): + self.expense.action_sheet_move_create() + + self.expense_line.vendor_id = self.vendor_id + self.expense.action_sheet_move_create() + self.assertEquals(self.expense.state, 'done') + self.assertTrue(self.expense.account_move_id.id, 'Expense Journal Entry is not created') + + # [(line.debit, line.credit, line.tax_line_id.id) for line in self.expense.expense_line_ids.account_move_id.line_ids] + # should git this result [(0.0, 700.0, False), (63.64, 0.0, 179), (636.36, 0.0, False)] + for line in self.expense.account_move_id.line_ids: + if line.credit: + self.assertEqual(line.partner_id, self.vendor_id) + self.assertAlmostEquals(line.credit, 700.00) + else: + if not line.tax_line_id == self.tax: + self.assertAlmostEquals(line.debit, 636.36) + else: + self.assertAlmostEquals(line.debit, 63.64) diff --git a/hr_expense_vendor/views/hr_expense_views.xml b/hr_expense_vendor/views/hr_expense_views.xml new file mode 100644 index 00000000..9038e8ec --- /dev/null +++ b/hr_expense_vendor/views/hr_expense_views.xml @@ -0,0 +1,26 @@ + + + + hr.expense.sheet.form.inherit + hr.expense.sheet + + + + + + + + + + hr.expense.form.inherit + hr.expense + + + + + + + + \ No newline at end of file From 641a16f878b5f19abe72d04d74622b4c601119f9 Mon Sep 17 00:00:00 2001 From: Kristen Marie Kulha Date: Fri, 8 Jun 2018 15:09:45 -0700 Subject: [PATCH 2/6] Add README. --- hr_expense_vendor/README.rst | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 hr_expense_vendor/README.rst diff --git a/hr_expense_vendor/README.rst b/hr_expense_vendor/README.rst new file mode 100644 index 00000000..e702d50b --- /dev/null +++ b/hr_expense_vendor/README.rst @@ -0,0 +1,30 @@ +************************* +Hibou - HR Expense Vendor +************************* + +Records the vendor paid on expenses. + +For more information and add-ons, visit `Hibou.io `_. + + +============= +Main Features +============= + +* Validates presence of assigned vendor to process a Company Paid Expense. +* If the expense is company paid, then the vendor will be the partner used when creating the journal entry, this makes it much easier to reconcile. +* Additionally, adds the expense reference to the journal entry to make it easier to reconcile in either case. + + +.. image:: https://user-images.githubusercontent.com/15882954/41182457-9b692f92-6b2a-11e8-9d5a-d8ef2f19f198.png + :alt: 'Expense Detail' + :width: 988 + :align: left + +======= +License +======= + +Please see `LICENSE `_. + +Copyright Hibou Corp. 2018 From e95a3bce5a3ff00f114a2bf33c26f630783fc6f0 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 20 May 2019 12:31:31 -0700 Subject: [PATCH 3/6] MIG `hr_expense_vendor` to 12.0 --- hr_expense_vendor/__manifest__.py | 2 +- hr_expense_vendor/models/hr_expense.py | 19 +++++---- hr_expense_vendor/tests/test_expenses.py | 44 +++++++++++++------- hr_expense_vendor/views/hr_expense_views.xml | 2 +- 4 files changed, 43 insertions(+), 24 deletions(-) diff --git a/hr_expense_vendor/__manifest__.py b/hr_expense_vendor/__manifest__.py index dee0c40e..e48c836e 100644 --- a/hr_expense_vendor/__manifest__.py +++ b/hr_expense_vendor/__manifest__.py @@ -1,6 +1,6 @@ { 'name': 'HR Expense Vendor', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'author': 'Hibou Corp. ', 'category': 'Human Resources', 'summary': 'Record the vendor paid on expenses.', diff --git a/hr_expense_vendor/models/hr_expense.py b/hr_expense_vendor/models/hr_expense.py index e2ef8b8e..f30ae71d 100644 --- a/hr_expense_vendor/models/hr_expense.py +++ b/hr_expense_vendor/models/hr_expense.py @@ -7,15 +7,18 @@ class HRExpense(models.Model): vendor_id = fields.Many2one('res.partner', string='Vendor') - def _prepare_move_line(self, line): - values = super(HRExpense, self)._prepare_move_line(line) - if self.payment_mode == 'company_account': - if not self.vendor_id: + @api.multi + def _get_account_move_line_values(self): + move_line_values_by_expense = super(HRExpense, self)._get_account_move_line_values() + for expense in self.filtered(lambda e: e.payment_mode == 'company_account'): + if not expense.vendor_id: raise ValidationError('You must have an assigned vendor to process a Company Paid Expense') - values['partner_id'] = self.vendor_id.id - name = values['name'] + (' - ' + str(self.reference) if self.reference else '') - values['name'] = name[:64] - return values + move_line_values = move_line_values_by_expense[expense.id] + for line_values in move_line_values: + new_name = expense.name.split('\n')[0][:64] + (' - ' + str(self.reference) if self.reference else '') + line_values['name'] = new_name[:64] + line_values['partner_id'] = expense.vendor_id.id + return move_line_values_by_expense class HRExpenseSheet(models.Model): diff --git a/hr_expense_vendor/tests/test_expenses.py b/hr_expense_vendor/tests/test_expenses.py index 2cceb774..37b51d89 100644 --- a/hr_expense_vendor/tests/test_expenses.py +++ b/hr_expense_vendor/tests/test_expenses.py @@ -1,35 +1,51 @@ -from odoo.addons.hr_expense.tests.test_expenses import TestCheckJournalEntry +from odoo.addons.hr_expense.tests.test_expenses import TestAccountEntry from odoo.exceptions import ValidationError -class TestCheckVendor(TestCheckJournalEntry): +class TestCheckVendor(TestAccountEntry): def setUp(self): super(TestCheckVendor, self).setUp() self.vendor_id = self.env.ref('base.res_partner_3') def test_journal_entry_vendor(self): - # Non company_account is handled by the super class's `test_journal_entry_ - self.expense.payment_mode = 'company_account' - self.expense_line.payment_mode = 'company_account' + expense = self.env['hr.expense.sheet'].create({ + 'name': 'Expense for John Smith', + 'employee_id': self.employee.id, + }) + expense_line = self.env['hr.expense'].create({ + 'name': 'Car Travel Expenses', + 'employee_id': self.employee.id, + 'product_id': self.product_expense.id, + 'unit_amount': 700.00, + 'tax_ids': [(6, 0, [self.tax.id])], + 'sheet_id': expense.id, + 'analytic_account_id': self.analytic_account.id, + }) + expense.payment_mode = 'company_account' + expense_line.payment_mode = 'company_account' + expense_line._onchange_product_id() + # State should default to draft + self.assertEquals(expense.state, 'draft', 'Expense should be created in Draft state') # Submitted to Manager - self.assertEquals(self.expense.state, 'submit', 'Expense is not in Reported state') + expense.action_submit_sheet() + self.assertEquals(expense.state, 'submit', 'Expense is not in Reported state') # Approve - self.expense.approve_expense_sheets() - self.assertEquals(self.expense.state, 'approve', 'Expense is not in Approved state') + expense.approve_expense_sheets() + self.assertEquals(expense.state, 'approve', 'Expense is not in Approved state') # Create Expense Entries with self.assertRaises(ValidationError): - self.expense.action_sheet_move_create() + expense.action_sheet_move_create() - self.expense_line.vendor_id = self.vendor_id - self.expense.action_sheet_move_create() - self.assertEquals(self.expense.state, 'done') - self.assertTrue(self.expense.account_move_id.id, 'Expense Journal Entry is not created') + expense_line.vendor_id = self.vendor_id + expense.action_sheet_move_create() + self.assertEquals(expense.state, 'done') + self.assertTrue(expense.account_move_id.id, 'Expense Journal Entry is not created') # [(line.debit, line.credit, line.tax_line_id.id) for line in self.expense.expense_line_ids.account_move_id.line_ids] # should git this result [(0.0, 700.0, False), (63.64, 0.0, 179), (636.36, 0.0, False)] - for line in self.expense.account_move_id.line_ids: + for line in expense.account_move_id.line_ids: if line.credit: self.assertEqual(line.partner_id, self.vendor_id) self.assertAlmostEquals(line.credit, 700.00) diff --git a/hr_expense_vendor/views/hr_expense_views.xml b/hr_expense_vendor/views/hr_expense_views.xml index 9038e8ec..57a50710 100644 --- a/hr_expense_vendor/views/hr_expense_views.xml +++ b/hr_expense_vendor/views/hr_expense_views.xml @@ -15,7 +15,7 @@ hr.expense.form.inherit hr.expense - + Date: Wed, 11 Sep 2019 16:52:44 -0400 Subject: [PATCH 4/6] MIG `hr_expense_vendor` For Odoo 13.0 --- hr_expense_vendor/__manifest__.py | 2 +- hr_expense_vendor/models/hr_expense.py | 1 - hr_expense_vendor/views/hr_expense_views.xml | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/hr_expense_vendor/__manifest__.py b/hr_expense_vendor/__manifest__.py index e48c836e..861ca08f 100644 --- a/hr_expense_vendor/__manifest__.py +++ b/hr_expense_vendor/__manifest__.py @@ -1,6 +1,6 @@ { 'name': 'HR Expense Vendor', - 'version': '12.0.1.0.0', + 'version': '13.0.1.0.0', 'author': 'Hibou Corp. ', 'category': 'Human Resources', 'summary': 'Record the vendor paid on expenses.', diff --git a/hr_expense_vendor/models/hr_expense.py b/hr_expense_vendor/models/hr_expense.py index f30ae71d..6e5cf1fe 100644 --- a/hr_expense_vendor/models/hr_expense.py +++ b/hr_expense_vendor/models/hr_expense.py @@ -7,7 +7,6 @@ class HRExpense(models.Model): vendor_id = fields.Many2one('res.partner', string='Vendor') - @api.multi def _get_account_move_line_values(self): move_line_values_by_expense = super(HRExpense, self)._get_account_move_line_values() for expense in self.filtered(lambda e: e.payment_mode == 'company_account'): diff --git a/hr_expense_vendor/views/hr_expense_views.xml b/hr_expense_vendor/views/hr_expense_views.xml index 57a50710..e469cf18 100644 --- a/hr_expense_vendor/views/hr_expense_views.xml +++ b/hr_expense_vendor/views/hr_expense_views.xml @@ -18,8 +18,7 @@ - + From f91ef145b8e2caad8b47c86b832ab38d6c7bda5a Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Sun, 1 Dec 2019 11:08:39 -0800 Subject: [PATCH 5/6] FIX `hr_expense_vendor` don't crash when posting expense sheet with multiple expense lines and references --- hr_expense_vendor/models/hr_expense.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hr_expense_vendor/models/hr_expense.py b/hr_expense_vendor/models/hr_expense.py index 6e5cf1fe..47b99793 100644 --- a/hr_expense_vendor/models/hr_expense.py +++ b/hr_expense_vendor/models/hr_expense.py @@ -14,7 +14,7 @@ class HRExpense(models.Model): raise ValidationError('You must have an assigned vendor to process a Company Paid Expense') move_line_values = move_line_values_by_expense[expense.id] for line_values in move_line_values: - new_name = expense.name.split('\n')[0][:64] + (' - ' + str(self.reference) if self.reference else '') + new_name = expense.name.split('\n')[0][:64] + (' - ' + str(expense.reference) if expense.reference else '') line_values['name'] = new_name[:64] line_values['partner_id'] = expense.vendor_id.id return move_line_values_by_expense From a66dd66696cdd7723c1a9af1c01d38627824430c Mon Sep 17 00:00:00 2001 From: Cedric Collins Date: Wed, 14 Apr 2021 18:28:05 -0500 Subject: [PATCH 6/6] [MIG] hr_expense_vendor: migrate to 14.0 --- hr_expense_vendor/__manifest__.py | 2 +- hr_expense_vendor/tests/test_expenses.py | 81 ++++++++++---------- hr_expense_vendor/views/hr_expense_views.xml | 3 +- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/hr_expense_vendor/__manifest__.py b/hr_expense_vendor/__manifest__.py index 861ca08f..2cde209e 100644 --- a/hr_expense_vendor/__manifest__.py +++ b/hr_expense_vendor/__manifest__.py @@ -1,6 +1,6 @@ { 'name': 'HR Expense Vendor', - 'version': '13.0.1.0.0', + 'version': '14.0.1.0.0', 'author': 'Hibou Corp. ', 'category': 'Human Resources', 'summary': 'Record the vendor paid on expenses.', diff --git a/hr_expense_vendor/tests/test_expenses.py b/hr_expense_vendor/tests/test_expenses.py index 37b51d89..949fa021 100644 --- a/hr_expense_vendor/tests/test_expenses.py +++ b/hr_expense_vendor/tests/test_expenses.py @@ -1,56 +1,59 @@ -from odoo.addons.hr_expense.tests.test_expenses import TestAccountEntry +from odoo.addons.hr_expense.tests.common import TestExpenseCommon from odoo.exceptions import ValidationError +from odoo.tests import Form, tagged -class TestCheckVendor(TestAccountEntry): +@tagged('-at_install', 'post_install') +class TestCheckVendor(TestExpenseCommon): - def setUp(self): - super(TestCheckVendor, self).setUp() - self.vendor_id = self.env.ref('base.res_partner_3') + @classmethod + def setUpClass(cls, chart_template_ref=None): + super(TestCheckVendor, cls).setUpClass(chart_template_ref=chart_template_ref) + cls.vendor_id = cls.env.ref('base.res_partner_3') + cls.tax = cls.env['account.tax'].create({ + 'name': 'Expense 10%', + 'amount': 10, + 'amount_type': 'percent', + 'type_tax_use': 'purchase', + 'price_include': True, + }) def test_journal_entry_vendor(self): - expense = self.env['hr.expense.sheet'].create({ - 'name': 'Expense for John Smith', - 'employee_id': self.employee.id, - }) - expense_line = self.env['hr.expense'].create({ - 'name': 'Car Travel Expenses', - 'employee_id': self.employee.id, - 'product_id': self.product_expense.id, - 'unit_amount': 700.00, - 'tax_ids': [(6, 0, [self.tax.id])], - 'sheet_id': expense.id, - 'analytic_account_id': self.analytic_account.id, - }) - expense.payment_mode = 'company_account' - expense_line.payment_mode = 'company_account' - expense_line._onchange_product_id() + expense_form = Form(self.env['hr.expense']) + expense_form.name = 'Car Travel Expenses' + expense_form.employee_id = self.expense_employee + expense_form.product_id = self.product_a + expense_form.unit_amount = 700.00 + expense_form.tax_ids.clear() + expense_form.tax_ids.add(self.tax) + expense_form.analytic_account_id = self.analytic_account_1 + expense_form.payment_mode = 'company_account' + expense = expense_form.save() - # State should default to draft - self.assertEquals(expense.state, 'draft', 'Expense should be created in Draft state') - # Submitted to Manager - expense.action_submit_sheet() - self.assertEquals(expense.state, 'submit', 'Expense is not in Reported state') + action_submit_expenses = expense.action_submit_expenses() + expense_sheet = self.env[action_submit_expenses['res_model']].browse(action_submit_expenses['res_id']) + + self.assertEqual(expense_sheet.state, 'submit', 'Expense is not in Submitted state') # Approve - expense.approve_expense_sheets() - self.assertEquals(expense.state, 'approve', 'Expense is not in Approved state') + expense_sheet.approve_expense_sheets() + self.assertEqual(expense_sheet.state, 'approve', 'Expense is not in Approved state') # Create Expense Entries with self.assertRaises(ValidationError): - expense.action_sheet_move_create() + expense_sheet.action_sheet_move_create() - expense_line.vendor_id = self.vendor_id - expense.action_sheet_move_create() - self.assertEquals(expense.state, 'done') - self.assertTrue(expense.account_move_id.id, 'Expense Journal Entry is not created') + expense.vendor_id = self.vendor_id + expense_sheet.action_sheet_move_create() + self.assertEqual(expense_sheet.state, 'done') + self.assertTrue(expense_sheet.account_move_id.id, 'Expense Journal Entry is not created') - # [(line.debit, line.credit, line.tax_line_id.id) for line in self.expense.expense_line_ids.account_move_id.line_ids] - # should git this result [(0.0, 700.0, False), (63.64, 0.0, 179), (636.36, 0.0, False)] - for line in expense.account_move_id.line_ids: + # [(line.debit, line.credit, line.tax_line_id.id) for line in expense_sheet.account_move_id.line_ids] + # should get this result [(0.0, 700.0, False), (63.64, 0.0, 179), (636.36, 0.0, False)] + for line in expense_sheet.account_move_id.line_ids: if line.credit: self.assertEqual(line.partner_id, self.vendor_id) - self.assertAlmostEquals(line.credit, 700.00) + self.assertAlmostEqual(line.credit, 700.00) else: if not line.tax_line_id == self.tax: - self.assertAlmostEquals(line.debit, 636.36) + self.assertAlmostEqual(line.debit, 636.36) else: - self.assertAlmostEquals(line.debit, 63.64) + self.assertAlmostEqual(line.debit, 63.64) diff --git a/hr_expense_vendor/views/hr_expense_views.xml b/hr_expense_vendor/views/hr_expense_views.xml index e469cf18..d1903271 100644 --- a/hr_expense_vendor/views/hr_expense_views.xml +++ b/hr_expense_vendor/views/hr_expense_views.xml @@ -6,8 +6,7 @@ - +