Skip to content

Commit

Permalink
Merge remote-tracking branch 'odoo/18.0' into 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
OCA-git-bot committed Feb 23, 2025
2 parents bf8a9c4 + 4fb8c72 commit 19d4af0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
4 changes: 3 additions & 1 deletion addons/sale_timesheet/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def _timesheet_domain_get_invoiced_lines(self, sale_line_delivery):
('project_id', '!=', False),
'|', '|',
('timesheet_invoice_id', '=', False),
('timesheet_invoice_id.state', '=', 'cancel'),
'&',
('timesheet_invoice_id.state', '=', 'cancel'),
('timesheet_invoice_id.payment_state', '!=', 'invoicing_legacy'),
('timesheet_invoice_id.payment_state', '=', 'reversed')
]

Expand Down
2 changes: 1 addition & 1 deletion addons/sale_timesheet/models/hr_timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _is_readonly(self):

def _is_not_billed(self):
self.ensure_one()
return not self.timesheet_invoice_id or self.timesheet_invoice_id.state == 'cancel'
return not self.timesheet_invoice_id or (self.timesheet_invoice_id.state == 'cancel' and self.timesheet_invoice_id.payment_state != 'invoicing_legacy')

def _check_timesheet_can_be_billed(self):
return self.so_line in self.project_id.mapped('sale_line_employee_ids.sale_line_id') | self.task_id.sale_line_id | self.project_id.sale_line_id
Expand Down
40 changes: 40 additions & 0 deletions addons/sale_timesheet/tests/test_project_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,43 @@ def test_project_form_view(self):
self.assertEqual(project_form.partner_id, self.so.partner_id, 'The partner should be the one defined the SO linked to the SOL defined in the mapping.')
project = project_form.save()
self.assertEqual(project.pricing_type, 'employee_rate', 'Since there is a mapping in this project, the pricing type should be employee rate.')

def test_take_into_account_invoicing_app_legacy(self):
""" Test the timesheets linked to a invoice determined as a invoiced imported form app legacy
are still considered as billed even if the state of those invoices is cancelled.
Since the account_accountant module is not in the dependencies of sale_timesheet module,
this test will manually set the state and payment_status to be in the same condition
than the feature "Invoicing Switch Threshold".
"""
timesheet1 = self.env['account.analytic.line'].create({
'name': '/',
'project_id': self.project_task_rate.id,
'unit_amount': 1,
'so_line': self.so1_line_deliver_no_task.id,
'is_so_line_edited': True,
'employee_id': self.employee_user.id,
})

self.assertEqual(self.so1_line_deliver_no_task.qty_delivered, timesheet1.unit_amount)
invoice1 = self.sale_order_1._create_invoices()[0]
invoice1.action_post()

self.assertEqual(self.so1_line_deliver_no_task.qty_invoiced, 1)
self.assertEqual(timesheet1.timesheet_invoice_id, invoice1)

timesheet2 = self.env['account.analytic.line'].create({
'project_id': self.project_task_rate.id,
'unit_amount': 2,
'so_line': self.so1_line_deliver_no_task.id,
'is_so_line_edited': True,
'employee_id': self.employee_user.id,
})
self.assertEqual(self.so1_line_deliver_no_task.qty_delivered, timesheet1.unit_amount + timesheet2.unit_amount)
invoice1.write({'state': 'cancel', 'payment_state': 'invoicing_legacy'})
self.assertEqual(self.so1_line_deliver_no_task.qty_invoiced, timesheet1.unit_amount)
invoice2 = self.sale_order_1._create_invoices()[0]
invoice2.action_post()
self.assertEqual(self.so1_line_deliver_no_task.qty_invoiced, timesheet1.unit_amount + timesheet2.unit_amount)
self.assertEqual(timesheet1.timesheet_invoice_id, invoice1)
self.assertEqual(timesheet2.timesheet_invoice_id, invoice2)

0 comments on commit 19d4af0

Please sign in to comment.