Skip to content

Commit

Permalink
[MIG] hr_expense_advance_clearing_consolidation: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigonevest authored and WesleyOliveira98 committed Jan 10, 2024
1 parent f0d3017 commit 11d4fc3
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 130 deletions.
18 changes: 9 additions & 9 deletions hr_expense_advance_clearing_consolidation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Hr Expense Advance Clearing Consolidation
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7b87b9b5cd2a4d9107cde631255eda39d0f52201c6489ac57d064c7e781688d4
!! source digest: sha256:2604ed1287fb981afea2d21294c4c1e38f2d872850c6b1bd3d8c578417821623
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -16,14 +16,14 @@ Hr Expense Advance Clearing Consolidation
.. |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-OCA%2Fhr-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/12.0/hr_expense_advance_clearing_consolidation
:alt: OCA/hr
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--expense-lightgray.png?logo=github
:target: https://github.com/OCA/hr-expense/tree/14.0/hr_expense_advance_clearing_consolidation
:alt: OCA/hr-expense
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_expense_advance_clearing_consolidation
:target: https://translation.odoo-community.org/projects/hr-expense-14-0/hr-expense-14-0-hr_expense_advance_clearing_consolidation
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr&target_branch=12.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-expense&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -38,10 +38,10 @@ This module adds the possibility to consolidate open advances, creating a new ad
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-expense/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/OCA/hr/issues/new?body=module:%20hr_expense_advance_clearing_consolidation%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/hr-expense/issues/new?body=module:%20hr_expense_advance_clearing_consolidation%0Aversion:%2014.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 @@ -73,6 +73,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/12.0/hr_expense_advance_clearing_consolidation>`_ project on GitHub.
This module is part of the `OCA/hr-expense <https://github.com/OCA/hr-expense/tree/14.0/hr_expense_advance_clearing_consolidation>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
21 changes: 11 additions & 10 deletions hr_expense_advance_clearing_consolidation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Hr Expense Advance Clearing Consolidation',
'summary': """
"name": "Hr Expense Advance Clearing Consolidation",
"summary": """
HR Expense Advance Clearing Consolidation""",
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'author': 'Escodoo,Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/hr',
'depends': [
'hr_expense_advance_clearing',
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr-expense",
"depends": [
"hr_expense_advance_clearing",
"account_reconciliation_widget",
],
'data': [
'views/hr_expense_sheet_view.xml',
"data": [
"views/hr_expense_sheet_view.xml",
],
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# Copyright 2022 - TODAY, Marcel Savegnago <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


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

is_consolidated_advance = fields.Boolean(
string='Is Consolidated Advance',
readonly=True
string="Is Consolidated Advance", readonly=True
)

@api.multi
def _consolidate_open_advances(self):
def _consolidate_open_advances(self): # noqa: C901
if not len(self) > 1:
raise UserError(
_(
Expand All @@ -35,11 +33,11 @@ def _consolidate_open_advances(self):
if any(rec.state != "done" for rec in self):
raise UserError(_("You cannot consolidate advances that are not paid."))

if self.env['hr.expense.sheet'].search(
if self.env["hr.expense.sheet"].search(
[
('advance', '=', False),
('state', '!=', 'done'),
('advance_sheet_id', 'in', self.ids)
("advance", "=", False),
("state", "!=", "done"),
("advance_sheet_id", "in", self.ids),
]
):
raise UserError(
Expand All @@ -48,7 +46,6 @@ def _consolidate_open_advances(self):
"report that is open."
)
)

writeoff_lines = self.env["account.move.line"]
emp_advance = self.env.ref("hr_expense_advance_clearing." "product_emp_advance")

Expand All @@ -57,14 +54,24 @@ def _consolidate_open_advances(self):
for line in advance.sudo().account_move_id.line_ids:
if line.account_id == emp_advance.property_account_expense_id:
residual_value += line.amount_residual
writeoff_acc_id = self.env["account.account"].search(
[("code", "=", line.counterpart)]
)
writeoff_journal_id = line.move_id.journal_id
line.reconcile(
writeoff_acc_id=writeoff_acc_id,
writeoff_journal_id=writeoff_journal_id,

line.reconcile()

counterpart_line = self.env["account.move.line"].search(
[
("move_id", "=", line.move_id.id),
("account_id", "!=", line.account_id.id),
]
)

writeoff_vals = {
"account_id": counterpart_line.account_id.id,
"journal_id": line.move_id.journal_id.id,
}

writeoff_to_reconcile = line._create_writeoff([writeoff_vals])
(line + writeoff_to_reconcile).reconcile()

for matched_credit_id in line.matched_credit_ids:
for (
move_line
Expand All @@ -89,12 +96,13 @@ def _consolidate_open_advances(self):
"name": "Consolidated Advance",
"employee_id": employee.id,
"product_id": emp_advance.id,
"account_id": emp_advance.property_account_expense_id.id,
"unit_amount": residual_value,
"sheet_id": consolidated_advance.id,
"advance": True,
}
)
consolidated_advance_line._onchange_product_id()
consolidated_advance_line._onchange_product_id_date_account_id()
consolidated_advance_line.unit_amount = residual_value

# Submitted to Manager
Expand All @@ -117,29 +125,32 @@ def _consolidate_open_advances(self):
if line.debit > 0:
aml_to_reconcile_debit |= line

aml._reconcile_lines(
aml_to_reconcile_debit,
aml_to_reconcile_credit,
"amount_residual_currency",
)
aml_to_reconcile.check_full_reconcile()
aml_to_reconcile.reconcile()
consolidated_advance.set_to_paid()

self._log_consolidation_open_advance(self, consolidated_advance)

return consolidated_advance

@api.multi
def consolidate_open_advances(self):
if self.env.user.has_group("account.group_account_manager"):
self._consolidate_open_advances()
else:
raise UserError(
_("You do not have permission to perform this action.")
)
raise UserError(_("You do not have permission to perform this action."))

@api.multi
def _log_consolidation_open_advance(self, advances, consolidated_advance):
consolidated_advance.message_post(body='%s %s' % (_("Consolidated advances:"), ", ".join('%s (ID %s)' % (p.name or 'n/a', p.id) for p in advances)))
consolidated_advance.message_post(
body="%s %s"
% (
_("Consolidated advances:"),
", ".join("%s (ID %s)" % (p.name or "n/a", p.id) for p in advances),
)
)
for advance in advances:
advance.message_post(body='%s' % (_("This advance was consolidated in the advance: %s (ID %s)") % (consolidated_advance.name or 'n/a', consolidated_advance.id)))
advance.message_post(
body=_("%s")
% (
_("This advance was consolidated in the advance: %s (ID %s)")
% (consolidated_advance.name or "n/a", consolidated_advance.id)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Hr Expense Advance Clearing Consolidation</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7b87b9b5cd2a4d9107cde631255eda39d0f52201c6489ac57d064c7e781688d4
!! source digest: sha256:2604ed1287fb981afea2d21294c4c1e38f2d872850c6b1bd3d8c578417821623
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.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/OCA/hr/tree/12.0/hr_expense_advance_clearing_consolidation"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_expense_advance_clearing_consolidation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr&amp;target_branch=12.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.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/OCA/hr-expense/tree/14.0/hr_expense_advance_clearing_consolidation"><img alt="OCA/hr-expense" src="https://img.shields.io/badge/github-OCA%2Fhr--expense-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-expense-14-0/hr-expense-14-0-hr_expense_advance_clearing_consolidation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr-expense&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds the possibility to consolidate open advances, creating a new advance with the sum of the residual value of all consolidated advances.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand All @@ -385,10 +385,10 @@ <h1 class="title">Hr Expense Advance Clearing Consolidation</h1>
</div>
<div class="section" id="bug-tracker">
<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/OCA/hr/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr-expense/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/OCA/hr/issues/new?body=module:%20hr_expense_advance_clearing_consolidation%0Aversion:%2012.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/OCA/hr-expense/issues/new?body=module:%20hr_expense_advance_clearing_consolidation%0Aversion:%2014.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 @@ -415,7 +415,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr/tree/12.0/hr_expense_advance_clearing_consolidation">OCA/hr</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-expense/tree/14.0/hr_expense_advance_clearing_consolidation">OCA/hr-expense</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Loading

0 comments on commit 11d4fc3

Please sign in to comment.