Ejemplo n.º 1
0
def register_horse_template_online(description, fn, ref):
    documents_service = JsonCallWrapper( DocumentsService(), JsonCallWrapper.HTTP_MODE)

    doc_id = documents_service.reference_to_document_id(ref)
    if not doc_id:
        doc_id = upload_template(os.path.join(resource_dir, fn))
        documents_service.update_template_description(doc_id,description,ref)
    else:
        mainlog.debug("I didn't add {} with reference {} because it's already there".format(fn,ref))
Ejemplo n.º 2
0
    def test_create_order_and_report_on_operation(self):

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()
        # add some more operation
        self._encode_not_imputable_operation()

        widget._set_state(OrderStatusType.order_ready_for_production)
        self.prepare_to_click_dialog("confirm_estimate_sent")

        # Save
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)

        mainlog.debug(order)
        mainlog.debug(order.parts[0])
        mainlog.debug(order.parts[0].production_file[0])

        operation = order.parts[0].production_file[0].operations[0]
        employee_id = dao.employee_dao.any().employee_id
        d1 = datetime(2013, 0o5, 26, 8)

        self.server = JsonCallWrapper(ClockService(),
                                      JsonCallWrapper.IN_PROCESS_MODE)
        self.server.record_pointage_on_operation(
            operation.operation_id, employee_id, d1, "nostromo",
            TaskActionReportType.start_task, None)

        d2 = datetime(2013, 5, 26, 10, 54)
        self.server.record_pointage_on_operation(
            operation.operation_id, employee_id, d2, "nostromo",
            TaskActionReportType.stop_task, None)

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        operation = order.parts[0].production_file[0].operations[0]

        widget.edit_new_order(
            self.customer.customer_id)  # Force the order reset below
        app.processEvents()
        widget.reset_order(order.order_id, overwrite=True)
        widget.refresh_action()

        m = widget.controller_operation.model
        self.assertEqual(2.9, m.data(m.index(0, 4), Qt.UserRole))

        m = widget.controller_part.model
        self.assertEqual(80, m.data(m.index(0, 4), Qt.UserRole))
        self.assertEqual(111, m.data(m.index(0, 6), Qt.UserRole))
Ejemplo n.º 3
0
    def test_create_order_and_report_on_order(self):

        # python test_integration.py TestEditOrderParts.test_create_order_and_report_on_order

        app = self.app
        widget = self.widget
        mw = self.mw
        clock_server = ClockServer(dao)

        self._make_basic_preorder()
        app.processEvents()

        widget._set_state(OrderStatusType.order_ready_for_production)
        self.prepare_to_click_dialog("confirm_estimate_sent")

        # Save
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()
        app.processEvents()
        app.processEvents()

        self.assertTrue(widget._current_order.order_id > 0)

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        bc = BarCodeIdentifier.code_for(order, self.opdef_order)

        employee_id = dao.employee_dao.any().employee_id
        d1 = datetime(2013, 0o5, 26, 8)
        # clock_server.recordPointage(bc,employee_id, datetime.strftime(d1, "%Y%m%dT%H:%M:%S"),"Nostromo")
        d2 = datetime(2013, 0o5, 26, 10, 54)
        # clock_server.recordPointage(bc,employee_id, datetime.strftime(d2, "%Y%m%dT%H:%M:%S"),"Nostromo")

        self.server = JsonCallWrapper(ClockService(),
                                      JsonCallWrapper.IN_PROCESS_MODE)
        self.server.record_pointage_on_order(
            order.order_id, self.opdef_order.operation_definition_id,
            employee_id, d1, "nostromo", TaskActionReportType.start_task, None)

        self.server.record_pointage_on_order(
            order.order_id, self.opdef_order.operation_definition_id,
            employee_id, d2, "nostromo", TaskActionReportType.stop_task, None)

        order = dao.order_dao.find_by_id(widget._current_order.order_id)

        widget.edit_new_order(
            self.customer.customer_id)  # Force the order reset below
        app.processEvents()
        widget.reset_order(order.order_id, overwrite=True)
        app.processEvents()
Ejemplo n.º 4
0
def base_init():
    global services, json_rpc_dispatcher

    init_db_session(configuration.get('Database', 'url'), metadata, False
                    or configuration.echo_query)
    dao.set_session(session())

    json_rpc_dispatcher = HorseJsonRpc()

    make_server_json_server_dispatcher(
        json_rpc_dispatcher,
        JsonCallWrapper(ClockService(), JsonCallWrapper.CHERRYPY_MODE))

    make_server_json_server_dispatcher(
        json_rpc_dispatcher,
        JsonCallWrapper(DocumentsService(), JsonCallWrapper.CHERRYPY_MODE))

    make_server_json_server_dispatcher(
        json_rpc_dispatcher,
        JsonCallWrapper(IndicatorsService(), JsonCallWrapper.CHERRYPY_MODE))

    services = Services()
    services.register_for_server(session, Base)
Ejemplo n.º 5
0
__author__ = 'stc'

from koi.Configurator import configuration
from koi.server.json_decorator import JsonCallWrapper
from koi.charts.indicators_service import IndicatorsService
from koi.doc_manager.documents_service import DocumentsService
from koi.datalayer.filters_dao import FilterService

