[FIX] hr_timesheet: hide WIP report in timesheet views

Before this commit, when `mrp_account` module is installed, a new report
to print is added in all views of `account.analytic.line`. the problem
is since timesheet model is `account.analytic.line` then that report
is available in the timesheets views and when the user chooses that
report to print in a timesheet view then he will get a traceback
because that report does not for the timesheet record.

This commit hides `WIP` report in the print menu when the view displayed
timesheets records only. That is all the views in the timesheets app.

task-3465424

closes odoo/odoo#145597

X-original-commit: https://github.com/odoo/odoo/pull/132005/commits/b293a6c9a5b2f7fb3a0c7624eccf5406c71521f1
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
Chauhan Aadil Riyazmohamed
2023-12-12 23:08:49 +00:00
committed by kcv-odoo
parent 882caa60a3
commit 5f22eed49c
@@ -249,6 +249,24 @@ class AccountAnalyticLine(models.Model):
key = super()._get_view_cache_key(view_id, view_type, **options)
return key + (self.env.company.timesheet_encode_uom_id,)
@api.model
def get_views(self, views, options=None):
res = super().get_views(views, options)
if options and options.get('toolbar'):
wip_report_id = None
def get_wip_report_id():
return self.env['ir.model.data']._xmlid_to_res_id("mrp_account.wip_report", raise_if_not_found=False)
for view_data in res['views'].values():
print_data_list = view_data.get('toolbar', {}).get('print')
if print_data_list:
if wip_report_id is None and re.search(r'widget="timesheet_uom(\w)*"', view_data['arch']):
wip_report_id = get_wip_report_id()
if wip_report_id:
view_data['toolbar']['print'] = [print_data for print_data in print_data_list if print_data['id'] != wip_report_id]
return res
@api.model
def _get_view(self, view_id=None, view_type='form', **options):
""" Set the correct label for `unit_amount`, depending on company UoM """