-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Conversation
c059b8a
to
c5c7475
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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.
386e050
to
1c49c52
Compare
1c49c52
to
8b5454b
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
account_move = sheet.account_move_ids | |
account_moves = sheet.account_move_ids |
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) |
There was a problem hiding this comment.
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:
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( |
There was a problem hiding this comment.
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
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 | ||
) |
There was a problem hiding this comment.
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:
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), | |
] | |
) |
exp_move_line.move_id.button_draft() | ||
exp_move_line.move_id.button_cancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
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() |
There was a problem hiding this comment.
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
def _cancel_payments(self, payments): | ||
for rec in payments: | ||
rec.move_id.button_draft() | ||
rec.move_id.button_cancel() |
There was a problem hiding this comment.
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?
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. |
Depends on #229
Some edits for this module :
the method on
hr.expense.sheet
is namedaction_approve_expense_sheets
and no moreapprove_expense_sheets
on
hr.expense.sheet
the fieldaccount_move_id
was changed toaccount_move_ids