if False:
    remote_indicators_service = JsonCallWrapper(IndicatorsService(), JsonCallWrapper.HTTP_MODE)
    remote_documents_service = JsonCallWrapper(DocumentsService(), JsonCallWrapper.HTTP_MODE)
    filters_service = JsonCallWrapper( FilterService(), JsonCallWrapper.HTTP_MODE)
else:
    remote_indicators_service = JsonCallWrapper(IndicatorsService(), JsonCallWrapper.IN_PROCESS_MODE)
    # remote_indicators_service = IndicatorsService()
    # remote_documents_service = DocumentsService()
    remote_documents_service = JsonCallWrapper(DocumentsService(), JsonCallWrapper.IN_PROCESS_MODE)
    filters_service = JsonCallWrapper( FilterService(), JsonCallWrapper.IN_PROCESS_MODE)

# The services to actually import on import *
__all__ = ['remote_documents_service', 'remote_indicators_service', 'filters_service']

def request_service( service_name):
    if service_name == 'remote_documents_service':
        return remote_documents_service

Ejemplo n.º 6
0
def print_order_confirmation_report(order_id):

    documents_service = JsonCallWrapper(DocumentsService(),
                                        JsonCallWrapper.HTTP_MODE)
    doc_id = documents_service.reference_to_document_id(HORSE_REFERENCE)

    if not doc_id:
        raise Exception(
            _("The template document with reference <code>{}</code> was not found. Check your templates."
              ).format(HORSE_REFERENCE))

    tpl_path = download_document(doc_id)

    order = dao.order_dao.find_by_id(order_id)

    from decimal import localcontext, Decimal

    with localcontext() as ctx:  # decimal context
        ctx.prec = 10 + 2
        qtize = Decimal(10)**-2

        grand_total = Decimal(0)
        from koi.reporting.utils import moneyfmt

        parts_table = []
        for part in order.parts:

            qty = Decimal(part.qty).quantize(qtize)
            sell_price = Decimal(part.sell_price).quantize(qtize)
            total_price = (qty * sell_price).quantize(qtize)

            grand_total += total_price

            parts_table.append({
                'ref': part.human_identifier,
                'description': part.description or "",
                'quantity': part.qty,
                'unit_price': moneyfmt(sell_price),
                'total_price': moneyfmt(total_price)
            })

    context = {
        'customer_name': order.customer.fullname or "",
        'customer_address1': order.customer.address1 or "",
        'customer_address2': order.customer.address2 or "",
        'customer_country': order.customer.country or "",
        'order_number': order.accounting_label or order.preorder_label,
        'order_reference_customer': order.customer_order_name or "",
        'total_parts': moneyfmt(grand_total),
        'items': parts_table,
    }

    tpl = DocxTemplate(tpl_path)
    tpl.render(context)
    doc_path = make_home_file("order_confirmation_report_{}.docx".format(
        order.accounting_label or order.preorder_label))

    tpl.save(doc_path)

    os.unlink(tpl_path)

    open_a_file_on_os(doc_path)
