[POS-commit] r5430 - in stoqlib/trunk: stoqlib/gui/editors

Johan Dahlin jdahlin at async.com.br
Fri Dec 1 14:47:47 BRST 2006


Author: jdahlin
Date: Fri Dec  1 14:47:47 2006
New Revision: 5430

Modified:
   stoqlib/trunk/data/glade/BaseCashSlave.glade
   stoqlib/trunk/stoqlib/gui/editors/tilleditor.py

Log:
#2971: Saldo de caixa, em suprimento e sangria

Modified: stoqlib/trunk/data/glade/BaseCashSlave.glade
==============================================================================
--- stoqlib/trunk/data/glade/BaseCashSlave.glade	(original)
+++ stoqlib/trunk/data/glade/BaseCashSlave.glade	Fri Dec  1 14:47:47 2006
@@ -30,8 +30,8 @@
                     </packing>
                 </child>
                 <child>
-                    <widget class="GtkLabel" id="cash_amount_lbl">
-                        <property name="label" context="yes" translatable="yes">Cash Amount:</property>
+                    <widget class="GtkLabel" id="label5">
+                        <property name="label" context="yes" translatable="yes">Balance:</property>
                         <property name="sizegroup">casheditor_label_sizegroup</property>
                         <property name="visible">True</property>
                         <property name="xalign">1.0</property>
@@ -44,8 +44,11 @@
                     </packing>
                 </child>
                 <child>
-                    <widget class="GtkLabel" id="label5">
+                    <widget class="GtkLabel" id="cash_amount_lbl">
+                        <property name="label" context="yes" translatable="yes">Cash Amount:</property>
+                        <property name="sizegroup">casheditor_label_sizegroup</property>
                         <property name="visible">True</property>
+                        <property name="xalign">1.0</property>
                     </widget>
                     <packing>
                         <property name="bottom_attach">3</property>
@@ -66,7 +69,7 @@
                     </packing>
                 </child>
                 <child>
-                    <widget class="GtkLabel" id="date">
+                    <widget class="ProxyLabel" id="date">
                         <property name="sizegroup">casheditor_label_sizegroup</property>
                         <property name="visible">True</property>
                         <property name="xalign">1.0</property>
@@ -78,12 +81,10 @@
                     </packing>
                 </child>
                 <child>
-                    <widget class="ProxyEntry" id="cash_amount">
-                        <property name="data_type">Decimal</property>
-                        <property name="is_focus">True</property>
-                        <property name="mandatory">True</property>
-                        <property name="model_attribute">value</property>
-                        <property name="sizegroup">casheditor_entry_sizegroup</property>
+                    <widget class="ProxyLabel" id="balance">
+                        <property name="data_type">currency</property>
+                        <property name="model_attribute">balance</property>
+                        <property name="sizegroup">casheditor_label_sizegroup</property>
                         <property name="visible">True</property>
                         <property name="xalign">1.0</property>
                     </widget>
@@ -96,8 +97,13 @@
                     </packing>
                 </child>
                 <child>
-                    <widget class="GtkLabel" id="label6">
+                    <widget class="ProxyEntry" id="value">
+                        <property name="data_type">Decimal</property>
+                        <property name="is_focus">True</property>
+                        <property name="mandatory">True</property>
+                        <property name="model_attribute">value</property>
                         <property name="visible">True</property>
+                        <property name="xalign">1.0</property>
                     </widget>
                     <packing>
                         <property name="bottom_attach">3</property>

Modified: stoqlib/trunk/stoqlib/gui/editors/tilleditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/tilleditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/tilleditor.py	Fri Dec  1 14:47:47 2006
@@ -67,6 +67,19 @@
     payment = None
     open_date = None
 
+class _BaseCashModel(object):
+    def __init__(self, entry):
+        self.entry = entry
+
+    def get_balance(self):
+        return currency(self.entry.till.get_balance())
+
+    def _get_value(self):
+        return self.entry.value
+    def _set_value(self, value):
+        self.entry.value = value
+    value = property(_get_value, _set_value)
+
 class TillOpeningEditor(BaseEditor):
     """
     An editor to open a till.
@@ -183,9 +196,9 @@
     Cash Amount: [        ]
     """
 
-    model_type = TillEntry
+    model_type = _BaseCashModel
     gladefile = 'BaseCashSlave'
-    proxy_widgets = ('cash_amount',)
+    proxy_widgets = ('value', 'balance')
 
     #
     # BaseEditorSlave
@@ -193,14 +206,34 @@
 
     def setup_proxies(self):
         self.proxy = self.add_proxy(self.model, BaseCashSlave.proxy_widgets)
-        self.date.set_text(datetime.now().strftime('%x'))
+        self.date.set_text(str(datetime.today().date()))
 
     def validate_confirm(self):
         if self.model.value <= 0:
-            self.cash_amount.set_invalid( _("Value Must be greater than zero"))
+            self.value.set_invalid( _("Value Must be greater than zero"))
             return False
+
+        zero = currency(0)
+        if self.model.get_balance() < zero:
+            self.value.set_invali(_("You can not specify an amount "
+                                    "removed greater than the "
+                                    "till balance."))
+            return False
+
         return True
 
+    #
+    # Kiwi handlers
+    #
+
+    def after_value__validate(self, widget, value):
+        zero = currency(0)
+        if value < zero:
+            self.proxy.update('balance', zero)
+            return ValidationError(_("Value cannot be less than zero"))
+
+    def after_value__content_changed(self, entry):
+        self.proxy.update('balance')
 
 class CashAdvanceEditor(BaseEditor):
     """
@@ -237,7 +270,7 @@
         return CashAdvanceInfo(payment=self.payment)
 
     def setup_slaves(self):
-        self.cash_slave = BaseCashSlave(self.conn, self.payment)
+        self.cash_slave = BaseCashSlave(self.conn, _BaseCashModel(self.payment))
         self.attach_slave("base_cash_holder", self.cash_slave)
         self._setup_widgets()
 
@@ -280,7 +313,9 @@
         return till.create_debit(currency(0))
 
     def setup_slaves(self):
-        self.cash_slave = BaseCashSlave(self.conn, self.model)
+        self.cash_slave = BaseCashSlave(
+            self.conn, _BaseCashModel(self.model))
+        self.cash_slave.value.connect('content-changed', self._on_cash_slave__value_changed)
         self.attach_slave("base_cash_holder", self.cash_slave)
 
     def validate_confirm(self):
@@ -296,10 +331,15 @@
             else:
                 payment_description = _(u'Cash out')
             self.model.description = payment_description
-            self.model.value = -self.model.value
 
         return valid
 
+    #
+    # BaseCashSlave
+    #
+
+    def _on_cash_slave__value_changed(self, entry):
+        self.cash_slave.model.value = -abs(self.cash_slave.model.value)
 
 class CashInEditor(BaseEditor):
     """
@@ -326,7 +366,8 @@
         return till.create_credit(currency(0), description)
 
     def setup_slaves(self):
-        self.cash_slave = BaseCashSlave(self.conn, self.model)
+        self.cash_slave = BaseCashSlave(self.conn,
+                                        _BaseCashModel(self.model))
         self.attach_slave("main_holder", self.cash_slave)
 
     def validate_confirm(self):


More information about the POS-commit mailing list