Initial commit hr_expense_vendor for 11.0

This commit is contained in:
Jared Kipe
2018-04-23 09:54:32 -07:00
parent 68efe61e91
commit 184fa88ac7
8 changed files with 115 additions and 0 deletions

3
.gitignore vendored
View File

@@ -99,3 +99,6 @@ ENV/
# mypy # mypy
.mypy_cache/ .mypy_cache/
# Pycharm
.idea/

View File

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

View File

@@ -0,0 +1,19 @@
{
'name': 'HR Expense Vendor',
'version': '11.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,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)]})

View File

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

View File

@@ -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)

View File

@@ -0,0 +1,26 @@
<?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" domain="[('supplier', '=', True)]"
context="{'default_supplier': True}" 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_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='product_id']" position="after">
<field name="vendor_id" domain="[('supplier', '=', True)]"
context="{'default_supplier': True}" groups="account.group_account_user"/>
</xpath>
</field>
</record>
</odoo>