Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] budget_activity_advance_clearing #465

Open
wants to merge 11 commits into
base: 16.0
Choose a base branch
from
98 changes: 98 additions & 0 deletions budget_activity_advance_clearing/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
==================================
Budget Activity - Advance/Clearing
==================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:85a085e257191cba5ccaa2c5aeb0acf79828325b72decbde192859798e194730
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-ecosoft--odoo%2Fbudgeting-lightgray.png?logo=github
:target: https://github.com/ecosoft-odoo/budgeting/tree/16.0/budget_activity_advance_clearing
:alt: ecosoft-odoo/budgeting

|badge1| |badge2| |badge3|

This module add "Activity" element for advance/clearing commitment

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

This module will create a new activity and KPI "Employee Advance" automatically.
You will need to setup the Account of this activity first.

* Go to Budgeting > Activity > Budget Activity > Open activity "Employee Advance"
* Select appropriate employee advance account from your chart of account
* Go to Budgeting > Configurations > Budget Template
* Select your template that control budget and add KPI "Employee Advance" into Template

Note:

* Employee Advance account code, if not already exists, you can create one. Use type = Current Asset and check Allow Reconciliation.

Usage
=====

#. Go to Expenses > My Expenses > Advances > Create new advance
#. Activity field is default Employee Advance and it will automatically change the account on the advance/clearing that your config.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/ecosoft-odoo/budgeting/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/ecosoft-odoo/budgeting/issues/new?body=module:%20budget_activity_advance_clearing%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Ecosoft

Contributors
~~~~~~~~~~~~

* `Ecosoft <http://ecosoft.co.th>`__:

* Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
* Saran Lim. <saranl@ecosoft.co.th>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>

Maintainers
~~~~~~~~~~~

.. |maintainer-Saran440| image:: https://github.com/Saran440.png?size=40px
:target: https://github.com/Saran440
:alt: Saran440

Current maintainer:

|maintainer-Saran440|

