Skip to content

Commit

Permalink
[MIG] budget_control_advance_clearing: 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 746f900 commit 3722250
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 91 deletions.
6 changes: 3 additions & 3 deletions budget_control_advance_clearing/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Budget Control on Expense extension on Advance/Clearing
: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_advance_clearing
:target: https://github.com/ecosoft-odoo/budgeting/tree/16.0/budget_control_advance_clearing
:alt: ecosoft-odoo/budgeting

|badge1| |badge2| |badge3|
Expand All @@ -41,7 +41,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_advance_clearing%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_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.

Expand Down Expand Up @@ -70,6 +70,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_advance_clearing>`_ project on GitHub.
This module is part of the `ecosoft-odoo/budgeting <https://github.com/ecosoft-odoo/budgeting/tree/16.0/budget_control_advance_clearing>`_ project on GitHub.

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

{
"name": "Budget Control on Expense extension on Advance/Clearing",
"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",
Expand Down
43 changes: 22 additions & 21 deletions budget_control_advance_clearing/models/budget_commit_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,32 @@ def _get_document_number(self, doc):
return f"{doc.sheet_id._name},{doc.sheet_id.id}"
return super()._get_document_number(doc)

def _get_commit_docline(self, res_model):
def _get_name_model(self, res_model, need_replace=False):
if res_model == "hr.expense.advance":
if need_replace:
return "hr_expense"
return "hr.expense"
return super()._get_name_model(res_model, need_replace)

def _get_base_from_extension(self, res_model):
"""For module extension"""
if res_model != "hr.expense.advance":
return super()._get_base_from_extension(res_model)
query_from = "JOIN hr_expense_sheet sheet ON sheet.id = a.sheet_id"
return query_from

def _get_base_domain_extension(self, res_model):
"""For module extension"""
if res_model not in ["hr.expense.advance", "hr.expense"]:
return super()._get_commit_docline(res_model)
domain = self._get_base_domain()
domain.extend(
[
("analytic_account_id", "!=", False),
("state", "!=", "cancel"),
]
)
return super()._get_base_domain_extension(res_model)

query_where = " AND a.state != 'cancel'"
# Special case, model = hr.expense with advance
if res_model == "hr.expense.advance":
domain.extend(
[
("advance", "=", True),
("sheet_id.clearing_residual", ">", 0.0),
]
)
query_where += " AND a.advance = True AND sheet.clearing_residual > 0.0"
else:
domain.extend(
[
("advance", "=", False), # Additional criteria
]
)
return self.env["hr.expense"].search(domain)
query_where += " AND a.advance = False"
return query_where


class BudgetCommitForwardLine(models.Model):
Expand Down
88 changes: 66 additions & 22 deletions budget_control_advance_clearing/models/hr_expense.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 api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import UserError


class HRExpenseSheet(models.Model):
Expand Down Expand Up @@ -55,15 +56,32 @@ def _filter_current_move(self, analytic):
)
return super()._filter_current_move(analytic)

@api.depends("advance_budget_move_ids", "budget_move_ids")
@api.depends("advance_budget_move_ids", "budget_move_ids", "budget_move_ids.date")
def _compute_commit(self):
advances = self.filtered("advance")
expenses = self - advances
# Advances
for rec in advances:
debit = sum(rec.advance_budget_move_ids.mapped("debit"))
credit = sum(rec.advance_budget_move_ids.mapped("credit"))
rec.amount_commit = debit - credit
analytic_distribution = rec[self._budget_analytic_field]
# Add analytic_distribution from forward_commit
if rec.fwd_analytic_distribution:
for analytic_id, aa_percent in rec.fwd_analytic_distribution.items():
analytic_distribution[analytic_id] = aa_percent

if not analytic_distribution:
continue

# Compute amount commit each analytic
amount_commit_json = {}
for analytic_id in analytic_distribution: # Get id only
budget_move = rec.advance_budget_move_ids.filtered(
lambda move: move.analytic_account_id.id == int(analytic_id)
)
debit = sum(budget_move.mapped("debit"))
credit = sum(budget_move.mapped("credit"))
amount_commit_json[analytic_id] = debit - credit
rec.amount_commit = amount_commit_json

if rec.advance_budget_move_ids:
rec.date_commit = min(rec.advance_budget_move_ids.mapped("date"))
else:
Expand Down Expand Up @@ -106,11 +124,6 @@ def _get_recompute_advances(self):
).recompute_budget_move()
advance_sheet = advances.mapped("sheet_id")
advance_sheet.ensure_one()
# If the advances has any clearing, uncommit them from advance
clearings = self.search(
[("sheet_id.advance_sheet_id", "=", advance_sheet.id)]
)
clearings.uncommit_advance_budget()
# If the advances has any reconcile (return advance),
# reverse commit them from advance
aml_debit = advance_sheet.account_move_id.line_ids.filtered(
Expand All @@ -130,6 +143,11 @@ def _get_recompute_advances(self):
move_line_id=return_ml.id,
date=return_ml.date_commit,
)
# If the advances has any clearing, uncommit them from advance
clearings = self.search(
[("sheet_id.advance_sheet_id", "=", advance_sheet.id)], order="id"
)
clearings.uncommit_advance_budget()
return res

