Files
odoo_source/addons/project/models/res_company.py
T
jem-odoo 2d32ff4bb8 [IMP] uom: measurement type on category
In order to restrict some uom field to some uom category, it is required to
add a measurement type on uom.category. Also, this will lessen the use of
master data.

Some technical justifications:
- measure_type is not required, to allow people creating their own
uom.category. Those ones will not interfere with addons business.
- measure_type is unique: we restrict to only one category containing
time, weight, ... in order to avoid mismatch category during conversion.
(2 different weight categories can not be converted).
- measure_type on uom.uom is stored: to allow search and domain on
field, we need to store it. Usually, UoM are not updated every day,
and the number of uom in a database is not that important.

To illustrate this mecanism, a domain is added on
'project_time_mode_id', in project module. This field
is use as timesheet default uom, and we obviously want to
restrict it to time category (timesheeting in liter does
not make sense ...)

Task #1820076
2018-04-09 10:13:06 +02:00

24 lines
996 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class ResCompany(models.Model):
_inherit = 'res.company'
@api.model
def _default_project_time_mode_id(self):
uom = self.env.ref('uom.product_uom_hour', raise_if_not_found=False)
if not uom:
uom = self.env['uom.uom'].search([('measure_type', '=', 'time'), ('uom_type', '=', 'reference')], limit=1)
if not uom:
uom = self.env['uom.uom'].search([('measure_type', '=', 'time')], limit=1)
return uom
project_time_mode_id = fields.Many2one('uom.uom', string='Project Time Unit',
default=_default_project_time_mode_id, domain=[('measure_type', '=', 'time')],
help="This will set the unit of measure used in projects and tasks.\n"
"If you use the timesheet linked to projects, don't "
"forget to setup the right unit of measure in your employees.")