Skip to content

Commit

Permalink
[MIG] hr_expense_cancel: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ilo committed May 15, 2024
1 parent 03f0d6e commit c5c7475
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions hr_expense_cancel/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Contributors
- Danh Vo <https://github.com/danhvophuong>
- Saran Lim. <saranl@ecosoft.co.th>
- Manuel Regidor <manuel.regidor@sygel.es>
- Italo LOPES <italo.lopes@camptocamp.com>

Maintainers
-----------
Expand Down
18 changes: 12 additions & 6 deletions hr_expense_cancel/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class HrExpenseSheet(models.Model):

def action_cancel(self):
for sheet in self:
account_move = sheet.account_move_id
sheet.account_move_id = False
account_move = sheet.account_move_ids
sheet.account_move_ids = False
payments = sheet.payment_ids.filtered(lambda line: line.state != "cancel")
# case : cancel invoice from hr_expense
self._remove_reconcile_hr_invoice(account_move)
# If the sheet is paid then remove payments
if sheet.state == "done":
if sheet.state in ("done", "approve"):
if sheet.expense_line_ids[:1].payment_mode == "own_account":
self._remove_move_reconcile(payments, account_move)
self._cancel_payments(payments)
Expand All @@ -27,8 +27,11 @@ def action_cancel(self):
# (if the expense sheet is paid and payment_mode == 'own_account')
# it has not been deleted
if account_move.exists():
if account_move.state != "draft":
account_move.button_cancel()
move_to_cancel = account_move.filtered(
lambda move: move.state != "draft"
)
if move_to_cancel:
move_to_cancel.button_cancel()
account_move.with_context(force_delete=True).unlink()
sheet.state = "submit"

Expand All @@ -38,7 +41,9 @@ def _remove_reconcile_hr_invoice(self, account_move):
aml = self.env["account.move.line"].search(
[("full_reconcile_id", "in", reconcile.ids)]
)
exp_move_line = aml.filtered(lambda line: line.move_id.id != account_move.id)
exp_move_line = aml.filtered(
lambda line: line.move_id.id not in account_move.ids
)
# set state to cancel
exp_move_line.move_id.button_draft()
exp_move_line.move_id.button_cancel()
Expand All @@ -56,4 +61,5 @@ def _remove_move_reconcile(self, payments, account_move):

def _cancel_payments(self, payments):
for rec in payments:
rec.move_id.button_draft()
rec.move_id.button_cancel()
1 change: 1 addition & 0 deletions hr_expense_cancel/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Danh Vo \<<https://github.com/danhvophuong>\>
- Saran Lim. \<<saranl@ecosoft.co.th>\>
- Manuel Regidor \<<manuel.regidor@sygel.es>\>
- Italo LOPES \<<italo.lopes@camptocamp.com>\>
1 change: 1 addition & 0 deletions hr_expense_cancel/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Danh Vo &lt;<a class="reference external" href="https://github.com/danhvophuong">https://github.com/danhvophuong</a>&gt;</li>
<li>Saran Lim. &lt;<a class="reference external" href="mailto:saranl&#64;ecosoft.co.th">saranl&#64;ecosoft.co.th</a>&gt;</li>
<li>Manuel Regidor &lt;<a class="reference external" href="mailto:manuel.regidor&#64;sygel.es">manuel.regidor&#64;sygel.es</a>&gt;</li>
<li>Italo LOPES &lt;<a class="reference external" href="mailto:italo.lopes&#64;camptocamp.com">italo.lopes&#64;camptocamp.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
10 changes: 5 additions & 5 deletions hr_expense_cancel/tests/test_hr_expense_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setUp(self):
"journal_id": self.expense_journal.id,
}
)
self.expense_sheet.approve_expense_sheets()
self.expense_sheet.action_approve_expense_sheets()

self.expense = self.env["hr.expense"].create(
{
Expand Down Expand Up @@ -62,12 +62,12 @@ def test_action_cancel_posted(self):
self.expense_sheet.action_sheet_move_create()

self.assertFalse(len(self.expense_sheet.payment_ids), 1)
self.assertTrue(self.expense_sheet.account_move_id)
self.assertTrue(self.expense_sheet.account_move_ids)

self.expense_sheet.action_cancel()

self.assertFalse(self.expense_sheet.payment_ids)
self.assertFalse(self.expense_sheet.account_move_id)
self.assertFalse(self.expense_sheet.account_move_ids)

def test_action_cancel_no_update_posted(self):
journals = self.payment_journal | self.expense_journal
Expand All @@ -79,9 +79,9 @@ def test_action_cancel_no_update_posted(self):
def test_action_cancel_company_account(self):
self.expense.payment_mode = "company_account"
self.expense_sheet.action_sheet_move_create()
self.assertTrue(self.expense_sheet.account_move_id)
self.assertTrue(self.expense_sheet.account_move_ids)
self.expense_sheet.action_cancel()
self.assertFalse(self.expense_sheet.account_move_id)
self.assertFalse(self.expense_sheet.account_move_ids)

def test_action_cancel_own_account(self):
self.expense_sheet.action_sheet_move_create()
Expand Down
2 changes: 1 addition & 1 deletion hr_expense_cancel/views/hr_expense_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<xpath expr="//header/field[@name='state']" position="before">
<button
name="action_cancel"
states="post,done"
invisible="state not in ('post', 'done')"
string="Cancel all related operations"
type="object"
groups="account.group_account_manager"
Expand Down

0 comments on commit c5c7475

Please sign in to comment.