[POS-commit] r6359 - in stoqlib/trunk/stoqlib: gui/slaves lib

fabio morbec fabio at async.com.br
Tue Apr 10 16:29:25 BRT 2007


Author: fabio
Date: Tue Apr 10 16:29:24 2007
New Revision: 6359

Modified:
   stoqlib/trunk/stoqlib/gui/slaves/saleslave.py
   stoqlib/trunk/stoqlib/lib/parameters.py

Log:
#3223: O desconto não pode ser maior ou igual a 100%. r=jdahlin

Modified: stoqlib/trunk/stoqlib/gui/slaves/saleslave.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/slaves/saleslave.py	(original)
+++ stoqlib/trunk/stoqlib/gui/slaves/saleslave.py	Tue Apr 10 16:29:24 2007
@@ -37,6 +37,7 @@
 from stoqlib.domain.sale import SaleView, Sale
 from stoqlib.domain.renegotiation import AbstractRenegotiationAdapter
 from stoqlib.lib.validators import get_price_format_str
+from stoqlib.lib.parameters import sysparam
 from stoqlib.lib.translation import stoqlib_gettext
 from stoqlib.database.database import finish_transaction
 from stoqlib.exceptions import StoqlibError
@@ -57,6 +58,7 @@
 
     def __init__(self, conn, model, model_type, visual_mode=False):
         self.model_type = model_type
+        self.max_discount = sysparam(conn).MAX_SALE_DISCOUNT
         BaseEditorSlave.__init__(self, conn, model, visual_mode=visual_mode)
 
     def setup_widgets(self):
@@ -87,10 +89,10 @@
         self.emit('discount-changed')
 
     def _validate_percentage(self, value, type_text):
-        if value > 100:
+        if value > self.max_discount:
             self.model.discount_percentage = 0
-            return ValidationError(_("%s can not be greater then 100")
-                                     % type_text)
+            return ValidationError(_("%s can not be greater then %d%%")
+                                     % (type_text, self.max_discount))
         if value < 0:
             self.model.discount_percentage = 0
             return ValidationError(_("%s can not be less then 0")
@@ -121,14 +123,16 @@
 
     @signal_block('discount_perc.changed')
     def after_discount_value__changed(self, *args):
-        if self.model.discount_percentage > 100:
-            msg = _("Discount can not be greater then 100 percent")
+        percentage = self.model.discount_percentage
+        if percentage > self.max_discount:
+            msg = _("Discount can not be greater then %d%%" \
+                    % self.max_discount)
             self.discount_value.set_invalid(msg)
             self.model.discount_percentage = 0
         elif self.model.discount_percentage < 0:
-           msg = _("Discount can not be negative")
-           self.discount_value.set_invalid(msg)
-           self.model.discount_percentage = 0
+            msg = _("Discount can not be negative")
+            self.discount_value.set_invalid(msg)
+            self.model.discount_percentage = 0
 
         self.setup_discount_surcharge()
 

Modified: stoqlib/trunk/stoqlib/lib/parameters.py
==============================================================================
--- stoqlib/trunk/stoqlib/lib/parameters.py	(original)
+++ stoqlib/trunk/stoqlib/lib/parameters.py	Tue Apr 10 16:29:24 2007
@@ -209,6 +209,11 @@
     _(u'Max sale order validity'),
     _(u'The max number of days that a sale order is valid')),
 
+    MAX_SALE_DISCOUNT=ParameterDetails(
+    _(u'Sales'),
+    _(u'Max discount for sales'),
+    _(u'The max discount for salesperson in a sale')),
+
     # XXX: USE_SCALES_PRICE
     USE_SCALE_PRICE=ParameterDetails(
     _(u'Sales'),
@@ -319,6 +324,7 @@
                       initial=True),
         ParameterAttr('ASK_SALES_CFOP', bool, initial=False),
         ParameterAttr('MAX_SALE_ORDER_VALIDITY', int, initial=30),
+        ParameterAttr('MAX_SALE_DISCOUNT', int, initial=5),
         ParameterAttr('USE_SCALE_PRICE', bool, initial=False),
         ParameterAttr('ICMS_TAX', int, initial=18),
         ParameterAttr('ISS_TAX', int, initial=18),


More information about the POS-commit mailing list