Skip to content

[18.0][MIG] budget_control_request_document_expense #515

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

Merged
merged 7 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions budget_control_request_document_expense/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
==========================================
Budget Control on Request Document Expense
==========================================

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

.. |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/18.0/budget_control_request_document_expense
:alt: ecosoft-odoo/budgeting

|badge1| |badge2| |badge3|

This module support commitment on request document expense

.. 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:

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_control_request_document_expense%0Aversion:%2018.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
------------

- Kitti Upariphutthiphong <[email protected]>
- Saran Lim. <[email protected]>

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/18.0/budget_control_request_document_expense>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions budget_control_request_document_expense/__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
20 changes: 20 additions & 0 deletions budget_control_request_document_expense/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Budget Control on Request Document Expense",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/ecosoft-odoo/budgeting",
"depends": [
"budget_control_request_document",
"budget_control_expense",
"request_document_expense",
],
"data": [],
"installable": True,
"auto_install": True,
"maintainers": ["Saran440"],
"development_status": "Alpha",
}
5 changes: 5 additions & 0 deletions budget_control_request_document_expense/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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

from odoo import models


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

def _init_docline_budget_vals(self, budget_vals, analytic_id):
"""Use standard budget move but we need commit in request"""
budget_vals = super()._init_docline_budget_vals(budget_vals, analytic_id)
if (
self.env.context.get("alt_budget_move_model") == "request.budget.move"
and self._name == "hr.expense"
):
budget_vals.pop("expense_id") # Delete expense reference
budget_vals["request_document_id"] = self[
self._doc_rel
].request_document_id.id
return budget_vals
15 changes: 15 additions & 0 deletions budget_control_request_document_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


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

def write(self, vals):
"""Uncommit budget for source request document."""
res = super().write(vals)
if vals.get("approval_state") in ("approve", "cancel", False):
self.mapped("request_document_id").recompute_budget_move()
return res
36 changes: 36 additions & 0 deletions budget_control_request_document_expense/models/request_document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class RequestDocument(models.Model):
_inherit = "request.document"

def _get_origin_lines(self):
vals = super()._get_origin_lines()
vals["expense"] = "expense_sheet_ids.expense_line_ids"
return vals

def _get_data_amount(self, request_line):
if request_line._name == "hr.expense":
data_amount = [
{doc_line.id: doc_line.total_amount_currency}
for doc_line in request_line
]
return data_amount
return super()._get_data_amount(request_line)

Check warning on line 22 in budget_control_request_document_expense/models/request_document.py

View check run for this annotation

Codecov / codecov/patch

budget_control_request_document_expense/models/request_document.py#L22

Added line #L22 was not covered by tests

def uncommit_request_budget(self, request_line):
res = super().uncommit_request_budget(request_line)
budget_move = request_line[request_line._budget_move_field]
# Expense with state approve, posted or done will auto close budget
if self.env.context.get("reverse_precommit") or (
request_line._name == "hr.expense"
and budget_move
and request_line[request_line._doc_rel].approval_state
in ["approve", "post", "done"]
):
budget_moves = self.close_budget_move()
return budget_moves
return res
3 changes: 3 additions & 0 deletions budget_control_request_document_expense/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Kitti Upariphutthiphong \<<[email protected]>\>
- Saran Lim. \<<[email protected]>\>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module support commitment on request document expense
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading