Esempio n. 1
0
    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()
    def on_cancel_button__clicked(self, event):
        msg_text = _(u'This will cancel the transfer. Are you sure?')

        # 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 = run_dialog(NoteEditor,
                            self,
                            self.model.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=note_min_length)

        if not retval:
            return

        # Try to cancel the transfer fiscally with a fiscal plugin. If False is
        # returned, the cancellation failed, so we don't proceed.
        if StockOperationTryFiscalCancelEvent.emit(self.model,
                                                   retval.notes) is False:
            warning(
                _("The cancellation was not authorized by SEFAZ. You "
                  "should do a reverse transfer."))
            return

        user = api.get_current_user(self.store)
        branch = api.get_current_branch(self.store)
        responsible = user.person.employee
        self.model.cancel(user, responsible, retval.notes, branch)
        self.store.commit(close=False)
        self.receival_date.set_property('model-attribute', 'cancel_date')
        self.transfer_proxy.update_many(
            ['destination_responsible_name', 'receival_date'])
        self.setup_proxies()
        self._setup_status()
Esempio n. 3
0
    def on_cancel_button__clicked(self, event):
        msg_text = _(u'This will cancel the transfer. Are you sure?')

        # 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 = run_dialog(
            NoteEditor, self, self.model.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=note_min_length)

        if not retval:
            return

        # Try to cancel the transfer fiscally with a fiscal plugin. If False is
        # returned, the cancellation failed, so we don't proceed.
        if StockOperationTryFiscalCancelEvent.emit(self.model, retval.notes) is False:
            warning(_("The cancellation was not authorized by SEFAZ. You "
                      "should do a reverse transfer."))
            return

        responsible = api.get_current_user(self.store).person.employee
        self.model.cancel(responsible, retval.notes)
        self.store.commit(close=False)
        self.receival_date.set_property('model-attribute', 'cancel_date')
        self.transfer_proxy.update_many(['destination_responsible_name',
                                         'receival_date'])
        self.setup_proxies()
        self._setup_status()