Skip to content

Commit

Permalink
[MIG] budget_control_purchase: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Aug 2, 2024
1 parent 36e39dc commit 7b2cb41
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 100 deletions.
8 changes: 4 additions & 4 deletions budget_control_purchase/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Budget Control on Purchase
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5b932565eafae9e063032f1ff796f89eb7ab9f5dc842b33f02d64bd3d23044ae
!! source digest: sha256:b1d5c0b5a5b3553d6c68a33ab89e36d4c73c02c496414a29bd59651f9ea90c24
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
Expand All @@ -17,7 +17,7 @@ Budget Control on Purchase
: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/15.0/budget_control_purchase
:target: https://github.com/ecosoft-odoo/budgeting/tree/16.0/budget_control_purchase
:alt: ecosoft-odoo/budgeting

|badge1| |badge2| |badge3|
Expand Down Expand Up @@ -45,7 +45,7 @@ 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%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/ecosoft-odoo/budgeting/issues/new?body=module:%20budget_control_purchase%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.

Expand Down Expand Up @@ -74,6 +74,6 @@ Current maintainer:

|maintainer-kittiu|

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

You are welcome to contribute.
3 changes: 2 additions & 1 deletion budget_control_purchase/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

{
"name": "Budget Control on Purchase",
"version": "15.0.1.0.0",
"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"],
"data": [
"security/ir.model.access.csv",
"views/purchase_budget_move.xml",
"views/budget_period_view.xml",
"views/purchase_view.xml",
"views/budget_control_view.xml",
Expand Down
48 changes: 26 additions & 22 deletions budget_control_purchase/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# 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
from odoo import _, models
from odoo.exceptions import UserError


class AccountMoveLine(models.Model):
Expand Down Expand Up @@ -29,7 +30,7 @@ def _get_qty_commit(self, purchase_line):

def uncommit_purchase_budget(self):
"""For vendor bill in valid state, do uncommit for related purchase."""
ForwardLine = self.env["budget.commit.forward.line"]
# ForwardLine =self.env["budget.commit.forward.line"]
for ml in self.filtered(
lambda l: l.move_id.move_type in ("in_invoice", "in_refund")
):
Expand All @@ -49,33 +50,36 @@ def uncommit_purchase_budget(self):
qty = ml._get_qty_commit(purchase_line)
if qty <= 0 and not ml._check_skip_negative_qty():
continue

Check warning on line 52 in budget_control_purchase/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

budget_control_purchase/models/account_move_line.py#L52

Added line #L52 was not covered by tests
# Check analytic distribution,
# Not allow to change analytic distribution is not depend on PO
purchase_analytic = purchase_line[purchase_line._budget_analytic_field]
# Add analytic_distribution from forward_commit
if purchase_line.fwd_analytic_distribution:
for (
analytic_id,
aa_percent,
) in purchase_line.fwd_analytic_distribution.items():
purchase_analytic[analytic_id] = aa_percent

Check warning on line 62 in budget_control_purchase/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

budget_control_purchase/models/account_move_line.py#L62

Added line #L62 was not covered by tests

ml_analytic_ids = [x for x in ml.analytic_distribution]
purchase_analytic_ids = [x for x in purchase_analytic]
if any(aa not in purchase_analytic_ids for aa in ml_analytic_ids):
raise UserError(

Check warning on line 67 in budget_control_purchase/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

budget_control_purchase/models/account_move_line.py#L67

Added line #L67 was not covered by tests
_(
"Analytic distribution mismatch. "
"Please align with the original purchase order."
)
)

# Only case reverse and want to return_amount_commit
context = {}
if move_type == "in_invoice" and ml.return_amount_commit:
context["return_amount_commit"] = ml.amount_commit

Check warning on line 77 in budget_control_purchase/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

budget_control_purchase/models/account_move_line.py#L77

Added line #L77 was not covered by tests
# Check case forward commit, it should uncommit with forward commit or old analytic
analytic_account = False
if purchase_line.fwd_analytic_account_id:
# Case actual use analytic same as PO Commit, it will uncommit with PO analytic
if purchase_line.account_analytic_id == ml.analytic_account_id:
analytic_account = purchase_line.account_analytic_id
else:
# Case actual commit is use analytic not same as PO Commit
domain_fwd_line = self._get_domain_fwd_line(purchase_line)
fwd_lines = ForwardLine.search(domain_fwd_line)
for fwd_line in fwd_lines:
if (
fwd_line.forward_id.to_budget_period_id.bm_date_from
<= ml.date_commit
<= fwd_line.forward_id.to_budget_period_id.bm_date_to
):
analytic_account = fwd_line.to_analytic_account_id
break
# Confirm vendor bill, do uncommit budget
context["product_qty"] = qty
purchase_line.with_context(**context).commit_budget(
reverse=move_type == "in_invoice",
analytic_distribution=ml.analytic_distribution,
move_line_id=ml.id,
analytic_account_id=analytic_account,
product_qty=qty,
date=ml.date_commit,
)
14 changes: 4 additions & 10 deletions budget_control_purchase/models/budget_commit_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ def _get_document_number(self, doc):
return f"{doc.order_id._name},{doc.order_id.id}"
return super()._get_document_number(doc)

Check warning on line 29 in budget_control_purchase/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control_purchase/models/budget_commit_forward.py#L28-L29

Added lines #L28 - L29 were not covered by tests

def _get_commit_docline(self, res_model):
def _get_base_domain_extension(self, res_model):
"""For module extension"""
if res_model == "purchase.order.line":
domain = self._get_base_domain()
domain.extend(
[
("account_analytic_id", "!=", False),
("state", "!=", "cancel"),
]
)
return self.env[res_model].search(domain)
return super()._get_commit_docline(res_model)
return " AND a.state != 'cancel'"
return super()._get_base_domain_extension(res_model)

Check warning on line 35 in budget_control_purchase/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control_purchase/models/budget_commit_forward.py#L34-L35

Added lines #L34 - L35 were not covered by tests


class BudgetCommitForwardLine(models.Model):
Expand Down
26 changes: 15 additions & 11 deletions budget_control_purchase/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def write(self, vals):

def button_confirm(self):
res = super().button_confirm()
self.flush()
self.flush_model()
BudgetPeriod = self.env["budget.period"]
for doc in self.filtered(lambda l: l.state == "purchase"):
BudgetPeriod.check_budget(doc.order_line, doc_type="purchase")
Expand All @@ -53,7 +53,7 @@ def button_confirm(self):
class PurchaseOrderLine(models.Model):
_name = "purchase.order.line"
_inherit = ["purchase.order.line", "budget.docline.mixin"]
_budget_analytic_field = "account_analytic_id"
_budget_analytic_field = "analytic_distribution"
_budget_date_commit_fields = ["order_id.write_date"]
_budget_move_model = "purchase.budget.move"
_doc_rel = "order_id"
Expand Down Expand Up @@ -103,30 +103,34 @@ def _get_po_line_account(self):
account = self.product_id.product_tmpl_id.get_product_accounts(fpos)["expense"]
return account

def _init_docline_budget_vals(self, budget_vals):
def _init_docline_budget_vals(self, budget_vals, analytic_id):
self.ensure_one()
product_qty = self.product_qty
if "product_qty" in budget_vals and budget_vals.get("product_qty"):
product_qty = budget_vals.pop("product_qty")
budget_vals["amount_currency"] = self.price_unit * product_qty
# Use product qty from context, if not, use line product_qty
product_qty = self.env.context.get("product_qty") or self.product_qty
# If not analytic_id, use 100% of the line
percent_analytic = (
self[self._budget_analytic_field].get(str(analytic_id)) or 100
)
budget_vals["amount_currency"] = (
self.price_unit * product_qty * percent_analytic / 100
)
budget_vals["tax_ids"] = self.taxes_id.ids
# Document specific vals
budget_vals.update(
{
"purchase_line_id": self.id,
"analytic_tag_ids": [(6, 0, self.analytic_tag_ids.ids)],
}
)
return super()._init_docline_budget_vals(budget_vals)
return super()._init_docline_budget_vals(budget_vals, analytic_id)

def _valid_commit_state(self):
return self.state in ["purchase", "done"]

def _prepare_account_move_line(self, move=False):
self.ensure_one()
res = super()._prepare_account_move_line(move)
if res.get("analytic_account_id") and self.fwd_analytic_account_id:
res["analytic_account_id"] = self.fwd_analytic_account_id.id
if res.get("analytic_distribution") and self.fwd_analytic_distribution:
res["analytic_distribution"] = self.fwd_analytic_distribution

Check warning on line 133 in budget_control_purchase/models/purchase.py

View check run for this annotation

Codecov / codecov/patch

budget_control_purchase/models/purchase.py#L133

Added line #L133 was not covered by tests
return res

def _get_included_tax(self):
Expand Down
16 changes: 8 additions & 8 deletions budget_control_purchase/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Budget Control on Purchase</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5b932565eafae9e063032f1ff796f89eb7ab9f5dc842b33f02d64bd3d23044ae
!! source digest: sha256:b1d5c0b5a5b3553d6c68a33ab89e36d4c73c02c496414a29bd59651f9ea90c24
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/ecosoft-odoo/budgeting/tree/15.0/budget_control_purchase"><img alt="ecosoft-odoo/budgeting" src="https://img.shields.io/badge/github-ecosoft--odoo%2Fbudgeting-lightgray.png?logo=github" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/ecosoft-odoo/budgeting/tree/16.0/budget_control_purchase"><img alt="ecosoft-odoo/budgeting" src="https://img.shields.io/badge/github-ecosoft--odoo%2Fbudgeting-lightgray.png?logo=github" /></a></p>
<p>This module will create budget commitment for purchase (to be used as alternate actual source in mis_builder)</p>
<p>When purchase order is confirmed, purchase.budget.commit is created, and when
vendor billed is confirmed, reversed purchase.budget.commit is created.</p>
Expand Down Expand Up @@ -397,7 +397,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/ecosoft-odoo/budgeting/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/ecosoft-odoo/budgeting/issues/new?body=module:%20budget_control_purchase%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/ecosoft-odoo/budgeting/issues/new?body=module:%20budget_control_purchase%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -419,7 +419,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>Current maintainer:</p>
<p><a class="reference external image-reference" href="https://github.com/kittiu"><img alt="kittiu" src="https://github.com/kittiu.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/ecosoft-odoo/budgeting/tree/15.0/budget_control_purchase">ecosoft-odoo/budgeting</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/ecosoft-odoo/budgeting/tree/16.0/budget_control_purchase">ecosoft-odoo/budgeting</a> project on GitHub.</p>
<p>You are welcome to contribute.</p>
</div>
</div>
Expand Down
Loading

0 comments on commit 7b2cb41

Please sign in to comment.