This module is part of the `ecosoft-odoo/budgeting <https://github.com/ecosoft-odoo/budgeting/tree/16.0/budget_activity_advance_clearing>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions budget_activity_advance_clearing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
23 changes: 23 additions & 0 deletions budget_activity_advance_clearing/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Budget Activity - Advance/Clearing",
"version": "16.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/ecosoft-odoo/budgeting",
"depends": [
"budget_activity_expense",
"budget_control_advance_clearing",
],
"data": [
"data/budget_advance_data.xml",
"views/hr_expense_view.xml",
],
"installable": True,
"auto_install": True,
"maintainers": ["Saran440"],
"development_status": "Alpha",
}
13 changes: 13 additions & 0 deletions budget_activity_advance_clearing/data/budget_advance_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="budget_kpi_advance" model="budget.kpi">
<field name="name">Employee Advance</field>
</record>
<record id="budget_activity_advance" model="budget.activity">
<field name="name">Employee Advance</field>
<field
name="kpi_id"
ref="budget_activity_advance_clearing.budget_kpi_advance"
/>
</record>
</odoo>
7 changes: 7 additions & 0 deletions budget_activity_advance_clearing/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import base_budget_move
from . import hr_expense
from . import budget_activity
from . import budget_period
from . import budget_control
21 changes: 21 additions & 0 deletions budget_activity_advance_clearing/models/base_budget_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class BudgetDoclineMixinBase(models.AbstractModel):
_inherit = "budget.docline.mixin.base"

def _domain_activity(self):
"""
Filter out the activity advance from the domain of the activity field,
because the activity advance is meant to be used only in the advances view.
"""
domain = super()._domain_activity()
advance_activity = self.env.ref(
"budget_activity_advance_clearing.budget_activity_advance"
)
if advance_activity:
domain.append(("id", "!=", advance_activity.id))
return domain
27 changes: 27 additions & 0 deletions budget_activity_advance_clearing/models/budget_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class BudgetActivity(models.Model):
_inherit = "budget.activity"

@api.onchange("account_id")
def _onchange_account_id(self):
"""
Update the expense account of the employee advance product based on the
account_id activity of the current record.
"""
budget_activity_advance = self.env.ref(
"budget_activity_advance_clearing.budget_activity_advance"
)
# If the current record is the budget activity advance reference
if self._origin.id == budget_activity_advance.id:
employee_advance_product = self.env.ref(
"hr_expense_advance_clearing.product_emp_advance"
)
# Update the expense account of the employee advance product
employee_advance_product.update(
{"property_account_expense_id": self.account_id}
)
16 changes: 16 additions & 0 deletions budget_activity_advance_clearing/models/budget_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class BudgetControl(models.Model):
_inherit = "budget.control"

def _get_lines_init_date(self):
self.ensure_one()
lines = super()._get_lines_init_date()
kpi_advance = self.env.ref(
"budget_activity_advance_clearing.budget_kpi_advance"
)
return lines.filtered(lambda l: l.kpi_id != kpi_advance)
17 changes: 17 additions & 0 deletions budget_activity_advance_clearing/models/budget_period.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class BudgetPeriod(models.Model):
_inherit = "budget.period"

def _get_budget_avaiable(self, analytic_id, template_lines):
"""Not check budget available with kpi advance"""
kpi_advance = self.env.ref(
"budget_activity_advance_clearing.budget_kpi_advance"
)
if template_lines._name == "budget.template.line":
template_lines = template_lines.filtered(lambda l: l.kpi_id != kpi_advance)
return super()._get_budget_avaiable(analytic_id, template_lines)
92 changes: 92 additions & 0 deletions budget_activity_advance_clearing/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError


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

def action_submit_sheet(self):
"""As advance clearing, Employee Advance as activity not allowed"""
if self.mapped("advance_sheet_id"):
activity_advance = self.env.ref(
"budget_activity_advance_clearing.budget_activity_advance"
)
if activity_advance in self.mapped("expense_line_ids.activity_id"):
raise UserError(
_(
"For clearing expenes, activity 'Employee Advance' "
"is not allowed.\nPlease change activity."
)
)
return super().action_submit_sheet()

def get_domain_advance_sheet_expense_line(self):
"""Overwrite domain filter expense lines with clearing product or activity"""
return self.advance_sheet_id.expense_line_ids.filtered(
lambda l: l.clearing_product_id or l.clearing_activity_id
)

def _prepare_clear_advance(self, line):
clearing_dict = super()._prepare_clear_advance(line)
if line.clearing_activity_id:
clearing_dict["activity_id"] = line.clearing_activity_id.id
clearing_dict["name"] = line.name
return clearing_dict

def create_clearing_expense_line(self, line):
clearing_line = super().create_clearing_expense_line(line)
clearing_line._onchange_activity_id()
return clearing_line


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

clearing_activity_id = fields.Many2one(
comodel_name="budget.activity",
string="Clearing Activity",
domain=lambda self: [
(
"id",
"!=",
self.env.ref(
"budget_activity_advance_clearing.budget_activity_advance", 0
).id,
)
],
tracking=True,
ondelete="restrict",
help="Optional: On the clear advance, the clearing "
"activity will create default activity line.",
)

@api.constrains("advance")
def _check_advance(self):
for expense in self.filtered("advance"):
budget_activity_advance = self.env.ref(
"budget_activity_advance_clearing.budget_activity_advance"
)
if not budget_activity_advance.account_id:
raise ValidationError(_("Employee advance activity has no account."))
if expense.activity_id != budget_activity_advance:
raise ValidationError(
_("Employee advance, selected activity is not valid.")
)
return super()._check_advance()

@api.onchange("advance")
def onchange_advance(self):
"""
Update the activity_id field of the current record based on the value of the
advance field.
"""
res = super().onchange_advance()
self.activity_id = (
self.env.ref("budget_activity_advance_clearing.budget_activity_advance")
if self.advance
else False
)
return res
11 changes: 11 additions & 0 deletions budget_activity_advance_clearing/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This module will create a new activity and KPI "Employee Advance" automatically.
You will need to setup the Account of this activity first.

* Go to Budgeting > Activity > Budget Activity > Open activity "Employee Advance"
* Select appropriate employee advance account from your chart of account
* Go to Budgeting > Configurations > Budget Template
* Select your template that control budget and add KPI "Employee Advance" into Template

Note:

* Employee Advance account code, if not already exists, you can create one. Use type = Current Asset and check Allow Reconciliation.
5 changes: 5 additions & 0 deletions budget_activity_advance_clearing/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* `Ecosoft <http://ecosoft.co.th>`__:

* Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
* Saran Lim. <saranl@ecosoft.co.th>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
1 change: 1 addition & 0 deletions budget_activity_advance_clearing/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module add "Activity" element for advance/clearing commitment
2 changes: 2 additions & 0 deletions budget_activity_advance_clearing/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#. Go to Expenses > My Expenses > Advances > Create new advance
#. Activity field is default Employee Advance and it will automatically change the account on the advance/clearing that your config.
Loading
Loading