Reformat and refactor.

This commit refs #2576
This commit is contained in:
Nicolás López 2017-06-09 13:00:39 +02:00
parent a388c25cc4
commit edb468ac25
3 changed files with 30 additions and 30 deletions

View File

@ -1,8 +1,10 @@
# The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool
from .productive_process import (ProductiveProcess, is_in_productive_process,
WithinProductiveProcess, PYSON_NULL_PROCESS)
from .productive_process import (ProductiveProcess,
ProductiveProcDocMixin, PYSON_NULL_PROCESS)
__all__ = ['ProductiveProcDocMixin', 'PYSON_NULL_PROCESS']
def register():

View File

@ -2,49 +2,38 @@
# 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.model import ModelSQL, ModelView
from trytond.pyson import Equal, Eval
from trytond.transaction import Transaction
__all__ = ['ProductiveProcess', 'WithinProductiveProcess',
'is_in_productive_process', 'PYSON_NULL_PROCESS']
__all__ = ['ProductiveProcess', 'ProductiveProcDocMixin', 'PYSON_NULL_PROCESS']
PYSON_NULL_PROCESS = Equal(Eval('productive_process', None), None)
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)
name = fields.Char('Name', translate=True, select=True)
class WithinProductiveProcess(Model):
class ProductiveProcDocMixin(object):
productive_process = fields.Many2One('productive.process',
'Productive process', ondelete='RESTRICT',
readonly=False, required=True, select=True)
'Productive process', ondelete='RESTRICT', required=True, select=True)
@staticmethod
def default_productive_process():
transaction = Transaction()
process = transaction.context.get('productive_process', None)
if process:
return 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
processes = Process.search([])
if len(processes) == 1:
return processes[0].id
return None

View File

@ -1,8 +1,11 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
import unittest
import trytond.tests.test_tryton
import doctest
from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import suite as test_suite
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
from trytond.tests.test_tryton import doctest_checker
class ProductiveProcessTestCase(ModuleTestCase):
@ -11,6 +14,12 @@ class ProductiveProcessTestCase(ModuleTestCase):
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(ProductiveProcessTestCase))
suite = test_suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
ProductiveProcessTestCase))
suite.addTests(doctest.DocFileSuite(
'scenario_productive_process.rst',
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite