def on_SalesCancel__activate(self, action): sale_view = self.results.get_selected() can_cancel = api.sysparam.get_bool('ALLOW_CANCEL_LAST_COUPON') # A plugin (e.g. ECF) can avoid the cancelation of a sale # because it wants it to be cancelled using another way if can_cancel and SaleAvoidCancelEvent.emit(sale_view.sale): return store = api.new_store() sale = store.fetch(sale_view.sale) msg_text = _(u"This will cancel the sale, Are you sure?") model = SaleComment(store=store, sale=sale, author=api.get_current_user(store)) retval = self.run_dialog(NoteEditor, store, model=model, attr_name='comment', message_text=msg_text, label_text=_(u"Reason"), mandatory=True, ok_button_label=_(u"Cancel sale"), cancel_button_label=_(u"Don't cancel")) if not retval: store.rollback() return sale.cancel() store.commit(close=True) self.refresh()
def on_SalesCancel__activate(self, action): sale_view = self.results.get_selected() can_cancel = api.sysparam.get_bool('ALLOW_CANCEL_LAST_COUPON') if can_cancel and ECFIsLastSaleEvent.emit(sale_view.sale): info( _("That is last sale in ECF. Return using the menu " "ECF - Cancel Last Document")) return store = api.new_store() sale = store.fetch(sale_view.sale) msg_text = _(u"This will cancel the sale, Are you sure?") model = SaleComment(store=store, sale=sale, author=api.get_current_user(store)) retval = self.run_dialog(NoteEditor, store, model=model, attr_name='comment', message_text=msg_text, label_text=_(u"Reason"), mandatory=True, ok_button_label=_(u"Cancel sale"), cancel_button_label=_(u"Don't cancel")) if not retval: store.rollback() return sale.cancel() store.commit(close=True) self.refresh()
def on_observations_button__clicked(self, *args): self.store.savepoint('before_run_notes_editor') model = self.model.comments.first() if not model: model = SaleComment(store=self.store, sale=self.model, author=api.get_current_user(self.store)) rv = run_dialog(NoteEditor, self.wizard, self.store, model, 'comment', title=_('Sale observations')) if not rv: self.store.rollback_to_savepoint('before_run_notes_editor')
def _run_comments_editor(self, item=None): if item is not None: run_dialog(NoteEditor, self, self.store, item, 'comment', title=_('Sale Comment'), visual_mode=True) return with api.new_store() as store: item = SaleComment(store=store, sale=store.fetch(self.model.sale), author=api.get_current_user(store)) run_dialog(NoteEditor, self, store, item, 'comment', title=_('New Sale Comment')) if store.committed: self._refresh_comments()
def _cancel_last_sale(self, last_doc, store): if last_doc.last_sale.status == Sale.STATUS_RETURNED: return sale = store.fetch(last_doc.last_sale) value = sale.total_amount sale.cancel(force=True) comment = _(u"Cancelling last document on ECF") SaleComment(store=store, sale=sale, comment=comment, author=api.get_current_user(store)) till = Till.get_current(store) # TRANSLATORS: cash out = sangria till.add_debit_entry(value, _(u"Cash out: last sale cancelled")) last_doc.last_sale = None info(_("Document was cancelled"))
def on_SalesCancel__activate(self, action): sale_view = self.results.get_selected() # A plugin (e.g. ECF) can avoid the cancelation of a sale # because it wants it to be cancelled using another way if SaleAvoidCancelEvent.emit(sale_view.sale, Sale.STATUS_CANCELLED): return store = api.new_store() sale = store.fetch(sale_view.sale) msg_text = _(u"This will cancel the sale, Are you sure?") model = SaleComment(store=store, sale=sale, author=api.get_current_user(store)) # nfce plugin cancellation event requires a minimum length for the # cancellation reason note. We can't set this in the plugin because it's # not possible to identify unically this NoteEditor. if get_plugin_manager().is_active('nfce'): note_min_length = 15 else: note_min_length = 0 retval = self.run_dialog(NoteEditor, store, model=model, attr_name='comment', message_text=msg_text, label_text=_(u"Reason"), mandatory=True, ok_button_label=_(u"Cancel sale"), cancel_button_label=_(u"Don't cancel"), min_length=note_min_length) if not retval: store.rollback() return # Try to cancel the sale with sefaz. Don't cancel the sale if sefaz # reject it. if StockOperationTryFiscalCancelEvent.emit(sale) is False: warning( _("The cancellation was not authorized by SEFAZ. You should " "do a sale return.")) return sale.cancel() store.commit(close=True) self.refresh()