Ejemplo n.º 7
0
    def setUpClass(cls):

        # In process so that the server is bypassed (or else
        # I have to run a server in parallel)
        cls.remote_documents_service = JsonCallWrapper(documents_service,JsonCallWrapper.DIRECT_MODE)
        cls.remote_indicators_service = IndicatorsService()

        configuration.set('Programs','pdf_viewer',None)

        mainlog.debug("TestBase.setUpClass : init database")


        from koi.dao import dao, DAO
        init_test_database()

        cls.open_locks_on_startup = cls._count_open_locks()

        mainlog.debug("TestBase.setUpClass")
        cls.dao = DAO()
        cls.dao.set_session(session)
        dao.set_session(session)

        cls._operation_definition_dao = cls.dao.operation_definition_dao
        cls.dao_employee = cls.dao.employee_dao
        cls.tar_dao = cls.dao.task_action_report_dao
        cls.task_dao = cls.dao.task_dao
        cls.timetrack_dao = cls.dao.timetrack_dao
        cls.delivery_slip_dao = cls.dao.delivery_slip_part_dao
        cls.order_dao = cls.dao.order_dao
        cls.day_time_synthesis_dao = cls.dao.day_time_synthesis_dao
        cls.month_time_synthesis_dao = cls.dao.month_time_synthesis_dao
        cls._production_file_dao = cls.dao.production_file_dao
        cls.employee_dao = cls.dao.employee_dao
        cls._order_dao = cls.dao.order_dao
        cls._order_part_dao = cls.dao.order_part_dao
        cls._operation_dao = cls.dao.operation_dao
        cls._customer_dao = cls.dao.customer_dao

        cls.customer = cls._customer_dao.make(u"Si"+ chr(233) + u"mens")
        cls.customer.address1 = u"Square Niklaus Wirth"+ chr(233)
        cls.customer.country = u"Pakistan"+ chr(233)
        cls.customer.phone = u"+494 0412 32 32 6654"
        cls.customer.email = u"*****@*****.**"

        cls._customer_dao.save(cls.customer)

        session().flush()

        cls.customer_id = cls.customer.customer_id

        cls.opdef = cls._operation_definition_dao.make()
        cls.opdef.short_id = "Unbi"
        cls.opdef.description = u"Unbi" + chr(233)
        cls.opdef.imputable = True
        cls.opdef.on_order = False
        cls.opdef.on_operation = False

        period = OperationDefinitionPeriod()
        period.start_date, period.end_date = date(2010,1,1), None
        cls.opdef.periods.append(period)

        cls._operation_definition_dao.save(cls.opdef)

        cls.nonbillable_op = cls.opdef
        cls.nonbillable_op_id = cls.opdef.operation_definition_id


        cls.opdef2 = cls._operation_definition_dao.make()
        cls.opdef2.short_id = "Unbi2"
        cls.opdef2.description = u"Unbi2"+ chr(233)
        cls.opdef2.imputable = True
        cls.opdef2.on_order = False
        cls.opdef2.on_operation = False

        period = OperationDefinitionPeriod()
        period.start_date, period.end_date = date(2010,1,1), None
        cls.opdef2.periods.append(period)

        cls._operation_definition_dao.save(cls.opdef2)


        cls.not_imputable_opdef_on_order = cls._operation_definition_dao.make()
        cls.not_imputable_opdef_on_order.short_id = "OnOrder"
        cls.not_imputable_opdef_on_order.description = u"OnOrder (not imputable)" + chr(233)
        cls.not_imputable_opdef_on_order.imputable = False
        cls.not_imputable_opdef_on_order.on_order = True
        cls.not_imputable_opdef_on_order.on_operation = False

        period = OperationDefinitionPeriod()
        period.start_date, period.end_date = date(2010,1,1), None
        cls.not_imputable_opdef_on_order.periods.append(period)

        cls._operation_definition_dao.save(cls.not_imputable_opdef_on_order)

        cls.not_imputable_opdef_on_operation = cls._operation_definition_dao.make()
        cls.not_imputable_opdef_on_operation.short_id = "MA"
        cls.not_imputable_opdef_on_operation.description = u"OnOperation (not imputable)" + chr(233)
        cls.not_imputable_opdef_on_operation.imputable = False
        cls.not_imputable_opdef_on_operation.on_order = False
        cls.not_imputable_opdef_on_operation.on_operation = True
        period = OperationDefinitionPeriod()
        period.start_date = date(2010,1,1)
        period.cost = 63.3 # BUG Cost makes no sense for non imputable task or does it ?
        cls.not_imputable_opdef_on_operation.periods.append(period)

        cls._operation_definition_dao.save(cls.not_imputable_opdef_on_operation)

        session().flush()

        # A regular operation

        mainlog.debug("Creating a regular operation definition")
        cls.opdef_op = cls._operation_definition_dao.make()
        cls.opdef_op.short_id = "TO"
        cls.opdef_op.description = u"Tournag" + chr(233)
        cls.opdef_op.imputable = True
        cls.opdef_op.on_order = False
        cls.opdef_op.on_operation = True

        period = OperationDefinitionPeriod()
        period.start_date = date(2010,1,1)
        period.cost = 63.3

        cls.opdef_op.periods.append(period)
        cls._operation_definition_dao.save( cls.opdef_op)

        # cls.dao.operation_definition_dao.add_period(period, cls.opdef_op)
        session().flush()
        mainlog.debug("Creating a regular operation definition => id is {}".format(cls.opdef_op.operation_definition_id))

        cls.opdef_order = cls._operation_definition_dao.make()
        cls.opdef_order.short_id = "ZO"
        cls.opdef_order.description = u"Analyse order " + chr(233)
        cls.opdef_order.imputable = True
        cls.opdef_order.on_order = True
        cls.opdef_order.on_operation = False

        period = OperationDefinitionPeriod()
        period.start_date, period.end_date = date(2010,1,1), None
        cls.opdef_order.periods.append(period)

        cls._operation_definition_dao.save(cls.opdef_order)

        cls.employee = cls.dao_employee.create(u"Don d. Knuth"+ chr(233))
        cls.employee.login = "******"

        h = hashlib.md5()
        h.update('kk'.encode('utf-8'))

        cls.employee.password = h.hexdigest()
        cls.employee_id = cls.employee.employee_id

        user_session.open(cls.employee)

        cls.reporter = cls.dao_employee.create(u"George Orwell")
        cls.reporter.login = "******"
        cls.reporter.password = h.hexdigest()
        cls.reporter_id = cls.reporter.employee_id

        # It's already in the basic database
        # fq = FilterQuery()
        # fq.family = "order_parts_overview"
        # fq.query = "CreationDate > 1/1/2016"
        # fq.owner_id = cls.employee_id
        # fq.name = "production"
        # f = cls.dao.filters_dao.save(fq)

        session().commit()

        mainlog.debug("***************************************************** CLASS INIT completed")
        cls.timer = QTimer()
        cls.timer_connected = False
        cls.dialog_to_click = []
Ejemplo n.º 8
0
            "base_url") + "/remove_file?file_id={}".format(doc_id)
        urlopener.open(url)


def download_document(doc_id, progress_tracker=None, destination=None):
    """ Download document to a given or temporary file. The temporary file
    name reflects the original name and extension.

    :param progress_tracker: a progress tacker
    :param destination: Where to store the file (full path, with filename).
    :return: the full path to the downloaded file. You'll have to delete that
    file if you need to.
    """

    url = configuration.get(
        "DownloadSite",
        "base_url") + "/download_file?file_id={}".format(doc_id)
    return download_file(url, progress_tracker, destination)


from koi.doc_manager.documents_service import documents_service
from koi.server.json_decorator import JsonCallWrapper

documents_service = JsonCallWrapper(documents_service,
                                    JsonCallWrapper.DIRECT_MODE)


