def test_cancel_workorder_confirm(self, new_store, run_dialog): new_store.return_value = self.store self.clean_domain([WorkOrderItem, WorkOrder]) workorder = self.create_workorder() api.sysparam(self.store).update_parameter(u'SMART_LIST_LOADING', u'0') app = self.create_app(MaintenanceApp, u'maintenance') olist = app.results olist.select(olist[0]) # Initial status for the order is Opened self.assertEquals(workorder.status, WorkOrder.STATUS_OPENED) self.assertSensitive(app, ['Cancel']) with mock.patch.object(self.store, 'close'): with mock.patch.object(self.store, 'commit'): # Click the cancel order, and confirm the change run_dialog.return_value = Note(notes=u'xxx') self.activate(app.Cancel) run_dialog.assert_called_once_with( NoteEditor, self.store, message_text=(u'This will cancel the selected order. ' u'Are you sure?'), model=Note(), mandatory=True, label_text=u'Reason') # Status should be updated to cancelled. self.assertEquals(workorder.status, WorkOrder.STATUS_CANCELLED)
def test_cancel_workorder_confirm(self, new_store, run_dialog): new_store.return_value = self.store self.clean_domain([WorkOrderItem, WorkOrder]) workorder = self.create_workorder() api.sysparam.set_bool(self.store, 'SMART_LIST_LOADING', False) app = self.create_app(ServicesApp, u'services') olist = app.search.results olist.select(olist[0]) # Initial status for the order is Opened self.assertEqual(workorder.status, WorkOrder.STATUS_OPENED) self.assertSensitive(app.actions, ['Cancel']) with mock.patch.object(self.store, 'close'): with mock.patch.object(self.store, 'commit'): # Click the cancel order, and confirm the change run_dialog.return_value = Note(notes=u'xxx') self.activate(app.actions.get_action('Cancel')) run_dialog.assert_called_once_with( NoteEditor, None, None, message_text=(u"This will cancel the selected order. " u"Any reserved items will return to stock. " u"Are you sure?"), model=Note(), mandatory=True, label_text=u'Reason') # Status should be updated to cancelled. self.assertEqual(workorder.status, WorkOrder.STATUS_CANCELLED) app.deactivate()
def test_paid_sales_cancel(self, new_store): with self.sysparam(ALLOW_CANCEL_CONFIRMED_SALES=True): new_store.return_value = self.store app = self.create_app(SalesApp, u'sales') sale_view = app.results[0] app.results.select(sale_view) sale_view.status = Sale.STATUS_CONFIRMED sale_view.sale.status = Sale.STATUS_CONFIRMED app._update_toolbar() for item in sale_view.sale.get_items(): item.quantity = 2 with contextlib.nested(mock.patch.object(app, 'run_dialog'), mock.patch.object(self.store, 'commit'), mock.patch.object(self.store, 'close')) as context: run_dialog = context[0] run_dialog.return_value = Note() self.activate(app.SalesCancel) msg_text = u"This will cancel the sale, Are you sure?" args, kwargs = run_dialog.call_args self.assertEquals(args, (NoteEditor, self.store)) self.assertEquals(kwargs['model'], None) self.assertEquals(kwargs['message_text'], msg_text) self.assertEquals(kwargs['label_text'], u"Reason") self.assertEquals(kwargs['mandatory'], True) self.assertEquals(kwargs['ok_button_label'], u"Cancel sale") self.assertEquals(kwargs['cancel_button_label'], u"Don't cancel") self.assertEquals(run_dialog.call_count, 1) self.assertEquals(sale_view.sale.status, Sale.STATUS_CANCELLED)
def _run_notes_editor(self, msg_text, mandatory): return self.run_dialog(NoteEditor, self.store, model=Note(), message_text=msg_text, label_text=_(u"Reason"), mandatory=mandatory)
def test_cancel_order_nfce_plugin_active(self, get_plugin_manager, run_dialog): dest_branch = Branch.get_active_remote_branches( self.store, api.get_current_branch(self.store))[0] source_branch = api.get_current_branch(self.store) order = self.create_transfer_order(source_branch=source_branch, dest_branch=dest_branch) self.create_transfer_order_item(order=order) order.identifier = 28474 order.open_date = localdatetime(2012, 2, 2) order.send(self.current_user) dialog = TransferOrderDetailsDialog(self.store, order) self.assertSensitive(dialog, ['cancel_button']) get_plugin_manager.is_active.return_value = True run_dialog.return_value = Note() with mock.patch.object(self.store, 'commit'): self.click(dialog.cancel_button) msg_text = u"This will cancel the transfer. Are you sure?" run_dialog.assert_called_once_with( NoteEditor, dialog, order.store, model=None, message_text=msg_text, label_text=u"Reason", mandatory=True, ok_button_label=u"Cancel transfer", cancel_button_label=u"Don't cancel", min_length=15) self.assertEqual(order.status, TransferOrder.STATUS_CANCELLED) self.assertEqual(order.receival_date, None)
def _run_notes_editor(self, msg_text=u'', mandatory=True, reason=_('Reason')): return self.run_dialog(NoteEditor, None, model=Note(), message_text=msg_text, label_text=reason, mandatory=mandatory)
def _ask_reason(self, work_order, new_status): if (work_order.status, new_status) not in self.need_reason: return None msg_text = self.status_question_map[new_status] rv = run_dialog(NoteEditor, None, work_order.store, model=Note(), message_text=msg_text, label_text=_(u"Reason"), mandatory=True) if not rv: # False means abort the status change return False return rv.notes
def _maybe_toggle_status(self): if self.model.can_approve(): self.model.approve() elif self.model.can_work(): self.model.work() elif self.model.can_pause(): msg_text = _(u"This will pause the order. Are you sure?") rv = run_dialog( NoteEditor, self, self.store, model=Note(), message_text=msg_text, label_text=_(u"Reason"), mandatory=True) if not rv: return self.model.pause(reason=rv.notes) self._update_view() self.history_slave.update_items()
def test_cancel_order_sefaz_rejected(self, warning, run_dialog): order = self.create_transfer_order() self.create_transfer_order_item(order=order) order.identifier = 28474 order.open_date = localdatetime(2012, 2, 2) order.send(self.current_user) dialog = TransferOrderDetailsDialog(self.store, order) self.assertSensitive(dialog, ['cancel_button']) run_dialog.return_value = Note() module = 'stoqlib.domain.events.StockOperationTryFiscalCancelEvent.emit' with mock.patch(module) as emit: with mock.patch.object(self.store, 'commit'): emit.return_value = False self.click(dialog.cancel_button) self.assertEqual(order.status, TransferOrder.STATUS_SENT) warning.assert_called_once_with( "The cancellation was not authorized by SEFAZ. You should do a " "reverse transfer.")
def _set_client_informed(self, view): # Drag and drop on the same Column if view.work_order.client_informed_date: return rv = run_dialog(NoteEditor, None, view.work_order.store, model=Note(), label_text=WorkOrderActions.inform_question, mandatory=True) if not rv: return with api.new_store() as store: work_order = store.fetch(view.work_order) # Make the work_order go through all the status if not work_order.is_finished(): work_order.change_status(WorkOrder.STATUS_WORK_FINISHED) work_order.inform_client(rv.notes)
def _ask_reason(self, work_order, new_status): if (work_order.status, new_status) not in self.need_reason: return None if work_order.status == new_status and not work_order.is_informed(): # This will prevent the NoteEditor popup when drag and drop in the # same column return None msg_text = self.status_question_map[new_status] rv = run_dialog(NoteEditor, None, work_order.store, model=Note(), message_text=msg_text, label_text=_(u"Reason"), mandatory=True) if not rv: # False means abort the status change return False return rv.notes