示例#1
0
    def _on_WorkOrderStatusChangedEvent(self, order, old_status):
        if old_status == WorkOrder.STATUS_OPENED:
            #Do nothing at this point.
            return

        optical_wo = OpticalWorkOrder.find_by_work_order(order.store, order)
        # If there is no optical WO, nothing to do here
        if optical_wo is None:
            return

        if optical_wo.can_create_purchase():
            with api.new_store() as store:
                rv = run_dialog(OpticalSupplierEditor, None, store, order)
            if not rv:
                # Return None to let the status be changed without creating a purchase order
                return

            order.supplier_order = rv.supplier_order
            optical_wo.create_purchase(order.store.fetch(rv.supplier),
                                       order.store.fetch(rv.item),
                                       rv.is_freebie)
            return

        for purchase in PurchaseOrder.find_by_work_order(order.store, order):
            if optical_wo.can_receive_purchase(purchase):
                optical_wo.receive_purchase(purchase, reserve=True)
示例#2
0
    def _on_WorkOrderStatusChangedEvent(self, order, old_status):
        if old_status == WorkOrder.STATUS_OPENED:
            #Do nothing at this point.
            return

        optical_wo = OpticalWorkOrder.find_by_work_order(order.store, order)
        # If there is no optical WO, nothing to do here
        if optical_wo is None:
            return

        if optical_wo.can_create_purchase():
            with api.new_store() as store:
                rv = run_dialog(OpticalSupplierEditor, None, store, order)
            if not rv:
                # Return None to let the status be changed without creating a purchase order
                return

            order.supplier_order = rv.supplier_order
            optical_wo.create_purchase(order.store.fetch(rv.supplier),
                                       order.store.fetch(rv.item),
                                       rv.is_freebie)
            return

        for purchase in PurchaseOrder.find_by_work_order(order.store, order):
            if optical_wo.can_receive_purchase(purchase):
                optical_wo.receive_purchase(purchase, reserve=True)
示例#3
0
    def test_find_by_work_order(self):
        work_order = self.create_workorder()
        purchase = self.create_purchase_order()
        purchase.work_order = work_order

        results = PurchaseOrder.find_by_work_order(work_order.store, work_order)
        for expected_purchase in results:
            self.assertEquals(purchase, expected_purchase)
示例#4
0
    def test_find_by_work_order(self):
        work_order = self.create_workorder()
        purchase = self.create_purchase_order()
        purchase.work_order = work_order

        results = PurchaseOrder.find_by_work_order(work_order.store, work_order)
        for expected_purchase in results:
            self.assertEquals(purchase, expected_purchase)
示例#5
0
    def test_new_purchase_confirm(self, run_dialog, new_store):
        new_store.return_value = self.store

        supplier = self.create_supplier()
        sale = self.create_sale()
        product = self.create_product()
        work_order = self.create_workorder()
        work_order.status = WorkOrder.STATUS_WORK_IN_PROGRESS
        work_order.sale = sale
        work_item = work_order.add_sellable(product.sellable)
        self.create_optical_work_order(work_order)
        app = self.create_app(ServicesApp, u'services')
        app.search.refresh()

        for wo_view in app.search.results:
            if wo_view.work_order == work_order:
                break

        self.assertIsNotNone(wo_view)
        app.search.results.select(wo_view)

        # Before the action, there are no purchase orders for this work order
        results = PurchaseOrder.find_by_work_order(self.store, work_order)
        self.assertEquals(results.count(), 0)

        action = OpticalWorkOrderActions.get_instance().get_action('OpticalNewPurchase')
        run_dialog.return_value = Settable(supplier=supplier,
                                           supplier_order='1111',
                                           item=work_item,
                                           is_freebie=True)
        with contextlib.nested(
                mock.patch.object(self.store, 'commit'),
                mock.patch.object(self.store, 'close')):
            self.activate(action)

        run_dialog.assert_called_once_with(OpticalSupplierEditor, None,
                                           self.store, work_order)

        # Now there should be one purchase order
        results = PurchaseOrder.find_by_work_order(self.store, work_order)
        self.assertEquals(results.count(), 1)
        app.deactivate()
示例#6
0
    def test_new_purchase_confirm(self, run_dialog, new_store):
        new_store.return_value = self.store

        supplier = self.create_supplier()
        sale = self.create_sale()
        product = self.create_product()
        work_order = self.create_workorder()
        work_order.status = WorkOrder.STATUS_WORK_IN_PROGRESS
        work_order.sale = sale
        work_item = work_order.add_sellable(product.sellable)
        self.create_optical_work_order(work_order)
        app = self.create_app(ServicesApp, u'services')
        app.search.refresh()

        for wo_view in app.search.results:
            if wo_view.work_order == work_order:
                break

        self.assertIsNotNone(wo_view)
        app.search.results.select(wo_view)

        # Before the action, there are no purchase orders for this work order
        results = PurchaseOrder.find_by_work_order(self.store, work_order)
        self.assertEquals(results.count(), 0)

        action = OpticalWorkOrderActions.get_instance().get_action('OpticalNewPurchase')
        run_dialog.return_value = Settable(supplier=supplier,
                                           supplier_order='1111',
                                           item=work_item,
                                           is_freebie=True)
        with contextlib.nested(
                mock.patch.object(self.store, 'commit'),
                mock.patch.object(self.store, 'close')):
            self.activate(action)

        run_dialog.assert_called_once_with(OpticalSupplierEditor, None,
                                           self.store, work_order)

        # Now there should be one purchase order
        results = PurchaseOrder.find_by_work_order(self.store, work_order)
        self.assertEquals(results.count(), 1)
        app.deactivate()