def update_name_and_description(document_id, name, description):
    documents_service.update_name_and_description(document_id, name,
                                                  description)
Ejemplo n.º 9
0
class TestEditOrderParts(TestBase):
    @classmethod
    def setUpClass(cls):
        super(TestEditOrderParts, cls).setUpClass()
        app = QApplication.instance()
        if app is None:
            app = QApplication(sys.argv)
        # Fix issues with combo box that gets cleared too fast
        app.setEffectEnabled(Qt.UI_AnimateCombo, False)
        cls.app = app

        operation_definition_cache.refresh()
        cls.mw = QMainWindow()
        cls.mw.setMinimumSize(1024, 768)
        cls.widget = EditOrderPartsWidget(None, None, True,
                                          cls.remote_documents_service)
        cls.order_overview_widget = OrderOverviewWidget(None, None, None, True)
        cls.mw.setCentralWidget(cls.widget)
        cls.mw.show()
        QTest.qWaitForWindowShown(cls.mw)

        cls.app.processEvents()

    @classmethod
    def tearDownClass(cls):
        # cls.mw.setCentralWidget(None)
        cls.mw.close()
        cls.widget.close()
        cls.app.processEvents()
        #cls.widget.deleteLater()
        #cls.mw.deleteLater()
        cls.app.processEvents()
        cls.app.closeAllWindows()
        # cls.app.exit()
        cls.app = None

    def setUp(self):
        super(TestEditOrderParts, self).setUp()
        operation_definition_cache.refresh()

    def _encode_imputable_operation(self,
                                    description="Description op 1, TOurnage",
                                    pause=False):
        widget = self.widget
        app = self.app

        widget.controller_operation.view.setFocus(Qt.OtherFocusReason)

        mainlog.debug("*** Activating operation selection")

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Down)  # modifier, delay
        app.processEvents()

        # Operation defintion
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_T)  # modifier, delay
        app.processEvents()
        ed = app.focusWidget()
        for i in range(10000):
            app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_O)  # modifier, delay
        app.processEvents()

        if pause:
            app.exec_()

        mainlog.debug("*** Selecting operation selection")

        for i in range(10000):
            app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()
        for i in range(10000):
            app.processEvents()

        mainlog.debug("*** Entering description")
        mainlog.debug(app.focusWidget())
        # Operation's description
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_8)  # modifier, delay
        app.processEvents()
        QTest.keyClicks(
            app.focusWidget(),
            description)  # modifier, delay        print(app.focusWidget())
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Uacute)  # modifier, delay
        app.processEvents()

        mainlog.debug("*** hitting enter")
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()
        mainlog.debug(app.focusWidget())

        mainlog.debug("*** entering number of hours")

        # Value/price (skipped because TO is not a fixed price)

        # Number of hours
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_8)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()

        # Leave auto edit to give focus back to parent
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        app.processEvents()
        app.processEvents()

    def _encode_not_imputable_operation(self):
        widget = self.widget
        app = self.app

        widget.controller_operation.view.setFocus(Qt.OtherFocusReason)
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Down)  # modifier, delay

        # Operation defintion
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_M)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_A)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()

        # Operation's description
        QTest.keyClicks(app.focusWidget(),
                        "Not imputable task")  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Uacute)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()

        # Value/price

        QTest.keyClicks(app.focusWidget(), "123.66")  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()

        # Number of hours (skipped because TO is not a fixed price)

        # Leave auto edit to give focus back to parent
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        app.processEvents()
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        app.processEvents()
        app.processEvents()

    def _make_basic_preorder(self):
        app = self.app
        widget = self.widget
        mw = self.mw

        widget.edit_new_order(self.customer.customer_id)

        widget.customer_order_name.setText(u"AKZO123" + chr(233))

        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_Down)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_1)  # modifier, delay
        app.processEvents()
        QTest.keyClicks(app.focusWidget(), "Order part one")  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Uacute)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_1)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_0)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()
        app.processEvents()

        # deadline
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Tab)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_1)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_1)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_1)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        self._encode_imputable_operation()

        # Leave auto edit to give focus back to parent
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        app.processEvents()
        app.processEvents()
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        app.processEvents()
        app.processEvents()

    def test_create_order_and_report_on_order(self):

        # python test_integration.py TestEditOrderParts.test_create_order_and_report_on_order

        app = self.app
        widget = self.widget
        mw = self.mw
        clock_server = ClockServer(dao)

        self._make_basic_preorder()
        app.processEvents()

        widget._set_state(OrderStatusType.order_ready_for_production)
        self.prepare_to_click_dialog("confirm_estimate_sent")

        # Save
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()
        app.processEvents()
        app.processEvents()

        self.assertTrue(widget._current_order.order_id > 0)

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        bc = BarCodeIdentifier.code_for(order, self.opdef_order)

        employee_id = dao.employee_dao.any().employee_id
        d1 = datetime(2013, 0o5, 26, 8)
        # clock_server.recordPointage(bc,employee_id, datetime.strftime(d1, "%Y%m%dT%H:%M:%S"),"Nostromo")
        d2 = datetime(2013, 0o5, 26, 10, 54)
        # clock_server.recordPointage(bc,employee_id, datetime.strftime(d2, "%Y%m%dT%H:%M:%S"),"Nostromo")

        self.server = JsonCallWrapper(ClockService(),
                                      JsonCallWrapper.IN_PROCESS_MODE)
        self.server.record_pointage_on_order(
            order.order_id, self.opdef_order.operation_definition_id,
            employee_id, d1, "nostromo", TaskActionReportType.start_task, None)

        self.server.record_pointage_on_order(
            order.order_id, self.opdef_order.operation_definition_id,
            employee_id, d2, "nostromo", TaskActionReportType.stop_task, None)

        order = dao.order_dao.find_by_id(widget._current_order.order_id)

        widget.edit_new_order(
            self.customer.customer_id)  # Force the order reset below
        app.processEvents()
        widget.reset_order(order.order_id, overwrite=True)
        app.processEvents()

        # app.exec_()

        # m = widget.indirects
        # self.assertEqual(2.9, m.data( m.index(0,2), Qt.DisplayRole))

    def test_new_order_is_a_preorder(self):  # passes
        app = self.app
        widget = self.widget
        mw = self.mw

        mainlog.debug(str(self.customer))

        widget.edit_new_order(self.customer.customer_id)

        #app.exec_()
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)

        assert order.state == OrderStatusType.preorder_definition
        assert order.preorder_label is not None
        assert order.accounting_label == None

    def test_new_order_is_not_a_preorder(self):  # passes
        app = self.app
        widget = self.widget
        mw = self.mw

        widget.edit_new_order(self.customer.customer_id)
        widget.order_state_label.set_value(
            OrderStatusType.order_ready_for_production)
        self.prepare_to_click_dialog("confirm_estimate")

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)

        assert order.state == OrderStatusType.order_ready_for_production
        assert order.preorder_label is None
        assert order.accounting_label is not None

    def test_create_order_and_report_on_operation(self):

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()
        # add some more operation
        self._encode_not_imputable_operation()

        widget._set_state(OrderStatusType.order_ready_for_production)
        self.prepare_to_click_dialog("confirm_estimate_sent")

        # Save
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)

        mainlog.debug(order)
        mainlog.debug(order.parts[0])
        mainlog.debug(order.parts[0].production_file[0])

        operation = order.parts[0].production_file[0].operations[0]
        employee_id = dao.employee_dao.any().employee_id
        d1 = datetime(2013, 0o5, 26, 8)

        self.server = JsonCallWrapper(ClockService(),
                                      JsonCallWrapper.IN_PROCESS_MODE)
        self.server.record_pointage_on_operation(
            operation.operation_id, employee_id, d1, "nostromo",
            TaskActionReportType.start_task, None)

        d2 = datetime(2013, 5, 26, 10, 54)
        self.server.record_pointage_on_operation(
            operation.operation_id, employee_id, d2, "nostromo",
            TaskActionReportType.stop_task, None)

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        operation = order.parts[0].production_file[0].operations[0]

        widget.edit_new_order(
            self.customer.customer_id)  # Force the order reset below
        app.processEvents()
        widget.reset_order(order.order_id, overwrite=True)
        widget.refresh_action()

        m = widget.controller_operation.model
        self.assertEqual(2.9, m.data(m.index(0, 4), Qt.UserRole))

        m = widget.controller_part.model
        self.assertEqual(80, m.data(m.index(0, 4), Qt.UserRole))
        self.assertEqual(111, m.data(m.index(0, 6), Qt.UserRole))

        # app.exec_()

    def _fill_order_part(self, description):
        app = self.app

        # Part's description
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_0)  # modifier, delay
        app.processEvents()
        QTest.keyClicks(app.focusWidget(), description)  # modifier, delay
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()

        # Part's quantity
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_9)  # modifier, delay
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()

        # deadline, skip it
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Tab)  # modifier, delay
        app.processEvents()

        # Unit price
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_1)  # modifier, delay
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        app.processEvents()

    def test_edit_order(self):

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        m = widget.controller_part.view.model()
        widget.controller_part.view.setCurrentIndex(m.index(0, 0))

        widget.controller_part.view.setFocus(Qt.OtherFocusReason)
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_Up)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_F5)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part zero")

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_F5,
                       Qt.ShiftModifier)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part two")

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        # app.exec_()

    def _save(self):
        app = self.app
        # Save
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

    def test_interrupted_order_update(self):
        # python test_integration.py TestEditOrderParts.test_interrupted_order_update

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        widget._set_state(OrderStatusType.order_ready_for_production)
        self.prepare_to_click_dialog("confirm_estimate_sent")

        self._save()

        self._encode_imputable_operation()
        self._encode_imputable_operation()
        self._encode_imputable_operation()

        # Interrupt the encoding
        session().commit()

        # Encode some more
        self._encode_imputable_operation()
        self._encode_imputable_operation()

        # And save again
        self._save()

        # app.exec_()

    def test_edit_order_change_state_and_add_part(self):
        # python test_integration.py TestEditOrderParts.test_edit_order_change_state_and_add_part

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        m = widget.controller_part.view.model()
        widget.controller_part.view.setCurrentIndex(m.index(0, 0))

        widget.controller_part.view.setFocus(Qt.OtherFocusReason)
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_Up)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_F5)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part zero")

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_F5,
                       Qt.ShiftModifier)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part two")

        widget.order_state_label.set_value(
            OrderStatusType.order_ready_for_production)
        # Because we're moving from a preorder to production directly,
        # skipping the "estimate sent" state.
        self.prepare_to_click_dialog("confirm_estimate_sent")
        # app.exec_()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        assert order.state == OrderStatusType.order_ready_for_production
        assert order.preorder_label is not None
        assert order.accounting_label is not None
        self.assertEqual(OrderPartStateType.ready_for_production,
                         order.parts[0].state)
        assert order.parts[1].state == OrderPartStateType.ready_for_production
        assert order.parts[2].state == OrderPartStateType.ready_for_production

    def test_edit_order_no_change_state_and_add_part(self):
        # python test_integration.py TestEditOrderParts.test_edit_order_change_state_and_add_part

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        m = widget.controller_part.view.model()
        widget.controller_part.view.setCurrentIndex(m.index(0, 0))

        widget.controller_part.view.setFocus(Qt.OtherFocusReason)
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_Up)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_F5)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part zero")

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_F5,
                       Qt.ShiftModifier)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part two")

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        assert order.state == OrderStatusType.preorder_definition
        assert order.preorder_label is not None
        assert order.accounting_label is None
        self.assertEqual(OrderPartStateType.preorder, order.parts[0].state)
        assert order.parts[1].state == OrderPartStateType.preorder
        assert order.parts[2].state == OrderPartStateType.preorder

    def test_edit_add_then_delete(self):
        # python test_integration.py TestEditOrderParts.test_edit_add_then_delete

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        m = widget.controller_part.view.model()
        widget.controller_part.view.setCurrentIndex(m.index(0, 0))

        widget.controller_part.view.setFocus(Qt.OtherFocusReason)
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_Up)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_F5)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part zero")

        # Skip a line, effectively creating a bloank order part
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_F5,
                       Qt.ShiftModifier)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part two")

        # Save will compress the blank order part
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        # Go up. We are now on top of a couple order parts list.
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_Up)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_Up)  # modifier, delay
        app.processEvents()
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_Up)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_F8)  # modifier, delay
        app.processEvents()

        # app.exec_()
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        assert len(order.parts) == 2

    def test_save_preserve_order(self):
        # python test_integration.py TestEditOrderParts.test_save_preserve_order

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        m = widget.controller_part.view.model()
        widget.controller_part.view.setCurrentIndex(m.index(0, 0))

        widget.controller_part.view.setFocus(Qt.OtherFocusReason)
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_Up)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view,
                       Qt.Key_F5)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part zero")

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Escape)  # modifier, delay
        QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_F5,
                       Qt.ShiftModifier)  # modifier, delay
        app.processEvents()

        self._fill_order_part("Order part two")

        # app.exec_()

        # We'll save several times to give to dict a chance
        # to mess keys around

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        self.assertEqual("0Order part zero", order.parts[0].description)
        self.assertEqual("0Order part two", order.parts[2].description)

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        self.assertEqual("0Order part zero", order.parts[0].description)
        self.assertEqual("0Order part two", order.parts[2].description)

    def test_save_preserve_operation_order2(self):
        order = self._make_order()
        order_id = order.order_id

        for i in range(10):
            operation = self._operation_dao.make()
            operation.production_file = order.parts[0].production_file[0]
            operation.description = "," + str(i + 1)
            operation.operation_model = self.opdef_op
            operation.planned_hours = (i + 10) * 10
            operation.position = 11 - i
            session().add(operation)

        self._order_dao.recompute_position_labels(order)

        session().commit()

        descriptions = [op.description for op in order.parts[0].operations]

        mainlog.debug(order)
        self.widget._panel_visible = True
        self.widget.reset_order(order_id, overwrite=True)

        # Edit superficially
        self.widget.controller_operation.view.setFocus(Qt.OtherFocusReason)

        for i in range(5):
            QTest.keyEvent(QTest.Click, self.app.focusWidget(),
                           Qt.Key_Down)  # modifier, delay
            self.app.processEvents()

        # set on description
        QTest.keyEvent(QTest.Click, self.app.focusWidget(),
                       Qt.Key_Right)  # modifier, delay
        self.app.processEvents()

        # change the description
        QTest.keyClicks(self.app.focusWidget(), "Zulu")
        self.app.processEvents()
        QTest.keyEvent(QTest.Click, self.app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        self.app.processEvents()

        # Another one
        QTest.keyEvent(QTest.Click, self.app.focusWidget(),
                       Qt.Key_Escape)  # stop current editing
        self.app.processEvents()
        QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_Tab,
                       Qt.ShiftModifier)
        self.app.processEvents()
        QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_Tab,
                       Qt.ShiftModifier)
        self.app.processEvents()

        QTest.keyEvent(QTest.Click, self.app.focusWidget(),
                       Qt.Key_Down)  # modifier, delay
        self.app.processEvents()
        QTest.keyEvent(QTest.Click, self.app.focusWidget(),
                       Qt.Key_Down)  # modifier, delay
        self.app.processEvents()
        QTest.keyClicks(self.app.focusWidget(), "Zulu")
        self.app.processEvents()
        QTest.keyEvent(QTest.Click, self.app.focusWidget(),
                       Qt.Key_Enter)  # modifier, delay
        self.app.processEvents()

        # Save
        QTest.keyEvent(QTest.Click, self.app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        self.app.processEvents()

        mainlog.debug(descriptions)
        mainlog.debug([op.description for op in order.parts[0].operations])

        order = dao.order_dao.find_by_id(order_id)
        operations = order.parts[0].operations

        for i in range(1, len(descriptions)):  # Skip the first one
            self.assertEqual(descriptions[i].split(',')[1],
                             operations[i].description.split(',')[1])

        # self.app.exec_()

    def test_save_preserve_operation_order(self):
        # python test_integration.py TestEditOrderParts.test_save_preserve_order

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        widget.controller_operation.view.setFocus(Qt.OtherFocusReason)
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_F5,
                       Qt.ShiftModifier)
        app.processEvents()

        # self._encode_imputable_operation("Description1")
        self._encode_imputable_operation("Description2")

        self._fix_focus(widget, widget.controller_operation.view)

        mainlog.debug("Second row " * 10)
        self._encode_imputable_operation("Description3")

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        # Go at the end of the table

        widget.controller_operation.view.setFocus(Qt.OtherFocusReason)

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Down)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Down)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Down)  # modifier, delay
        app.processEvents()

        # app.exec_()

        # Now we reverse the operations order

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_F6,
                       Qt.ShiftModifier)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_F6,
                       Qt.ShiftModifier)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Down)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_Down)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_F6,
                       Qt.ShiftModifier)  # modifier, delay
        app.processEvents()

        # app.exec_()

        # Save

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        # Check the operations order
        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        mainlog.debug(order.parts[0].operations[0].description)
        mainlog.debug(order.parts[0].operations[1].description)
        mainlog.debug(order.parts[0].operations[2].description)

        assert "3" in order.parts[0].operations[0].description
        assert "2" in order.parts[0].operations[1].description
        assert "1" in order.parts[0].operations[2].description

    @Slot()
    def _lookup(self):
        QTest.keyEvent(QTest.Click, self.app.activeModalWidget(), Qt.Key_Enter)

    @Slot()
    def _accept_dialog(self):
        QTest.keyEvent(QTest.Click, self.app.activeModalWidget(), Qt.Key_Enter)

    @Slot()
    def _cancel_dialog(self):
        QTest.keyEvent(QTest.Click, self.app.activeModalWidget(),
                       Qt.Key_Escape)

    def test_change_order_customer(self):
        customer2 = self._customer_dao.make(
            "AAAA")  # Name chosen so it happens first int he customer dialog
        self._customer_dao.save(customer2)

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        self._encode_imputable_operation("Description2")
        self._encode_imputable_operation("Description3")

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        # Make sure the test is set up correctly
        preorder = self.order_dao.find_by_id_frozen(
            widget._current_order.order_id)
        assert preorder.customer_id == self.customer.customer_id

        # We're going to have a modal dialog for the new
        # customer name. So we prepare to click on it.

        timer = QTimer()
        timer.timeout.connect(self._lookup)
        timer.setSingleShot(True)
        timer.start(1000)

        widget.change_customer()
        # app.exec_() # Wait for the timer to shoot

        mainlog.debug("test_change_order_customer" * 10)
        mainlog.debug(app.focusWidget())

        widget.setFocus(
            Qt.OtherFocusReason)  # This refocus was introduced for linux
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        mainlog.debug("test_change_order_customer")

        preorder = self.order_dao.find_by_id_frozen(
            widget._current_order.order_id)
        assert preorder.customer_id == customer2.customer_id

        mainlog.debug("test_change_order_customer")

        self.order_dao.delete(preorder.order_id)
        self.dao.customer_dao.delete(customer2.customer_id)

    def test_change_order_customer_cancelled(self):
        customer2 = self._customer_dao.make(
            "AAAA")  # Name chosen so it happens first int he customer dialog
        self._customer_dao.save(customer2)

        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        self._encode_imputable_operation("Description2")
        self._encode_imputable_operation("Description3")

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        # Make sure the test is set up correctly
        preorder = self.order_dao.find_by_id_frozen(
            widget._current_order.order_id)
        assert preorder.customer_id == self.customer.customer_id

        # We're going to have a modal dialog for the new
        # customer name. So we prepare to click on it.

        timer = QTimer()
        timer.timeout.connect(self._cancel_dialog)
        timer.setSingleShot(True)
        timer.start(1000)  # Had 250, my linux seems to prefer 1000

        widget.change_customer()  # blocks
        app.processEvents()
        # app.exec_() # Wait for the timer to shoot

        widget.setFocus(
            Qt.OtherFocusReason)  # This refocus was introduced for linux

        for i in range(1000):
            app.processEvents()  # Linux needs a break

        mainlog.debug("Pressing ctrl-S on this widget : {}".format(
            app.focusWidget()))
        # app.exec_()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        preorder = self.order_dao.find_by_id_frozen(
            widget._current_order.order_id)
        assert preorder.customer_id == self.customer.customer_id

        self.order_dao.delete(preorder.order_id)
        self.dao.customer_dao.delete(customer2.customer_id)

    def test_delete_order_happy(self):
        app = self.app
        widget = self.widget
        mw = self.mw
        self._make_basic_preorder()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        deleted_order_id = widget._current_order.order_id

        # We're going to have a modal dialog for the new
        # customer name. So we prepare to click on it.

        timer = QTimer()
        timer.timeout.connect(self._accept_dialog)
        timer.setSingleShot(True)
        timer.start(250)

        widget.delete_button_clicked()

        assert not self.order_dao.find_by_id_frozen(deleted_order_id,
                                                    resilient=True)

    def test_delete_unsaved_order(self):
        app = self.app
        widget = self.widget
        mw = self.mw
        # self._make_basic_preorder()
        widget.edit_new_order(self.customer.customer_id)

        self.prepare_to_click_dialog("delete_only_saved_order")
        widget.delete_button_clicked()
        assert self.dialog_test_result

    def _fill_preorder_print_dialog(self):
        d = self.app.activeModalWidget()
        d.message_text_area.setText("ZuluHeader")
        d.message_text_area_footer.setText("ZuluFooter")

        QTest.keyEvent(QTest.Click, d, Qt.Key_Enter)

    def test_print_preorder(self):
        # python test_integration.py TestEditOrderParts.test_print_preorder

        app = self.app
        widget = self.widget
        self._make_basic_preorder()
        self._encode_imputable_operation("Description2")
        self._encode_imputable_operation("Description3")
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        # We're going to have a modal dialog for the
        # preorder print. So we prepare to click on it.

        timer = QTimer()
        timer.timeout.connect(self._fill_preorder_print_dialog)
        timer.setSingleShot(True)
        timer.start(250)

        self.prepare_to_click_dialog("set_preorder_sent_state", 3)
        widget.preorderPrint()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)
        self.assertEqual("ZuluHeader", order.preorder_print_note)
        self.assertEqual("ZuluFooter", order.preorder_print_note_footer)

    def test_delete_an_operation(self):
        # python test_integration.py TestEditOrderParts.test_delete_an_operation

        order = self._make_order()
        order_id = order.order_id

        app = self.app
        widget = self.widget
        widget.reset_order(order.order_id, overwrite=True)
        widget.refresh_action()

        session().close()

        widget.controller_operation.view.setFocus(Qt.OtherFocusReason)
        QTest.keyEvent(QTest.Click, app.focusWidget(),
                       Qt.Key_F8)  # modifier, delay
        app.processEvents()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(order_id)
        self.assertTrue(not order.parts[0].operations)
