Merge branch 'mig/14.0/hr_expense_vendor' into '14.0'

mig/14.0/hr_expense_vendor into 14.0

See merge request hibou-io/hibou-odoo/suite!888
This commit is contained in:
Jared Kipe
2021-08-03 20:22:58 +00:00
8 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
*************************
Hibou - HR Expense Vendor
*************************
Records the vendor paid on expenses.
For more information and add-ons, visit `Hibou.io <https://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 <https://github.com/hibou-io/hibou-odoo-suite/blob/11.0/LICENSE>`_.
Copyright Hibou Corp. 2018

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,19 @@
{
'name': 'HR Expense Vendor',
'version': '14.0.1.0.0',
'author': 'Hibou Corp. <hello@hibou.io>',
'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,
}

View File

@@ -0,0 +1 @@
from . import hr_expense

View File

@@ -0,0 +1,26 @@
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 _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')
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(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
class HRExpenseSheet(models.Model):
_inherit = 'hr.expense.sheet'
expense_line_ids = fields.One2many(states={'done': [('readonly', True)], 'post': [('readonly', True)]})

View File

@@ -0,0 +1 @@
from . import test_expenses

View File

@@ -0,0 +1,59 @@
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
from odoo.exceptions import ValidationError
from odoo.tests import Form, tagged
@tagged('-at_install', 'post_install')
class TestCheckVendor(TestExpenseCommon):
@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_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()
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_sheet.approve_expense_sheets()
self.assertEqual(expense_sheet.state, 'approve', 'Expense is not in Approved state')
# Create Expense Entries
with self.assertRaises(ValidationError):
expense_sheet.action_sheet_move_create()
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 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.assertAlmostEqual(line.credit, 700.00)
else:
if not line.tax_line_id == self.tax:
self.assertAlmostEqual(line.debit, 636.36)
else:
self.assertAlmostEqual(line.debit, 63.64)

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_hr_expense_sheet_form_inherit" model="ir.ui.view">
<field name="name">hr.expense.sheet.form.inherit</field>
<field name="model">hr.expense.sheet</field>
<field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='expense_line_ids']/tree/field[@name='name']" position="after">
<field name="vendor_id" context="{'res_partner_search_mode': 'supplier'}" groups="account.group_account_user"/>
</xpath>
</field>
</record>
<record id="hr_expense_form_view_inherit" model="ir.ui.view">
<field name="name">hr.expense.form.inherit</field>
<field name="model">hr.expense</field>
<field name="inherit_id" ref="hr_expense.hr_expense_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_id']" position="after">
<field name="vendor_id" context="{'res_partner_search_mode': 'supplier'}" groups="account.group_account_user"/>
</xpath>
</field>
</record>
</odoo>