| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
|
| 4 |
from odoo import api, models |
| 5 |
|
| 6 |
|
| 7 |
class IrHttp(models.AbstractModel): |
| 8 |
_inherit = 'ir.http' |
| 9 |
|
| 10 |
def session_info(self): |
| 11 |
""" The widget 'timesheet_uom' needs to know which UoM conversion factor and which javascript |
| 12 |
widget to apply, depending on the current company. |
| 13 |
""" |
| 14 |
result = super().session_info() |
| 15 |
if self.env.user._is_internal(): |
| 16 |
company_ids = self.env.user.company_ids |
| 17 |
|
| 18 |
for company in company_ids: |
| 19 |
result["user_companies"]["allowed_companies"][company.id].update({ |
| 20 |
"timesheet_uom_id": company.timesheet_encode_uom_id.id, |
| 21 |
"timesheet_uom_factor": company.project_time_mode_id._compute_quantity( |
| 22 |
1.0, |
| 23 |
company.timesheet_encode_uom_id, |
| 24 |
round=False |
| 25 |
), |
| 26 |
}) |
| 27 |
result["uom_ids"] = self.get_timesheet_uoms() |
| 28 |
return result |
| 29 |
|
| 30 |
@api.model |
| 31 |
def get_timesheet_uoms(self): |
| 32 |
company_ids = self.env.user.company_ids |
| 33 |
uom_ids = company_ids.mapped('timesheet_encode_uom_id') | \ |
| 34 |
company_ids.mapped('project_time_mode_id') |
| 35 |
return { |
| 36 |
uom.id: |
| 37 |
{ |
| 38 |
'id': uom.id, |
| 39 |
'name': uom.name, |
| 40 |
'rounding': uom.rounding, |
| 41 |
'timesheet_widget': uom.timesheet_widget, |
| 42 |
} for uom in uom_ids |
| 43 |
} |