Ejemplo n.º 10
0
 def setUpClass(cls):
     super(TestClockService, cls).setUpClass()
     cls.server = JsonCallWrapper(ClockService(),
                                  JsonCallWrapper.IN_PROCESS_MODE)
Ejemplo n.º 11
0
    d = apply_changes(order, change_tracker)

    order.parts.swap(0, 1)
    d = apply_changes(order, change_tracker)

    d = change_tracker.serialize_full(
        session().query(Order).filter(
            Order.order_id == order.order_id).one(), )

    pprint(d)

    change_tracker.unserialize_full(d)

    # from koi.server.json_decorator import horse_json_encoder
    # e = horse_json_encoder.encode(d)
    # print(e)

    # --------------------------------------------------------------------------------------
    # service = EmployeeService(change_tracker)
    service = OrderService(change_tracker)
    remote_service = JsonCallWrapper(service, JsonCallWrapper.DIRECT_MODE)

    d = remote_service.load_all()

    pprint(d)

    change_tracker.unserialize_full(d)

    exit()
    # --------------------------------------------------------------------------------------
Ejemplo n.º 12
0
            "base_url") + "/remove_file?file_id={}".format(doc_id)
        urlopener.open(url)


def download_document(doc_id, progress_tracker=None, destination=None):
    """ Download document to a given or temporary file. The temporary file
    name reflects the original name and extension.

    :param progress_tracker: a progress tacker
    :param destination: Where to store the file (full path, with filename).
    :return: the full path to the downloaded file. You'll have to delete that
    file if you need to.
    """

    url = configuration.get(
        "DownloadSite",
        "base_url") + "/download_file?file_id={}".format(doc_id)
    return download_file(url, progress_tracker, destination)


