51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
# The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
from trytond.model import fields
|
|
from trytond.pool import Pool
|
|
from trytond.model import ModelSQL, ModelView, Model
|
|
from trytond.pyson import Equal, Eval
|
|
from trytond.transaction import Transaction
|
|
|
|
__all__ = ['ProductiveProcess', 'WithinProductiveProcess',
|
|
'is_in_productive_process', 'PYSON_NULL_PROCESS']
|
|
|
|
|
|
PYSON_NULL_PROCESS = Equal(Eval('productive_process', 0), 0)
|
|
|
|
|
|
def is_in_productive_process(within, module, productive_process_model_data_id):
|
|
within_productive_process = getattr(within, 'productive_process', None)
|
|
if within_productive_process:
|
|
model_data_pool = Pool().get('ir.model.data')
|
|
productive_process_id = model_data_pool.get_id(module,
|
|
productive_process_model_data_id)
|
|
return productive_process_id == within_productive_process.id
|
|
return True
|
|
|
|
|
|
class ProductiveProcess(ModelSQL, ModelView):
|
|
"""Productive process"""
|
|
__name__ = 'productive.process'
|
|
|
|
name = fields.Char('Name', translate=True,
|
|
readonly=False, select=True)
|
|
|
|
|
|
class WithinProductiveProcess(Model):
|
|
|
|
productive_process = fields.Many2One('productive.process',
|
|
'Productive process', ondelete='RESTRICT',
|
|
readonly=False, required=True, select=True)
|
|
|
|
@staticmethod
|
|
def default_productive_process():
|
|
pool = Pool()
|
|
Process = pool.get('productive.process')
|
|
|
|
process_id = Transaction().context.get('productive_process')
|
|
if not process_id:
|
|
processes = Process.search([])
|
|
if len(processes) == 1:
|
|
process_id = processes[0].id
|
|
return process_id
|