[FIX] {hr,sale}_timesheet: prevent default project_id on non timesheets
Prior to this commit and since odoo/odoo#94144, a default project_id is provided event for non timesheets. This commit fixes this issue by setting a context key in the `account.analytic.line` actions that are related to timesheets and by setting the default project_id only when this key is set to `True`. This commit also removes `encoding_uom_id` from 'default_get' as it is any computed as the field is compute (not stored). closes odoo/odoo#104901 X-original-commit: 5768a5f25b62ce9f07212adbf6584e0b874c64ea Related: odoo/enterprise#33581 Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
committed by
Xavier BOL (xbo)
parent
8873581323
commit
623ecff069
@@ -26,11 +26,9 @@ class AccountAnalyticLine(models.Model):
|
||||
@api.model
|
||||
def default_get(self, field_list):
|
||||
result = super(AccountAnalyticLine, self).default_get(field_list)
|
||||
if 'encoding_uom_id' in field_list:
|
||||
result['encoding_uom_id'] = self.env.company.timesheet_encode_uom_id.id
|
||||
if not self.env.context.get('default_employee_id') and 'employee_id' in field_list and result.get('user_id'):
|
||||
result['employee_id'] = self.env['hr.employee'].search([('user_id', '=', result['user_id']), ('company_id', '=', result.get('company_id', self.env.company.id))], limit=1).id
|
||||
if not self._context.get('default_project_id') and 'project_id' in field_list:
|
||||
if not self._context.get('default_project_id') and self._context.get('is_timesheet'):
|
||||
employee_id = result.get('employee_id', self.env.context.get('default_employee_id', False))
|
||||
favorite_project_id = self._get_favorite_project_id(employee_id)
|
||||
if favorite_project_id:
|
||||
|
||||
@@ -274,6 +274,7 @@
|
||||
<field name="domain">[('project_id', '!=', False), ('user_id', '=', uid)]</field>
|
||||
<field name="context">{
|
||||
"search_default_week":1,
|
||||
"is_timesheet": 1,
|
||||
}</field>
|
||||
<field name="search_view_id" ref="hr_timesheet_line_my_timesheet_search"/>
|
||||
<field name="help" type="html">
|
||||
@@ -336,6 +337,9 @@
|
||||
<record id="timesheet_action_task" model="ir.actions.act_window">
|
||||
<field name="name">Task's Timesheets</field>
|
||||
<field name="res_model">account.analytic.line</field>
|
||||
<field name="context">{
|
||||
'is_timesheet': 1,
|
||||
}</field>
|
||||
<field name="domain">[('task_id', 'in', active_ids)]</field>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="view_id" ref="timesheet_view_tree_user"/>
|
||||
@@ -344,6 +348,9 @@
|
||||
<record id="timesheet_action_project" model="ir.actions.act_window">
|
||||
<field name="name">Project's Timesheets</field>
|
||||
<field name="res_model">account.analytic.line</field>
|
||||
<field name="context">{
|
||||
'is_timesheet': 1,
|
||||
}</field>
|
||||
<field name="domain">[('project_id', 'in', active_ids)]</field>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="view_id" ref="timesheet_view_tree_user"/>
|
||||
@@ -357,6 +364,7 @@
|
||||
<field name="domain">[('project_id', '!=', False)]</field>
|
||||
<field name="context">{
|
||||
'search_default_week':1,
|
||||
'is_timesheet': 1,
|
||||
}</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
<field name="context">{
|
||||
'search_default_month':1,
|
||||
'search_default_employee_id': [active_id],
|
||||
'default_employee_id': active_id
|
||||
'default_employee_id': active_id,
|
||||
"is_timesheet": 1,
|
||||
}</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
<field name="view_mode">tree,kanban,pivot,graph,form</field>
|
||||
<field name="view_id" ref="timesheet_view_tree_user"/>
|
||||
<field name="domain">[('project_id', '=', active_id)]</field>
|
||||
<field name="context">{"default_project_id": active_id}</field>
|
||||
<field name="context">{
|
||||
"default_project_id": active_id,
|
||||
"is_timesheet": 1,
|
||||
}</field>
|
||||
<field name="search_view_id" ref="hr_timesheet_line_search"/>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
|
||||
@@ -6,7 +6,12 @@
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">account.analytic.line</field>
|
||||
<field name="view_mode">tree,form,graph,pivot,kanban</field>
|
||||
<field name="context">{'create': False, 'edit': False, 'delete': False}</field>
|
||||
<field name="context">{
|
||||
'create': False,
|
||||
'edit': False,
|
||||
'delete': False,
|
||||
"is_timesheet": 1,
|
||||
}</field>
|
||||
<field name="domain">[('timesheet_invoice_id', '=', active_id)]</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
|
||||
@@ -95,6 +95,9 @@
|
||||
<field name="name">Timesheets</field>
|
||||
<field name="res_model">account.analytic.line</field>
|
||||
<field name="search_view_id" ref="hr_timesheet.hr_timesheet_line_search"/>
|
||||
<field name="context">{
|
||||
"is_timesheet": 1,
|
||||
}</field>
|
||||
<field name="domain">[('project_id', '!=', False)]</field>
|
||||
</record>
|
||||
|
||||
@@ -123,6 +126,7 @@
|
||||
'search_default_week': 1,
|
||||
'default_so_line': active_id,
|
||||
'default_is_so_line_edited': True,
|
||||
"is_timesheet": 1,
|
||||
}</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
@@ -177,6 +181,9 @@
|
||||
<field name="res_model">account.analytic.line</field>
|
||||
<field name="view_mode">pivot,tree,form</field>
|
||||
<field name="domain">[('project_id', '!=', False)]</field>
|
||||
<field name="context">{
|
||||
"is_timesheet": 1,
|
||||
}</field>
|
||||
<field name="search_view_id" ref="hr_timesheet.hr_timesheet_line_search"/>
|
||||
</record>
|
||||
|
||||
@@ -185,6 +192,9 @@
|
||||
<field name="res_model">account.analytic.line</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="domain">[('project_id', '!=', False)]</field>
|
||||
<field name="context">{
|
||||
"is_timesheet": 1,
|
||||
}</field>
|
||||
<field name="search_view_id" ref="hr_timesheet.hr_timesheet_line_search"/>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user