from koi.doc_manager.documents_service import documents_service
from koi.server.json_decorator import JsonCallWrapper

documents_service = JsonCallWrapper(documents_service,
                                    JsonCallWrapper.HTTP_MODE)


def update_name_and_description(document_id, name, description):
    documents_service.update_name_and_description(document_id, name,
                                                  description)
Ejemplo n.º 13
0
    init_db_session(configuration.database_url, metadata, False
                    or configuration.echo_query)

from koi.business_charts import *

if __name__ == "__main__":
    app = QApplication(sys.argv)

    # widget = MonthlyFinancialReportOverviewWidget(None)
    # widget = MonthlyProductionReportOverviewWidget(None)

    global remote_indicators_service
    from koi.charts.indicators_service import IndicatorsService
    from koi.server.json_decorator import JsonCallWrapper

    remote_indicators_service = JsonCallWrapper(IndicatorsService(),
                                                JsonCallWrapper.DIRECT_MODE)

    import logging
    mainlog.setLevel(logging.DEBUG)

    dao.set_session(session())
    begin, end = month_before(date.today(), 12), date.today()
    remote_indicators_service.clear_caches()

    # widget = ISOIndicatorsWidget(None, remote_indicators_service) # Done
    # widget = FinancialIndicatorsWidget(None, remote_indicators_service) # DONE
    widget = MonthlyProductionReportOverviewWidget(None,
                                                   remote_indicators_service)

    widget.refresh_action()
Ejemplo n.º 14
0
 def setUpClass(cls):
     super(TestPeopleAdminService, cls).setUpClass()
     cls.server = JsonCallWrapper(DayEventService(),
                                  JsonCallWrapper.IN_PROCESS_MODE)