Skip to content

Commit

Permalink
Merge 6378223 into a727ec9
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevhe18 committed Dec 16, 2016
2 parents a727ec9 + 6378223 commit 4b4c8a9
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 0 deletions.
39 changes: 39 additions & 0 deletions hr_expense_payable_account/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

==========================
HR Expense Payable Account
==========================

This module adds field accounts for Expense.

Installation
============

To install this module, you need to:

1. Clone the branch 8.0 of the repository https://github.com/open-synergy/opnsynid-hr
2. Add the path to this repository in your configuration (addons-path)
3. Update the module list
4. Go to menu *Setting -> Modules -> Local Modules*
5. Search For *HR Expense Payable Account*
6. Install the module

Credits
=======

Contributors
------------

* Michael Viriyananda <viriyananda.michael@gmail.com>
* Andhitia Rama <andhitia.r@gmail.com>

Maintainer
----------

.. image:: https://opensynergy-indonesia.com/logo.png
:alt: OpenSynergy Indonesia
:target: https://opensynergy-indonesia.com

This module is maintained by the OpenSynergy Indonesia.
5 changes: 5 additions & 0 deletions hr_expense_payable_account/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
15 changes: 15 additions & 0 deletions hr_expense_payable_account/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# Copyright 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account for Expense",
"version": "8.0.1.0.0",
"summary": "Add Account for Expense",
"category": "Human Resource",
"website": "https://opensynergy-indonesia.com",
"author": "OpenSynergy Indonesia",
"license": "AGPL-3",
"installable": True,
"depends": ["hr_expense"],
"data": ["views/hr_expense.xml"],
}
5 changes: 5 additions & 0 deletions hr_expense_payable_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import hr_expense
46 changes: 46 additions & 0 deletions hr_expense_payable_account/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# Copyright 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api


class HrExpense(models.Model):
_inherit = "hr.expense.expense"

account_id = fields.Many2one(
string="Account",
comodel_name="account.account"
)

@api.model
def _get_partner_account(self):
address_home_id =\
self.employee_id.address_home_id
if address_home_id:
commercial_partner_id =\
address_home_id.commercial_partner_id
if commercial_partner_id:
account_id =\
commercial_partner_id.property_account_payable
if account_id:
return account_id.id
return False

@api.multi
@api.onchange(
'journal_id',
'employee_id'
)
def onchange_journal_id(self):
value = False
if self.journal_id:
account_id =\
self.journal_id.default_credit_account_id
if account_id:
value = account_id.id
else:
value = self._get_partner_account()
else:
value = self._get_partner_account()
self.account_id = value
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions hr_expense_payable_account/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_onchange
67 changes: 67 additions & 0 deletions hr_expense_payable_account/tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
# © 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests.common import TransactionCase


class BaseCase(TransactionCase):
def setUp(self):
super(BaseCase, self).setUp()
# Data Object
self.obj_hr_expense = self.env['hr.expense.expense']

# Data Journal
self.journal_1 = self.env.ref('account.expenses_journal')
self.journal_2 = self.create_journal()
# Data Employee
self.employee_1 = self.env.ref('hr.employee_mit')
self.employee_2 = self.create_employee()

def create_journal(self):
# Create Journal
# Condition :
# default_credit_account_id = False
# default_debit_account_id = False
obj_account_journal = self.env['account.journal']
sequence = self.env.ref('account.sequence_purchase_journal')
analytic_acc = self.env.ref('account.exp')
user = self.env.ref('base.user_root')

val = {
'name': 'Test Expenses Journal',
'code': 'TSTJ',
'type': 'purchase',
'sequence_id': sequence.id,
'default_credit_account_id': False,
'default_debit_account_id': False,
'analytic_journal_id': analytic_acc.id,
'user_id': user.id
}

journal =\
obj_account_journal.create(val)
return journal

def create_employee(self):
# Create Journal
# Condition :
# address_home_id = False
obj_hr_employee = self.env['hr.employee']
department_id = self.env.ref('hr.dep_rd')
parent_id = self.env.ref('hr.employee_al')
job_id = self.env.ref('hr.job_developer')
category_id = self.env.ref('hr.employee_category_4')

val = {
'name': 'Test Employee',
'department_id': department_id.id,
'parent_id': parent_id.id,
'job_id': job_id.id,
'category_ids': [(6, 0, [category_id.id])],
'address_home_id': False
}

employee =\
obj_hr_employee.create(val)
return employee
89 changes: 89 additions & 0 deletions hr_expense_payable_account/tests/test_onchange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
# Copyright 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from .base import BaseCase


class HrExpensePayableAccount(BaseCase):
# Check value account_id
# Condition :
# journal_id == True
# default_credit_account == True
# home_address == True
# property_account_payable == True
def test_onchange_journal_id_1(self):
with self.env.do_in_onchange():
new = self.obj_hr_expense.new()

new.journal_id = self.journal_1.id
new.employee_id = self.employee_1.id

new.onchange_journal_id()

self.assertEqual(
self.journal_1.default_credit_account_id.id,
new.account_id.id)

# Check value account_id
# Condition :
# journal_id == True
# default_credit_account == False
# home_address == True
# property_account_payable == True
def test_onchange_journal_id_2(self):
with self.env.do_in_onchange():
new = self.obj_hr_expense.new()

new.journal_id = self.journal_2.id
new.employee_id = self.employee_1.id

property_account_payable =\
new._get_partner_account()

new.onchange_journal_id()

self.assertEqual(
property_account_payable,
new.account_id.id)

# Check value account_id
# Condition :
# journal_id == True
# default_credit_account == False
# home_address == False
# property_account_payable == False
def test_onchange_journal_id_3(self):
with self.env.do_in_onchange():
new = self.obj_hr_expense.new()

new.journal_id = self.journal_2.id
new.employee_id = self.employee_2.id

new.onchange_journal_id()

self.assertEqual(
False,
new.account_id.id)

# Check value account_id
# Condition :
# journal_id == False
# default_credit_account == False
# home_address == True
# property_account_payable == True
def test_onchange_journal_id_4(self):
with self.env.do_in_onchange():
new = self.obj_hr_expense.new()

new.journal_id = False
new.employee_id = self.employee_1.id

property_account_payable =\
new._get_partner_account()

new.onchange_journal_id()

self.assertEqual(
property_account_payable,
new.account_id.id)
16 changes: 16 additions & 0 deletions hr_expense_payable_account/views/hr_expense.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="hr_expense_view_form" model="ir.ui.view">
<field name="name">HR Expense Account</field>
<field name="model">hr.expense.expense</field>
<field name="inherit_id" ref="hr_expense.view_expenses_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='journal_id']" position="after">
<field name="account_id"/>
</xpath>
</field>
</record>
</data>
</openerp>

0 comments on commit 4b4c8a9

Please sign in to comment.