[POS-commit] r7154 - in stoqlib/trunk: plugins/ecf stoqlib/gui

Johan Dahlin jdahlin at async.com.br
Tue Aug 28 13:47:51 BRT 2007


Author: jdahlin
Date: Tue Aug 28 13:47:51 2007
New Revision: 7154

Modified:
   stoqlib/trunk/plugins/ecf/ecfui.py
   stoqlib/trunk/stoqlib/gui/fiscalprinter.py

Log:
#3498: Ao desativar uma ECF o sistema não deve realizar vendas

Modified: stoqlib/trunk/plugins/ecf/ecfui.py
==============================================================================
--- stoqlib/trunk/plugins/ecf/ecfui.py	(original)
+++ stoqlib/trunk/plugins/ecf/ecfui.py	Tue Aug 28 13:47:51 2007
@@ -29,6 +29,7 @@
 from stoqlib.domain.events import (SaleConfirmEvent, TillAddCashEvent,
                                    TillRemoveCashEvent, TillOpenEvent,
                                    TillCloseEvent)
+from stoqlib.exceptions import DeviceError
 from stoqlib.gui.base.dialogs import run_dialog
 from stoqlib.gui.events import StartApplicationEvent, CouponCreatedEvent
 from stoqlib.lib.message import info, warning, yesno
@@ -77,23 +78,20 @@
 
     def _validate_printer(self):
         if self._printer is None:
-            warning(_("This operation requires a connected fiscal printer"))
-            return False
+            raise DeviceError(
+                _("This operation requires a connected fiscal printer"))
 
-        if self._printer_verified:
-            return True
+        if not self._printer_verified:
+            domain = self._printer.get_printer()
+            driver = self._printer.get_driver()
+            self._status = ECFAsyncPrinterStatus(domain.device_name,
+                                                 printer=driver)
+
+            if not self._printer.check_serial():
+                raise DeviceError(
+                    _("Fiscalprinters serial number is different!"))
 
-        domain = self._printer.get_printer()
-        driver = self._printer.get_driver()
-        self._status = ECFAsyncPrinterStatus(domain.device_name, printer=driver)
-
-        if not self._printer.check_serial():
-            warning(_("Fiscalprinters serial number is different!"))
-            return False
-
-        self._printer_verified = True
-
-        return True
+            self._printer_verified = True
 
     def _add_ui_menus(self, appname, uimanager):
         if appname == 'pos':
@@ -174,8 +172,7 @@
     def _open_till(self, till):
         log.info('ECFCouponPrinter.open_till(%r)' % (till,))
 
-        if not self._validate_printer():
-            return False
+        self._validate_printer()
 
         # Don't do anything on till_open, eg the driver is responsible
         # for sending the LeituraX if needed
@@ -208,8 +205,11 @@
     def _close_till(self, till, previous_day):
         log.info('ECFCouponPrinter.close_till(%r, %r)' % (till, previous_day))
 
-        if not self._validate_printer():
-            return False
+        try:
+            self._validate_printer()
+        except DeviceError, e:
+            warning(e)
+            return
 
         retval = True
         while True:
@@ -238,28 +238,24 @@
     def _add_cash(self, till, value):
         log.info('ECFCouponPrinter.add_cash(%r, %r)' % (till, value,))
 
-        if not self._validate_printer():
-            return
+        self._validate_printer()
 
         self._printer.add_cash(value)
 
     def _remove_cash(self, till, value):
         log.info('ECFCouponPrinter.remove_cash(%r, %r)' % (till, value,))
 
-        if not self._validate_printer():
-            return
+        self._validate_printer()
 
         self._printer.remove_cash(value)
 
     def _confirm_sale(self, sale):
         log.info('ECFCouponPrinter.confirm_sale(%r)' % (sale,))
 
-        if not self._validate_printer():
-            return
+        self._validate_printer()
 
     def _coupon_create(self, fiscalcoupon):
-        if not self._validate_printer():
-            return
+        self._validate_printer()
 
         coupon = self._printer.create_coupon(fiscalcoupon)
         assert coupon
@@ -277,7 +273,10 @@
         return coupon
 
     def _cancel_last_document(self):
-        if not self._validate_printer():
+        try:
+            self._validate_printer()
+        except DeviceError, e:
+            warning(e)
             return
 
         if yesno(
@@ -292,7 +291,10 @@
             info(_("Document was cancelled"))
 
     def _till_summarize(self):
-        if not self._validate_printer():
+        try:
+            self._validate_printer()
+        except DeviceError, e:
+            warning(e)
             return
 
         self._printer.summarize()
@@ -328,12 +330,14 @@
 
 
     def _on_coupon__open(self, coupon):
+        self._validate_printer()
         coupon.open()
 
     def _on_coupon__identify_customer(self, coupon, person):
         coupon.identify_customer(person)
 
     def _on_coupon__add_item(self, coupon, item):
+        self._validate_printer()
         return coupon.add_item(item)
 
     def _on_coupon__remove_item(self, coupon, item_id):

Modified: stoqlib/trunk/stoqlib/gui/fiscalprinter.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/fiscalprinter.py	(original)
+++ stoqlib/trunk/stoqlib/gui/fiscalprinter.py	Tue Aug 28 13:47:51 2007
@@ -124,7 +124,16 @@
         """
         @returns: a new coupon
         """
-        return FiscalCoupon(self._parent)
+
+        coupon = FiscalCoupon(self._parent)
+
+        try:
+            CouponCreatedEvent.emit(coupon)
+        except DeviceError, e:
+            warning(e)
+            coupon = None
+
+        return coupon
 
 
 class FiscalCoupon(gobject.GObject):
@@ -147,8 +156,6 @@
     def __init__(self, parent):
         gobject.GObject.__init__(self)
 
-        CouponCreatedEvent.emit(self)
-
         self._parent = parent
         self._item_ids = {}
 
@@ -244,7 +251,7 @@
                     gtk.RESPONSE_YES, _(u"Resume"), _(u"Confirm later")):
                     return False
                 return self.open()
-            except DriverError, e:
+            except (DriverError, DeviceError), e:
                 warning(_(u"It is not possible to emit the coupon"),
                         str(e))
                 return False
@@ -257,7 +264,7 @@
 
         try:
             self.emit('totalize', sale)
-        except DriverError, details:
+        except (DriverError, DeviceError), details:
             warning(_(u"It is not possible to totalize the coupon"),
                     str(details))
             return False
@@ -295,7 +302,7 @@
         try:
             coupon_id = self.emit('close')
             return True
-        except DriverError, details:
+        except (DeviceError, DriverError), details:
             warning(_("It's not possible to close the coupon"), str(details))
 
         sale.coupon_id = coupon_id


More information about the POS-commit mailing list