Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] hr_expense_cancel #233

Open
wants to merge 24 commits into
base: 17.0
Choose a base branch
from

Conversation

imlopes
Copy link

@imlopes imlopes commented May 15, 2024

Depends on #229

Some edits for this module :

  • the method on hr.expense.sheet is named action_approve_expense_sheets and no more approve_expense_sheets

  • on hr.expense.sheet the field account_move_id was changed to account_move_ids

@imlopes imlopes force-pushed the 17.0-mig-hr_expense_cancel branch 2 times, most recently from c059b8a to c5c7475 Compare May 15, 2024 19:34
@imlopes imlopes marked this pull request as ready for review May 15, 2024 19:57
Copy link

@vvrossem vvrossem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.
Pre-approving regarding Red Travis

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're changing account_move_id single record to multiple account_move_ids.
Have you checked for example self._remove_move_reconcile(payments, account_move) can take as an argument multiple moves?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @yankinmax
I'm not changing the field account_move_id.
It was changed on odoo source when migrating to 17.0

Here if I'm not wrong : OCA/OCB@68fbdc9#diff-42c75e4d29952aadf0abdd1bfe7e066bef3db1275c16d64dd3f3b96a332a2ff3

ernestotejeda and others added 23 commits May 24, 2024 11:01
This module lets to cancel and correct expenses. It adds a cancel
button on the expense sheet that undo reconciliations and delete
payments and journal entries.
The multi own account test has been removed as it is no longer possible
in odoo core to register the payment of several expense sheet reports at
the same time.

Co-Authored By:
Stefan Ungureanu
aiendry-aktivsoftware
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: hr-expense-16.0/hr-expense-16.0-hr_expense_cancel
Translate-URL: https://translation.odoo-community.org/projects/hr-expense-16-0/hr-expense-16-0-hr_expense_cancel/
Currently translated at 100.0% (3 of 3 strings)

Translation: hr-expense-16.0/hr-expense-16.0-hr_expense_cancel
Translate-URL: https://translation.odoo-community.org/projects/hr-expense-16-0/hr-expense-16-0-hr_expense_cancel/it/
In this version, if a product doesn't have cost, you are only able
to enter total amount, so the test should be adjusted to this
condition.
@imlopes imlopes force-pushed the 17.0-mig-hr_expense_cancel branch 2 times, most recently from 386e050 to 1c49c52 Compare May 24, 2024 14:56
@imlopes imlopes force-pushed the 17.0-mig-hr_expense_cancel branch from 1c49c52 to 8b5454b Compare May 24, 2024 14:57
Copy link

@SilvioC2C SilvioC2C left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few things to fix here and there


def action_cancel(self):
for sheet in self:
account_move = sheet.account_move_ids

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have a X2many field, variable name should be plural

Suggested change
account_move = sheet.account_move_ids
account_moves = sheet.account_move_ids

Comment on lines +19 to +25
if sheet.expense_line_ids[:1].payment_mode == "own_account":
self._remove_move_reconcile(payments, account_move)
self._cancel_payments(payments)
else:
# In this case, during the cancellation the journal entry
# will be deleted
self._cancel_payments(payments)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the else block:

Suggested change
if sheet.expense_line_ids[:1].payment_mode == "own_account":
self._remove_move_reconcile(payments, account_move)
self._cancel_payments(payments)
else:
# In this case, during the cancellation the journal entry
# will be deleted
self._cancel_payments(payments)
if sheet.expense_line_ids[:1].payment_mode == "own_account":
self._remove_move_reconcile(payments, account_move)
self._cancel_payments(payments)

# (if the expense sheet is paid and payment_mode == 'own_account')
# it has not been deleted
if account_move.exists():
move_to_cancel = account_move.filtered(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to moves_to_cancel

Comment on lines +40 to +46
reconcile = account_move.mapped("line_ids.full_reconcile_id")
aml = self.env["account.move.line"].search(
[("full_reconcile_id", "in", reconcile.ids)]
)
exp_move_line = aml.filtered(
lambda line: line.move_id.id not in account_move.ids
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why run a search() only to filter out records right after? All this could be implemented via search() only:

Suggested change
reconcile = account_move.mapped("line_ids.full_reconcile_id")
aml = self.env["account.move.line"].search(
[("full_reconcile_id", "in", reconcile.ids)]
)
exp_move_line = aml.filtered(
lambda line: line.move_id.id not in account_move.ids
)
exp_move_line = self.env["account.move.line"].search(
[
("full_reconcile_id", "in", account_move.line_ids.full_reconcile_id.ids),
("move_id", "not in", account_move.ids),
]
)

Comment on lines +48 to +49
exp_move_line.move_id.button_draft()
exp_move_line.move_id.button_cancel()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exp_move_line.move_id.button_draft()
exp_move_line.move_id.button_cancel()
if exp_move_line:
moves = exp_move_line.move_id
moves.button_draft()
moves.button_cancel()

Comment on lines +54 to +60
reconcile = account_move.mapped("line_ids.full_reconcile_id")
payments_aml = payments.move_id.line_ids
aml_unreconcile = payments_aml.filtered(
lambda r: r.full_reconcile_id in reconcile
)

aml_unreconcile.remove_move_reconcile()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method could be improved just like the one above

Comment on lines +62 to +65
def _cancel_payments(self, payments):
for rec in payments:
rec.move_id.button_draft()
rec.move_id.button_cancel()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self is not even used, maybe we could move this method to the payments model instead?

Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.