Skip to content

Commit

Permalink
Merge pull request #444 from ecosoft-odoo/16.0-mig-budget_control_pur…
Browse files Browse the repository at this point in the history
…chase_request

[16.0][MIG] budget_control_purchase_request
  • Loading branch information
Saran440 authored Aug 14, 2024
2 parents 52bdce5 + 15f1c72 commit f8974b1
Show file tree
Hide file tree
Showing 28 changed files with 1,378 additions and 0 deletions.
79 changes: 79 additions & 0 deletions budget_control_purchase_request/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
==================================
Budget Control on Purchase Request
==================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7146707799784bb21d8e53d22fba0d6756866f1de1861508f78d57eab6679936
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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_control_purchase_request
:alt: ecosoft-odoo/budgeting

|badge1| |badge2| |badge3|

This module will create budget commitment for purchase request (to be used as alternate actual source in mis_builder)

When purchase request is approved, purchase.request.budget.move is created, and when
purchase order is confirmed, reversed purchase.request.budget.move is created.

A new tab "Budget Commitment" is created on purchase request for budget user to keep track of the committed budget.

.. 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_purchase_request%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
~~~~~~~~~~~~

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

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

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

Current maintainer:

|maintainer-kittiu|

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

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

{
"name": "Budget Control on Purchase Request",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/ecosoft-odoo/budgeting",
"depends": [
"budget_control_purchase",
"purchase_request",
],
"data": [
"security/ir.model.access.csv",
"views/budget_period_view.xml",
"views/purchase_request_view.xml",
"views/budget_control_view.xml",
"views/budget_commit_forward_view.xml",
],
"installable": True,
"maintainers": ["kittiu"],
"development_status": "Alpha",
}
9 changes: 9 additions & 0 deletions budget_control_purchase_request/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import purchase_budget_move
from . import purchase_request_budget_move
from . import budget_period
from . import purchase
from . import purchase_request
from . import budget_control
from . import budget_commit_forward
53 changes: 53 additions & 0 deletions budget_control_purchase_request/models/budget_commit_forward.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class BudgetCommitForward(models.Model):
_inherit = "budget.commit.forward"

purchase_request = fields.Boolean(
default=True,
help="If checked, click review budget commitment will pull purchase request commitment",
)
forward_purchase_request_ids = fields.One2many(
comodel_name="budget.commit.forward.line",
inverse_name="forward_id",
string="Purchase Requests",
domain=[("res_model", "=", "purchase.request.line")],
)

def _get_budget_docline_model(self):
res = super()._get_budget_docline_model()
if self.purchase_request:
res.append("purchase.request.line")
return res

def _get_document_number(self, doc):
if doc._name == "purchase.request.line":
return f"{doc.request_id._name},{doc.request_id.id}"
return super()._get_document_number(doc)

def _get_base_domain_extension(self, res_model):
"""For module extension"""
if res_model == "purchase.request.line":
return " AND a.request_state != 'rejected'"
return super()._get_base_domain_extension(res_model)


class BudgetCommitForwardLine(models.Model):
_inherit = "budget.commit.forward.line"

res_model = fields.Selection(
selection_add=[("purchase.request.line", "Purchase Request Line")],
ondelete={"purchase.request.line": "cascade"},
)
document_id = fields.Reference(
selection_add=[("purchase.request.line", "Purchase Request Line")],
ondelete={"purchase.request.line": "cascade"},
)
document_number = fields.Reference(
selection_add=[("purchase.request", "Purchase Request")],
ondelete={"purchase.request": "cascade"},
)
14 changes: 14 additions & 0 deletions budget_control_purchase_request/models/budget_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


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

amount_purchase_request = fields.Monetary(
string="Purchase Request",
compute="_compute_budget_info",
help="Sum of purchase amount",
)
38 changes: 38 additions & 0 deletions budget_control_purchase_request/models/budget_period.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2020 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


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

purchase_request = fields.Boolean(
string="On Purchase Request",
compute="_compute_control_purchase_request",
store=True,
readonly=False,
help="Control budget on purchase request approved",
)

def _budget_info_query(self):
query = super()._budget_info_query()
query["info_cols"]["amount_purchase_request"] = ("2_pr_commit", True)
return query

@api.depends("control_budget")
def _compute_control_purchase_request(self):
for rec in self:
rec.purchase_request = rec.control_budget

@api.model
def _get_eligible_budget_period(self, date=False, doc_type=False):
budget_period = super()._get_eligible_budget_period(date, doc_type)
# Get period control budget.
# if doctype is purchase_request, check special control too.
if doc_type == "purchase_request":
return budget_period.filtered(
lambda l: (l.control_budget and l.purchase_request)
or (not l.control_budget and l.purchase_request)
)
return budget_period
36 changes: 36 additions & 0 deletions budget_control_purchase_request/models/purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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 PurchaseOrder(models.Model):
_inherit = "purchase.order"

def write(self, vals):
"""Uncommit budget for source purchase request document."""
res = super().write(vals)
if vals.get("state") in ("purchase", "cancel"):
self.mapped("order_line.purchase_request_lines").recompute_budget_move()
return res


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

def uncommit_purchase_request_budget(self):
"""For purchase in valid state, do uncommit for related PR."""
for po_line in self:
po_state = po_line.order_id.state
if self.env.context.get("force_commit") or po_state in ("purchase", "done"):
for pr_line in po_line.purchase_request_lines.filtered("amount_commit"):
pr_line.commit_budget(
reverse=True,
analytic_account_id=pr_line.fwd_analytic_distribution or False,
purchase_line_id=po_line.id,
date=po_line.date_commit,
)
else: # Cancel or draft, not commitment line
self.env["purchase.request.budget.move"].search(
[("purchase_line_id", "=", po_line.id)]
).unlink()
23 changes: 23 additions & 0 deletions budget_control_purchase_request/models/purchase_budget_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2020 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 PurchaseBudgetMove(models.Model):
_inherit = "purchase.budget.move"

@api.depends("purchase_id")
def _compute_source_document(self):
res = super()._compute_source_document()
for rec in self.filtered(lambda l: l.purchase_line_id.purchase_request_lines):
rec.source_document = (
rec.source_document
if rec.source_document
else ", ".join(
rec.purchase_line_id.purchase_request_lines.mapped(
"request_id.name"
)
)
)
return res
Loading

0 comments on commit f8974b1

Please sign in to comment.