[FIX] hr_expense: due date conflict with payment terms

Have an employee with payment terms set in the contact form
Create an expense for $100 for the employee
Create the expense report > Submit to manager > Approve > Post journal
entries

Issue: The bill due date is manually set to the Accounting Date.
This is not consistent with the Payment terms applied on the
bill

opw-3298981

closes odoo/odoo#124542

X-original-commit: d363aa12429768e63d0f9def7006101983fd0adc
Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
Signed-off-by: Grazioso Andrea (agr) <agr@odoo.com>
Signed-off-by: Laurent Smet <las@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2023-06-12 12:41:19 +02:00
parent 2476a5b1bb
commit 4caddf1787
2 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ class AccountMove(models.Model):
# Also, expense' account moves are expressed in the company currency.
super()._compute_needed_terms()
for move in self:
if move.expense_sheet_id:
if move.expense_sheet_id and move.expense_sheet_id.payment_mode == 'company_account':
amount_currency = -sum(move.line_ids.filtered(lambda l: l.display_type != 'payment_term').mapped("amount_currency"))
move.needed_terms = {
frozendict(
+24
View File
@@ -900,3 +900,27 @@ class TestExpenses(TestExpenseCommon):
expense.unlink()
self.analytic_account_1.unlink()
def test_expense_sheet_due_date(self):
''' Test expense sheet bill due date'''
self.expense_employee.user_partner_id.property_supplier_payment_term_id = self.env.ref('account.account_payment_term_30days')
expense_sheet = self.env['hr.expense.sheet'].create({
'name': 'Expense for John Smith',
'employee_id': self.expense_employee.id,
'accounting_date': '2021-01-01',
'expense_line_ids': [(0, 0, {
'name': 'Car Travel Expenses',
'employee_id': self.expense_employee.id,
'product_id': self.product_a.id,
'unit_amount': 350.00,
})]
})
expense_sheet.action_submit_sheet()
expense_sheet.action_approve_expense_sheets()
expense_sheet.action_sheet_move_create()
move = expense_sheet.account_move_id
expected_date = fields.Date.from_string('2021-01-31')
self.assertEqual(move.invoice_date_due, expected_date, 'Bill due date should follow employee payment terms')