[POS-commit] r6291 - in stoqlib/trunk: data/glade stoqlib/gui/slaves

fabio morbec fabio at async.com.br
Tue Apr 3 13:08:24 BRT 2007


Author: fabio
Date: Tue Apr  3 13:08:24 2007
New Revision: 6291

Modified:
   stoqlib/trunk/data/glade/InstallmentConfirmation.glade
   stoqlib/trunk/stoqlib/gui/slaves/installmentslave.py

Log:
#3051: Implementar opção de baixa para pagamentos (parte - Stoqlib). r=jdahlin



Modified: stoqlib/trunk/data/glade/InstallmentConfirmation.glade
==============================================================================
--- stoqlib/trunk/data/glade/InstallmentConfirmation.glade	(original)
+++ stoqlib/trunk/data/glade/InstallmentConfirmation.glade	Tue Apr  3 13:08:24 2007
@@ -17,7 +17,7 @@
                             <widget class="GtkTable" id="table1">
                                 <property name="column_spacing">6</property>
                                 <property name="n_columns">2</property>
-                                <property name="n_rows">5</property>
+                                <property name="n_rows">7</property>
                                 <property name="row_spacing">6</property>
                                 <property name="visible">True</property>
                                 <child>
@@ -61,14 +61,24 @@
                                     </packing>
                                 </child>
                                 <child>
+                                    <widget class="GtkLabel" id="discount_label">
+                                        <property name="label" context="yes" translatable="yes">Discount:</property>
+                                        <property name="xalign">1.0</property>
+                                    </widget>
+                                    <packing>
+                                        <property name="bottom_attach">6</property>
+                                        <property name="top_attach">4</property>
+                                    </packing>
+                                </child>
+                                <child>
                                     <widget class="GtkLabel" id="label1">
                                         <property name="label" context="yes" translatable="yes">Total value:</property>
                                         <property name="visible">True</property>
                                         <property name="xalign">1.0</property>
                                     </widget>
                                     <packing>
-                                        <property name="bottom_attach">5</property>
-                                        <property name="top_attach">4</property>
+                                        <property name="bottom_attach">7</property>
+                                        <property name="top_attach">6</property>
                                     </packing>
                                 </child>
                                 <child>
@@ -130,6 +140,20 @@
                                     </packing>
                                 </child>
                                 <child>
+                                    <widget class="ProxyEntry" id="discount">
+                                        <property name="data_type">currency</property>
+                                        <property name="model_attribute">discount</property>
+                                        <property name="xalign">1.0</property>
+                                    </widget>
+                                    <packing>
+                                        <property name="bottom_attach">6</property>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">4</property>
+                                        <property name="x_options"></property>
+                                    </packing>
+                                </child>
+                                <child>
                                     <widget class="ProxyLabel" id="total_value">
                                         <property name="data_type">currency</property>
                                         <property name="model_attribute">total_value</property>
@@ -137,10 +161,10 @@
                                         <property name="xalign">1.0</property>
                                     </widget>
                                     <packing>
-                                        <property name="bottom_attach">5</property>
+                                        <property name="bottom_attach">7</property>
                                         <property name="left_attach">1</property>
                                         <property name="right_attach">2</property>
-                                        <property name="top_attach">4</property>
+                                        <property name="top_attach">6</property>
                                         <property name="x_padding">2</property>
                                     </packing>
                                 </child>
@@ -157,7 +181,7 @@
                                         <property name="row_spacing">6</property>
                                         <property name="visible">True</property>
                                         <child>
-                                            <widget class="GtkLabel" id="label7">
+                                            <widget class="GtkLabel" id="person_label">
                                                 <property name="label" context="yes" translatable="yes">Client:</property>
                                                 <property name="visible">True</property>
                                                 <property name="xalign">1.0</property>
@@ -167,9 +191,9 @@
                                             </packing>
                                         </child>
                                         <child>
-                                            <widget class="ProxyLabel" id="client_name">
+                                            <widget class="ProxyLabel" id="person_name">
                                                 <property name="data_type">unicode</property>
-                                                <property name="model_attribute">client_name</property>
+                                                <property name="model_attribute">person_name</property>
                                                 <property name="visible">True</property>
                                                 <property name="width_chars">24</property>
                                                 <property name="xalign">0.0</property>
