[FIX] hr_expense: allow minor edits in expense payment

Create an Expense Report
Add an expense paid by company
Submit to manager > Approve > Post journal entries
Choose the payment method to be Checks
Open Accounting dashboard, in Bank card click on 'Checks to print'
Select the check
Print the check

Issue: Action will be blocked by error
"You cannot do this modification since the payment is linked to an expense report."
This occurs because the system does not allow writing to the payment record
once it has been linked to the expense

This commit allow to edit fields that would not trigger a move
synchronize

opw-3633035

closes odoo/odoo#149440

X-original-commit: fa89fcf7a30edf760bbba1920966ed4595e45fe8
Signed-off-by: John Laterre (jol) <jol@odoo.com>
Signed-off-by: Andrea Grazioso (agr) <agr@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2024-01-22 21:10:45 +00:00
parent 09093a51ae
commit 772e713317
2 changed files with 30 additions and 1 deletions
+2 -1
View File
@@ -31,7 +31,8 @@ class AccountPayment(models.Model):
def _synchronize_to_moves(self, changed_fields):
# EXTENDS account
if self.expense_sheet_id:
trigger_fields = set(self._get_trigger_fields_to_synchronize()) | {'ref', 'expense_sheet_id', 'payment_method_line_id'}
if self.expense_sheet_id and any(field_name in trigger_fields for field_name in changed_fields):
raise UserError(_("You cannot do this modification since the payment is linked to an expense report."))
return super()._synchronize_to_moves(changed_fields)
+28
View File
@@ -728,3 +728,31 @@ class TestExpenses(TestExpenseCommon):
expense_sheet.action_approve_expense_sheets()
expense_sheet.action_sheet_move_create()
self.assertRecordValues(expense_sheet.account_move_ids.payment_id, [{'payment_method_line_id': new_payment_method_line.id}])
def test_payment_edit_fields(self):
""" Test payment fields cannot be modified once linked with an expense
"""
sheet = self.env['hr.expense.sheet'].create({
'company_id': self.env.company.id,
'employee_id': self.expense_employee.id,
'name': 'test sheet 2',
'expense_line_ids': [
Command.create({
'name': 'expense_1',
'date': '2016-01-01',
'product_id': self.product_c.id,
'total_amount': 10.0,
'payment_mode': 'company_account',
'employee_id': self.expense_employee.id
}),
],
})
sheet.action_submit_sheet()
sheet.action_approve_expense_sheets()
sheet.action_sheet_move_create()
payment = sheet.account_move_ids.payment_id
with self.assertRaises(UserError, msg="Cannot edit payment amount after linking to an expense"):
payment.write({'amount': 500})
payment.write({'is_move_sent': True})