示例#7
0
    def test_work_order_cancel_change_status(self):
        product = self.create_product()
        opt_type = OpticalProduct.TYPE_GLASS_LENSES
        optical_product = self.create_optical_product(optical_type=opt_type)
        optical_product.product = product
        sale = self.create_sale()
        sale_item = sale.add_sellable(sellable=product.sellable)
        wo = self.create_workorder()
        work_item = wo.add_sellable(product.sellable)
        work_item.sale_item = sale_item
        wo.sale = sale
        wo.approve(self.current_user)

        app = self.create_app(ServicesApp, u'services')
        app.search.refresh()

        for wo_view in app.search.results:
            if wo_view.work_order == wo:
                break

        self.assertIsNotNone(wo_view)
        app.search.results.select(wo_view)

        with mock.patch('plugins.optical.opticalui.run_dialog') as run_dialog:
            # No optical work order related to this WO, the dialog doesn't even run
            wo.work(self.current_branch, self.current_user)
            self.assertNotCalled(run_dialog)

        wo.pause(self.current_user, 'Reason')
        optical_wo = self.create_optical_work_order()
        optical_wo.work_order = wo

        with mock.patch('plugins.optical.opticalui.run_dialog') as run_dialog:
            run_dialog.return_value = None
            wo.work(self.current_branch, self.current_user)
            # At this point we didnt create a purchase
            results = PurchaseOrder.find_by_work_order(wo.store, wo)
            self.assertEquals(len(list(results)), 0)
        app.deactivate()
示例#8
0
    def test_work_order_cancel_change_status(self):
        product = self.create_product()
        opt_type = OpticalProduct.TYPE_GLASS_LENSES
        optical_product = self.create_optical_product(optical_type=opt_type)
        optical_product.product = product
        sale = self.create_sale()
        sale_item = sale.add_sellable(sellable=product.sellable)
        wo = self.create_workorder()
        work_item = wo.add_sellable(product.sellable)
        work_item.sale_item = sale_item
        wo.sale = sale
        wo.approve()

        app = self.create_app(ServicesApp, u'services')
        app.search.refresh()

        for wo_view in app.search.results:
            if wo_view.work_order == wo:
                break

        self.assertIsNotNone(wo_view)
        app.search.results.select(wo_view)

        with mock.patch('plugins.optical.opticalui.run_dialog') as run_dialog:
            # No optical work order related to this WO, the dialog doesn't even run
            wo.work()
            self.assertNotCalled(run_dialog)

        wo.pause('Reason')
        optical_wo = self.create_optical_work_order()
        optical_wo.work_order = wo

        with mock.patch('plugins.optical.opticalui.run_dialog') as run_dialog:
            run_dialog.return_value = None
            wo.work()
            # At this point we didnt create a purchase
            results = PurchaseOrder.find_by_work_order(wo.store, wo)
            self.assertEquals(len(list(results)), 0)
        app.deactivate()
示例#9
0
    def test_work_order_change_status(self):
        supplier = self.create_supplier()
        product = self.create_product()
        opt_type = OpticalProduct.TYPE_GLASS_LENSES
        optical_product = self.create_optical_product(optical_type=opt_type)
        optical_product.product = product
        sale = self.create_sale()
        sale_item = sale.add_sellable(sellable=product.sellable)
        wo = self.create_workorder()
        work_item = wo.add_sellable(product.sellable)
        work_item.sale_item = sale_item
        wo.sale = sale
        optical_wo = self.create_optical_work_order()
        optical_wo.work_order = wo

        app = self.create_app(ServicesApp, u'services')
        app.search.refresh()

        for wo_view in app.search.results:
            if wo_view.work_order == wo:
                break

        self.assertIsNotNone(wo_view)
        app.search.results.select(wo_view)
        with mock.patch('plugins.optical.opticalui.run_dialog') as run_dialog:
            wo.approve(self.current_user)
            run_dialog.return_value = Settable(supplier=supplier,
                                               supplier_order='1111',
                                               item=work_item,
                                               is_freebie=False)
            wo.work(self.current_branch, self.current_user)
            results = PurchaseOrder.find_by_work_order(wo.store, wo)
            self.assertEquals(len(list(results)), 1)

        wo.finish(self.current_branch, self.current_user)
        app.deactivate()
示例#10
0
    def test_work_order_change_status(self):
        supplier = self.create_supplier()
        product = self.create_product()
        opt_type = OpticalProduct.TYPE_GLASS_LENSES
        optical_product = self.create_optical_product(optical_type=opt_type)
        optical_product.product = product
        sale = self.create_sale()
        sale_item = sale.add_sellable(sellable=product.sellable)
        wo = self.create_workorder()
        work_item = wo.add_sellable(product.sellable)
        work_item.sale_item = sale_item
        wo.sale = sale
        optical_wo = self.create_optical_work_order()
        optical_wo.work_order = wo

        app = self.create_app(ServicesApp, u'services')
        app.search.refresh()

        for wo_view in app.search.results:
            if wo_view.work_order == wo:
                break

        self.assertIsNotNone(wo_view)
        app.search.results.select(wo_view)
        with mock.patch('plugins.optical.opticalui.run_dialog') as run_dialog:
            wo.approve()
            run_dialog.return_value = Settable(supplier=supplier,
                                               supplier_order='1111',
                                               item=work_item,
                                               is_freebie=False)
            wo.work()
            results = PurchaseOrder.find_by_work_order(wo.store, wo)
            self.assertEquals(len(list(results)), 1)

        wo.finish()
        app.deactivate()