@@ -187,12 +211,14 @@
                                     </packing>
                                 </child>
                                 <child>
-                                    <widget class="GtkExpander" id="expander1">
+                                    <widget class="GtkExpander" id="expander">
                                         <property name="is_focus">True</property>
                                         <property name="label" context="yes" translatable="yes"></property>
                                         <property name="visible">True</property>
                                         <child>
                                             <widget class="GtkVBox" id="vbox3">
+                                                <property name="border_width">6</property>
+                                                <property name="spacing">6</property>
                                                 <property name="visible">True</property>
                                                 <child>
                                                     <widget class="ProxyCheckButton" id="pay_penalty">
@@ -219,6 +245,8 @@
                                         </child>
                                     </widget>
                                     <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
                                         <property name="position">1</property>
                                     </packing>
                                 </child>

Modified: stoqlib/trunk/stoqlib/gui/slaves/installmentslave.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/slaves/installmentslave.py	(original)
+++ stoqlib/trunk/stoqlib/gui/slaves/installmentslave.py	Tue Apr  3 13:08:24 2007
@@ -20,14 +20,16 @@
 ## Foundation, Inc., or visit: http://www.gnu.org/.
 ##
 ## Author(s):   Johan Dahlin      <jdahlin at async.com.br>
+##              Fabio Morbec      <fabio at async.com.br>
 ##
 ##
 """ Installment confirmation slave """
 
 import datetime
 
-from kiwi.datatypes import currency
+from kiwi.datatypes import currency, ValidationError
 from kiwi.ui.objectlist import Column
+from kiwi import ValueUnset
 
 from stoqlib.gui.editors.baseeditor import BaseEditor
 from stoqlib.lib.translation import stoqlib_gettext
@@ -43,6 +45,9 @@
     def get_installment_value(self):
         return currency(sum(p.value for p in self.payments))
 
+    def get_discount(self):
+        return currency(0)
+
     def get_interest(self):
         if not self.pay_interest:
             return currency(0)
@@ -74,10 +79,22 @@
     def get_order_number(self):
         return self._sale.id
 
-    def get_client_name(self):
+    def get_person_name(self):
         if self._sale.client:
             return self._sale.client.person.name
 
+class _PurchaseConfirmationModel(_ConfirmationModel):
+    def __init__(self, payments, purchase):
+        _ConfirmationModel.__init__(self, payments)
+        self._purchase = purchase
+
+    def get_order_number(self):
+        return self._purchase.id
+
+    def get_person_name(self):
+        if self._purchase.supplier:
+            return self._purchase.supplier.person.name
+
 class _InstallmentConfirmationSlave(BaseEditor):
     """
     This slave is responsible for confirming a list of payments and
@@ -102,8 +119,9 @@
                      'installment_value',
                      'interest',
                      'penalty',
+                     'discount',
                      'total_value',
-                     'client_name',
+                     'person_name',
                      'pay_penalty',
                      'pay_interest')
 
@@ -154,3 +172,34 @@
 class SaleInstallmentConfirmationSlave(_InstallmentConfirmationSlave):
     model_type = _SaleConfirmationModel
 
+class PurchaseInstallmentConfirmationSlave(_InstallmentConfirmationSlave):
+    model_type = _PurchaseConfirmationModel
+
+    def _setup_widgets(self):
+        _InstallmentConfirmationSlave._setup_widgets(self)
+        self.discount_label.show()
+        self.discount.show()
+        self.person_label.set_text(_("Supplier: "))
+        self.expander.set_expanded(True)
+
+    def after_discount__content_changed(self, proxy_entry):
+        try:
+            value = proxy_entry.read()
+        except ValidationError:
+            value = ValueUnset
+        installments_number = len(self._payments)
+        for payment in self._payments:
+            if value == ValueUnset:
+                payment.value = payment.base_value
+            else:
+                payment.value = payment.base_value - (value/installments_number)
+            self.installments.update(payment)
+        self._proxy.update('total_value')
+
+    def on_discount__validate(self, entry, value):
+        if value >= self._payments[0].base_value:
+            return ValidationError(_("Discount can not be greater than value"))
+
+    def create_model(self, conn):
+        return _PurchaseConfirmationModel(self._payments,
+                                          self._payments[0].group.get_adapted())


More information about the POS-commit mailing list