def _close_budget_sheets_with_adj_commit(self):
Expand Down Expand Up @@ -189,6 +207,7 @@ def uncommit_advance_budget(self):
clearing_approved.sorted(key=lambda l: l.date_commit)
+ clearing_not_approved
)
config_budget_include_tax = self.env.company.budget_include_tax
for clearing in clearing_sorted:
cl_state = clearing.sheet_id.state
if self.env.context.get("force_commit") or cl_state in (
Expand All @@ -200,29 +219,54 @@ def uncommit_advance_budget(self):
# just return amount line by line
origin_clearing_amount = (
clearing.total_amount
if self.env.company.budget_include_tax
if config_budget_include_tax
else clearing.untaxed_amount
)
while origin_clearing_amount > 0:
advance_sheet = clearing.sheet_id.advance_sheet_id
advances = advance_sheet.expense_line_ids.filtered("amount_commit")
if not advances:
break
clearing_analytic = clearing.analytic_distribution
advance_sheet = clearing.sheet_id.advance_sheet_id
advance_lines = advance_sheet.expense_line_ids

advances = advance_lines.filtered("amount_commit")
if not advances:
continue

# Check analytic distribution match with advance
advance_analytic = {}
for av_line in advance_lines:
if av_line.fwd_analytic_distribution:
advance_analytic.update(av_line.fwd_analytic_distribution)
advance_analytic.update(av_line.analytic_distribution)
clearing_analytic_ids = [x for x in clearing_analytic]
advance_analytic_ids = [x for x in advance_analytic]

if any(aa not in advance_analytic_ids for aa in clearing_analytic_ids):
raise UserError(
_(
"Analytic distribution mismatch. "
"Please align with the original advance."
)
)
# Uncommit budget to advance line by line
for analyic_id, aa_percent in clearing_analytic.items():
clearing_amount = origin_clearing_amount * aa_percent / 100
for advance in advances:
clearing_amount = min(
advance.amount_commit, origin_clearing_amount
if not advance.amount_commit.get(str(analyic_id)):
continue

clearing_amount_commit = min(
advance.amount_commit[str(analyic_id)], clearing_amount
)
origin_clearing_amount -= clearing_amount
clearing_amount -= clearing_amount_commit
budget_move = advance.commit_budget(
reverse=True,
clearing_id=clearing.id,
amount_currency=clearing_amount,
analytic_account_id=advance.fwd_analytic_account_id
amount_currency=clearing_amount_commit,
analytic_account_id=advance.fwd_analytic_distribution
or False,
date=clearing.date_commit,
)
budget_moves |= budget_move
if origin_clearing_amount <= 0:
if clearing_amount <= 0:
break
else:
# Cancel or draft, not commitment line
Expand Down
14 changes: 7 additions & 7 deletions budget_control_advance_clearing/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 (goodger@python.org)
: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 @@ -369,7 +369,7 @@ <h1 class="title">Budget Control on Expense extension on Advance/Clearing</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bcf8834b892bb6a3bc48ad39bf03d25c79988339d47eac638e12e5de5a1914e3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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_advance_clearing"><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_advance_clearing"><img alt="ecosoft-odoo/budgeting" src="https://img.shields.io/badge/github-ecosoft--odoo%2Fbudgeting-lightgray.png?logo=github" /></a></p>
<p>This module relate clearing expense with advance, and make ensure that clearing expense
will make budget commitment only in excess of advance amount.</p>
<div class="admonition important">
Expand All @@ -395,7 +395,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_advance_clearing%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_advance_clearing%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 @@ -417,7 +417,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_advance_clearing">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_advance_clearing">ecosoft-odoo/budgeting</a> project on GitHub.</p>
<p>You are welcome to contribute.</p>
</div>
</div>
Expand Down
10 changes: 3 additions & 7 deletions budget_control_advance_clearing/views/budget_period_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
<field name="model">budget.period</field>
<field name="inherit_id" ref="budget_control.budget_period_view_form" />
<field name="arch" type="xml">
<div name="account" position="after">
<label for="advance" invisible="1" />
<div name="advance" class="o_row">
<field name="advance" />
<span>On Advance</span>
</div>
</div>
<xpath expr="//group[@name='budget_period_control']" position="inside">
<field name="advance" />
</xpath>
</field>
</record>
</odoo>
33 changes: 3 additions & 30 deletions budget_control_advance_clearing/views/hr_expense_view.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="hr_expense_view_form" model="ir.ui.view">
<field name="name">hr.expense.view.form</field>
<field name="model">hr.expense</field>
<field
name="inherit_id"
ref="hr_expense_advance_clearing.hr_expense_view_form"
/>
<field name="arch" type="xml">
<!-- Bring back, as removed from hr_expense_advance_clearing -->
<field name="analytic_account_id" position="attributes">
<attribute name="attrs">
{'readonly': [('is_editable', '=', False)]}
</attribute>
<attribute name="force_save">1</attribute>
</field>
<field name="analytic_tag_ids" position="attributes">
<attribute name="attrs">
{'readonly': [('is_editable', '=', False)]}
</attribute>
<attribute name="force_save">1</attribute>
</field>
</field>
</record>
<record id="view_hr_expense_sheet_form" model="ir.ui.view">
<field name="name">view.hr.expense.sheet.form</field>
<field name="model">hr.expense.sheet</field>
Expand All @@ -34,7 +11,7 @@
name="advance_budget_commit"
attrs="{'invisible': [('advance_budget_move_ids', '=', [])]}"
>
<div class="oe_read_only oe_right" name="buttons">
<div class="oe_right" name="buttons">
<button
type="object"
name="recompute_budget_move"
Expand All @@ -53,15 +30,11 @@
<field name="advance_budget_move_ids" readonly="1">
<tree>
<field name="expense_id" optional="show" />
<field name="clearing_id" optional="show" />
<field name="move_id" />
<field name="date" />
<field name="analytic_group" optional="show" />
<field name="analytic_plan" optional="show" />
<field name="analytic_account_id" optional="show" />
<field
name="analytic_tag_ids"
optional="hide"
widget="many2many_tags"
/>
<field name="write_uid" optional="show" />
<field name="write_date" optional="show" />
<field name="note" optionl="hide" />
Expand Down

0 comments on commit 3722250

Please sign in to comment.