-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.0.1.0.0] hr_timesheet_accrue_expense
- Loading branch information
Showing
11 changed files
with
414 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
================================================== | ||
Generate Accrue Expense Based On Timesheet Details | ||
================================================== | ||
|
||
|
||
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 *Generate Accrue Expense Based On Timesheet Details* | ||
6. Install the module | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Michael Viriyananda <viriyananda.michael@gmail.com> | ||
* Andhitia Rama <andhitia.r@gmail.com> | ||
* Nurazmi <azmimr67@gmail.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://simetri-sinergi.id/logo.png | ||
:alt: PT. Simetri Sinergi Indonesia | ||
:target: https://simetri-sinergi.id.com | ||
|
||
This module is maintained by the PT. Simetri Sinergi Indonesia. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 OpenSynergy Indonesia | ||
# Copyright 2020 PT. Simetri Sinergi Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import ( | ||
models, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 OpenSynergy Indonesia | ||
# Copyright 2020 PT. Simetri Sinergi Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Generate Accrue Expense Based On Timesheet Details", | ||
"version": "8.0.1.0.0", | ||
"website": "https://simetri-sinergi.id", | ||
"author": "PT. Simetri Sinergi Indonesia, OpenSynergy Indonesia", | ||
"license": "AGPL-3", | ||
"installable": True, | ||
"depends": [ | ||
"hr_timesheet", | ||
"hr_timesheet_onchange", | ||
], | ||
"data": [ | ||
"views/hr_employee_views.xml", | ||
"views/account_analytic_account_views.xml", | ||
"views/hr_analytic_timesheet_views.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 OpenSynergy Indonesia | ||
# Copyright 2020 PT. Simetri Sinergi Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import ( | ||
account_analytic_account, | ||
hr_analytic_timesheet, | ||
hr_employee, | ||
) |
30 changes: 30 additions & 0 deletions
30
hr_timesheet_accrue_expense/models/account_analytic_account.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 OpenSynergy Indonesia | ||
# Copyright 2020 PT. Simetri Sinergi Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import models, fields | ||
|
||
|
||
class AccountAnalyticAccount(models.Model): | ||
_name = "account.analytic.account" | ||
_inherit = "account.analytic.account" | ||
|
||
accrue_expense_journal_id = fields.Many2one( | ||
string="Accrue Expense Journal", | ||
comodel_name="account.journal", | ||
domain=[ | ||
("type", "=", "general"), | ||
], | ||
) | ||
accrue_expense_account_id = fields.Many2one( | ||
string="Accrue Expense Account", | ||
comodel_name="account.account", | ||
domain=[ | ||
("type", "=", "other"), | ||
], | ||
) | ||
accrue_expense_ok = fields.Boolean( | ||
string="Can Create Accrue Expense", | ||
default=False, | ||
) |
195 changes: 195 additions & 0 deletions
195
hr_timesheet_accrue_expense/models/hr_analytic_timesheet.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 OpenSynergy Indonesia | ||
# Copyright 2020 PT. Simetri Sinergi Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import fields, models, api, _ | ||
from openerp.exceptions import Warning as UserError | ||
|
||
|
||
class HrAnalyticTimesheet(models.Model): | ||
_name = "hr.analytic.timesheet" | ||
_inherit = "hr.analytic.timesheet" | ||
|
||
accrue_expense_journal_id = fields.Many2one( | ||
string="Accrue Expense Journal", | ||
comodel_name="account.journal", | ||
domain=[ | ||
("type", "=", "general"), | ||
], | ||
) | ||
accrue_expense_account_id = fields.Many2one( | ||
string="Accrue Expense Account", | ||
comodel_name="account.account", | ||
domain=[ | ||
("type", "=", "other"), | ||
], | ||
) | ||
accrue_expense_ok = fields.Boolean( | ||
string="Can Create Accrue Expense", | ||
default=False, | ||
) | ||
accrue_expense_move_id = fields.Many2one( | ||
string="Accrue Expense Move", | ||
comodel_name="account.move", | ||
readonly=True, | ||
) | ||
|
||
@api.onchange( | ||
"user_id", | ||
"account_id", | ||
) | ||
def onchange_accrue_expense_journal_id(self): | ||
journal = False | ||
if self.user_id and \ | ||
len(self.user_id.employee_ids) > 0 and \ | ||
self.user_id.employee_ids[0].accrue_expense_journal_id: | ||
journal = self.user_id.employee_ids[0].accrue_expense_journal_id | ||
|
||
if not journal and \ | ||
self.account_id and \ | ||
self.account_id.accrue_expense_journal_id: | ||
journal = self.account_id.accrue_expense_journal_id | ||
|
||
self.accrue_expense_journal_id = journal | ||
|
||
@api.onchange( | ||
"user_id", | ||
"account_id", | ||
) | ||
def onchange_accrue_expense_account_id(self): | ||
account = False | ||
if self.user_id and \ | ||
len(self.user_id.employee_ids) > 0 and \ | ||
self.user_id.employee_ids[0].accrue_expense_account_id: | ||
account = self.user_id.employee_ids[0].accrue_expense_account_id | ||
|
||
if not account and \ | ||
self.account_id and \ | ||
self.account_id.accrue_expense_account_id: | ||
account = self.account_id.accrue_expense_account_id | ||
|
||
self.accrue_expense_account_id = account | ||
|
||
@api.onchange( | ||
"account_id", | ||
) | ||
def onchange_accrue_expense_ok(self): | ||
result = False | ||
|
||
if self.account_id: | ||
result = self.account_id.accrue_expense_ok | ||
|
||
self.accrue_expense_ok = result | ||
|
||
@api.multi | ||
def action_create_accrue_expense_move(self): | ||
for document in self: | ||
document._create_accrue_expense_move() | ||
|
||
@api.multi | ||
def action_unlink_accrue_expense_move(self): | ||
for document in self: | ||
document._unlink_accrue_expense_move() | ||
|
||
@api.multi | ||
def _unlink_accrue_expense_move(self): | ||
self.ensure_one() | ||
move = self.accrue_expense_move_id | ||
self.write({ | ||
"accrue_expense_move_id": False, | ||
}) | ||
move.unlink() | ||
|
||
@api.multi | ||
def _create_accrue_expense_move(self): | ||
self.ensure_one() | ||
obj_move = self.env["account.move"] | ||
move = obj_move.create(self._prepare_accrue_expense_move()) | ||
self.write({ | ||
"accrue_expense_move_id": move.id, | ||
}) | ||
|
||
@api.multi | ||
def _get_accrue_expense_journal(self): | ||
self.ensure_one() | ||
if not self.accrue_expense_journal_id: | ||
err_msg = _("No accrue expense journal defined") | ||
raise UserError(err_msg) | ||
return self.accrue_expense_journal_id | ||
|
||
@api.multi | ||
def _get_accrue_expense_account(self): | ||
self.ensure_one() | ||
if not self.accrue_expense_account_id: | ||
err_msg = _("No accrue expense account defined") | ||
raise UserError(err_msg) | ||
return self.accrue_expense_account_id | ||
|
||
@api.multi | ||
def _get_expense_account(self): | ||
self.ensure_one() | ||
return self.general_account_id | ||
|
||
@api.multi | ||
def _get_period(self): | ||
self.ensure_one() | ||
period = self.env["account.period"].find(self.date) | ||
return period | ||
|
||
@api.multi | ||
def _prepare_accrue_expense_move(self): | ||
self.ensure_one() | ||
journal = self._get_accrue_expense_journal() | ||
period = self._get_period() | ||
return { | ||
"journal_id": journal.id, | ||
"period_id": period.id, | ||
"date": self.date, | ||
"line_id": self._prepare_move_lines() | ||
} | ||
|
||
@api.multi | ||
def _prepare_move_lines(self): | ||
self.ensure_one() | ||
result = [] | ||
result.append(self._prepare_accrue_expense_line()) | ||
result.append(self._prepare_expense_line()) | ||
return result | ||
|
||
@api.multi | ||
def _get_partner(self): | ||
self.ensure_one() | ||
partner = self.user_id.employee_ids[0].address_home_id | ||
if not partner: | ||
err_msg = _("No home address defined") | ||
raise UserError(err_msg) | ||
return partner | ||
|
||
@api.multi | ||
def _prepare_accrue_expense_line(self): | ||
self.ensure_one() | ||
return (0, 0, { | ||
"account_id": self._get_accrue_expense_account().id, | ||
"credit": self.amount, | ||
"debit": 0.0, | ||
"partner_id": self._get_partner().id, | ||
"name": self.name, | ||
"product_id": self.product_id.id, | ||
"product_uom_id": self.product_uom_id.id, | ||
"quantity": self.unit_amount, | ||
}) | ||
|
||
@api.multi | ||
def _prepare_expense_line(self): | ||
self.ensure_one() | ||
return (0, 0, { | ||
"account_id": self._get_expense_account().id, | ||
"debit": self.amount, | ||
"credit": 0.0, | ||
"partner_id": self._get_partner().id, | ||
"name": self.name, | ||
"product_id": self.product_id.id, | ||
"product_uom_id": self.product_uom_id.id, | ||
"quantity": self.unit_amount, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 OpenSynergy Indonesia | ||
# Copyright 2020 PT. Simetri Sinergi Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import models, fields | ||
|
||
|
||
class HrEmployee(models.Model): | ||
_name = "hr.employee" | ||
_inherit = "hr.employee" | ||
|
||
accrue_expense_journal_id = fields.Many2one( | ||
string="Accrue Expense Journal", | ||
comodel_name="account.journal", | ||
domain=[ | ||
("type", "=", "general"), | ||
], | ||
) | ||
accrue_expense_account_id = fields.Many2one( | ||
string="Accrue Expense Account", | ||
comodel_name="account.account", | ||
domain=[ | ||
("type", "=", "other"), | ||
], | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions
30
hr_timesheet_accrue_expense/views/account_analytic_account_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2020 OpenSynergy Indonesia | ||
Copyright 2020 PT. Simetri Sinergi Indonesia | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<openerp> | ||
<data> | ||
|
||
<record id="account_analytic_account_view_form" model="ir.ui.view"> | ||
<field name="name">account.analytic.account form</field> | ||
<field name="model">account.analytic.account</field> | ||
<field name="inherit_id" ref="hr_timesheet.account_analytic_account_timesheet_form"/> | ||
<field name="arch" type="xml"> | ||
<data> | ||
<xpath expr="//notebook" position="inside"> | ||
<page name="accrue_expense" string="Accrue Expense" attrs="{'invisible':[('use_timesheets','=',False)]}"> | ||
<group name="accrue_expense_1" colspan="4" col="2"> | ||
<field name="accrue_expense_journal_id"/> | ||
<field name="accrue_expense_account_id"/> | ||
<field name="accrue_expense_ok"/> | ||
</group> | ||
</page> | ||
</xpath> | ||
</data> | ||
</field> | ||
</record> | ||
|
||
|
||
</data> | ||
</openerp> |
29 changes: 29 additions & 0 deletions
29
hr_timesheet_accrue_expense/views/hr_analytic_timesheet_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2020 OpenSynergy Indonesia | ||
Copyright 2020 PT. Simetri Sinergi Indonesia | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<openerp> | ||
<data> | ||
|
||
<record id="hr_analytic_timesheet_view_tree" model="ir.ui.view"> | ||
<field name="name">hr.analytic.timesheet form</field> | ||
<field name="model">hr.analytic.timesheet</field> | ||
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/> | ||
<field name="arch" type="xml"> | ||
<data> | ||
<xpath expr="//field[@name='general_account_id']" position="after"> | ||
<field name="accrue_expense_journal_id"/> | ||
<field name="accrue_expense_account_id"/> | ||
<field name="accrue_expense_ok"/> | ||
<field name="accrue_expense_move_id"/> | ||
<button name="action_create_accrue_expense_move" string="Generate Accrue Expense" icon="gtk-apply" type="object" attrs="{'invisible':['|',('accrue_expense_move_id','!=',False),('accrue_expense_ok','=',False)]}"/> | ||
<button name="action_unlink_accrue_expense_move" string="Delete Accrue Expense" icon="gtk-delete" type="object" attrs="{'invisible':['|',('accrue_expense_move_id','=',False),('accrue_expense_ok','=',False)]}"/> | ||
</xpath> | ||
</data> | ||
</field> | ||
</record> | ||
|
||
|
||
</data> | ||
</openerp> |
Oops, something went wrong.