mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
MIG hr_expense_vendor to 12.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
'name': 'HR Expense Vendor',
|
||||
'version': '11.0.1.0.0',
|
||||
'version': '12.0.1.0.0',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'category': 'Human Resources',
|
||||
'summary': 'Record the vendor paid on expenses.',
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<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="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" domain="[('supplier', '=', True)]"
|
||||
|
||||
Reference in New Issue
Block a user