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

george at async.com.br george at async.com.br
Thu Aug 2 17:30:49 BRT 2007


Author: george
Date: Thu Aug  2 17:30:48 2007
New Revision: 7072

Added:
   stoqlib/trunk/stoqlib/gui/slaves/categoryslave.py
   stoqlib/trunk/stoqlib/gui/slaves/serviceslave.py
Modified:
   stoqlib/trunk/stoqlib/gui/editors/categoryeditor.py
   stoqlib/trunk/stoqlib/gui/editors/producteditor.py
   stoqlib/trunk/stoqlib/gui/editors/serviceeditor.py
   stoqlib/trunk/stoqlib/gui/slaves/productslave.py
   stoqlib/trunk/stoqlib/gui/slaves/sellableslave.py

Log:
#3321: No cadastro de categorias e produtos em compras a taxa para
       serviços é mostrada. r=jdahlin


Modified: stoqlib/trunk/stoqlib/gui/editors/categoryeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/categoryeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/categoryeditor.py	Thu Aug  2 17:30:48 2007
@@ -26,6 +26,7 @@
 
 from stoqlib.lib.translation import stoqlib_gettext
 from stoqlib.gui.editors.baseeditor import BaseEditor
+from stoqlib.gui.slaves.categoryslave import CategoryTributarySituationSlave
 from stoqlib.gui.slaves.commissionslave import CategoryCommissionSlave
 
 from stoqlib.lib.parameters import sysparam
@@ -51,7 +52,6 @@
 
     def setup_combo(self):
         self.tax_constant.prefill(
-            [(_('(unset)'), None)] +
             [(c.description, c)
                   for c in SellableTaxConstant.select(connection=self.conn)])
 
@@ -100,6 +100,10 @@
         cat = self.category.get_selected_label()
         commission_slave.change_label('Calculate Commission From: %s' % cat)
 
+        tax_slave = CategoryTributarySituationSlave(self.conn,
+                                                    self.model)
+        self.attach_slave("on_tax_holder", tax_slave)
+
     def setup_proxies(self):
         # We need to prefill combobox before to set a proxy, since we want
         # the attribute 'group' be set properly in the combo.

Modified: stoqlib/trunk/stoqlib/gui/editors/producteditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/producteditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/producteditor.py	Thu Aug  2 17:30:48 2007
@@ -40,7 +40,7 @@
 from stoqlib.gui.base.lists import SimpleListDialog
 from stoqlib.gui.editors.baseeditor import BaseEditor, BaseEditorSlave
 from stoqlib.gui.editors.sellableeditor import SellableEditor
-from stoqlib.gui.slaves.productslave import TributarySituationSlave
+from stoqlib.gui.slaves.productslave import ProductTributarySituationSlave
 from stoqlib.lib.parameters import sysparam
 from stoqlib.lib.translation import stoqlib_gettext
 
@@ -214,11 +214,12 @@
 
     def setup_slaves(self):
         supplier_slave = ProductSupplierSlave(self.conn, self.model)
-        tax_slave = TributarySituationSlave(self.conn, ISellable(self.model))
         supplier_slave.connect("cost-changed",
                                self._on_supplier_slave__cost_changed)
         self.attach_slave('product_supplier_holder', supplier_slave)
         # XXX: tax_holder is a Brazil-specifc area
+        tax_slave = ProductTributarySituationSlave(self.conn,
+                                                   ISellable(self.model))
         self.attach_slave("tax_holder", tax_slave)
 
     def setup_widgets(self):

Modified: stoqlib/trunk/stoqlib/gui/editors/serviceeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/serviceeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/serviceeditor.py	Thu Aug  2 17:30:48 2007
@@ -34,6 +34,7 @@
 from stoqlib.lib.translation import stoqlib_gettext
 from stoqlib.gui.editors.baseeditor import BaseEditor
 from stoqlib.gui.editors.sellableeditor import SellableEditor
+from stoqlib.gui.slaves.serviceslave import ServiceTributarySituationSlave
 from stoqlib.domain.interfaces import ISellable
 from stoqlib.domain.service import Service
 from stoqlib.domain.sellable import (BaseSellableInfo,
@@ -81,6 +82,11 @@
     model_name = 'Service'
     model_type = Service
 
+    def setup_slaves(self):
+        tax_slave = ServiceTributarySituationSlave(self.conn,
+                                                   ISellable(self.model))
+        self.attach_slave("tax_holder", tax_slave)
+
     def setup_widgets(self):
         self.notes_lbl.set_text(_('Service details'))
         self.stock_total_lbl.hide()

Added: stoqlib/trunk/stoqlib/gui/slaves/categoryslave.py
==============================================================================
--- (empty file)
+++ stoqlib/trunk/stoqlib/gui/slaves/categoryslave.py	Thu Aug  2 17:30:48 2007
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+##
+## Copyright (C) 2007 Async Open Source <http://www.async.com.br>
+## All rights reserved
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU Lesser General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., or visit: http://www.gnu.org/.
+##
+## Author(s):   George Kussumoto    <george at async.com.br>
+##
+""" Slaves for categories """
+
+from stoqlib.domain.sellable import SellableCategory
+from stoqlib.gui.slaves.sellableslave import TributarySituationSlave
+from stoqlib.lib.translation import stoqlib_gettext
+
+_ = stoqlib_gettext
+
+class CategoryTributarySituationSlave(TributarySituationSlave):
+    model_type = SellableCategory
+
+    def setup_combos(self):
+        constant = self.model.get_tax_constant()
+        if constant:
+            tax = [(constant.description, constant)]
+        else:
+            tax = [(_('No tax'), None)]
+
+        self.tax_constant.prefill(tax)

Modified: stoqlib/trunk/stoqlib/gui/slaves/productslave.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/slaves/productslave.py	(original)
+++ stoqlib/trunk/stoqlib/gui/slaves/productslave.py	Thu Aug  2 17:30:48 2007
@@ -27,47 +27,14 @@
 
 from stoqdrivers.enum import TaxType
 
+from stoqlib.gui.slaves.sellableslave import TributarySituationSlave
 from stoqlib.domain.product import ProductAdaptToSellable
 from stoqlib.domain.sellable import SellableTaxConstant
-from stoqlib.gui.editors.baseeditor import BaseEditorSlave
 
-class TributarySituationSlave(BaseEditorSlave):
-    gladefile = "TributarySituationSlave"
-    proxy_widgets = ("tax_constant",
-                     "tax_value")
+class ProductTributarySituationSlave(TributarySituationSlave):
     model_type = ProductAdaptToSellable
 
-
-    def __init__(self, conn, model=None):
-        self.proxy = None
-        BaseEditorSlave.__init__(self, conn, model)
-
-    def _setup_combos(self):
+    def setup_combos(self):
         constants = SellableTaxConstant.select(connection=self.trans)
-        self.tax_constant.prefill([(c.description, c)  for c in constants])
-
-    def _update_percentage(self):
-        constant = self.tax_constant.get_selected_data()
-        self.model.tax_value = constant.tax_value
-        if self.proxy:
-            self.proxy.update('tax_value')
-
-        if constant.tax_type == TaxType.CUSTOM:
-            label = '%'
-        else:
-            label = ''
-
-        self.label_percent.set_label(label)
-
-    #
-    # BaseEditorSlave hooks
-    #
-
-    def setup_proxies(self):
-        self._setup_combos()
-        self.proxy = self.add_proxy(self.model,
-                                    TributarySituationSlave.proxy_widgets)
-        self._update_percentage()
-
-    def on_tax_constant__changed(self, combo):
-        self._update_percentage()
+        self.tax_constant.prefill([(c.description, c) for c in constants
+                                    if c.tax_type != TaxType.SERVICE])

Modified: stoqlib/trunk/stoqlib/gui/slaves/sellableslave.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/slaves/sellableslave.py	(original)
+++ stoqlib/trunk/stoqlib/gui/slaves/sellableslave.py	Thu Aug  2 17:30:48 2007
@@ -51,7 +51,7 @@
 
     def setup_proxies(self):
         self.proxy = self.add_proxy(self.model, self.proxy_widgets)
-  
+
     #
     # Kiwi callbacks
     #
@@ -59,3 +59,42 @@
     def on_on_sale_price__validate(self, entry, value):
         if value < 0:
            return ValidationError(_("Sale price can not be 0"))
+
+class TributarySituationSlave(BaseEditorSlave):
+    """
+    This is base slave for tributary taxes applied to product, service
+        and it's category if any.
+    """
+    gladefile = "TributarySituationSlave"
+    proxy_widgets = ("tax_constant", "tax_value")
+    model_type = None
+
+
+    def __init__(self, conn, model=None):
+        self.proxy = None
+        BaseEditorSlave.__init__(self, conn, model)
+
+    def setup_combos(self):
+        """
+        The child class must fill the combo
+        """
+
+    def _update_tax_value(self):
+        constant = self.tax_constant.get_selected_data()
+        if constant:
+            self.model.tax_value = constant.tax_value
+            if self.proxy:
+                self.proxy.update('tax_value')
+
+    #
+    # BaseEditorSlave hooks
+    #
+
+    def setup_proxies(self):
+        self.setup_combos()
+        self.proxy = self.add_proxy(self.model,
+                            TributarySituationSlave.proxy_widgets)
+        self._update_tax_value()
+
+    def on_tax_constant__changed(self, combo):
+        self._update_tax_value()

Added: stoqlib/trunk/stoqlib/gui/slaves/serviceslave.py
==============================================================================
--- (empty file)
+++ stoqlib/trunk/stoqlib/gui/slaves/serviceslave.py	Thu Aug  2 17:30:48 2007
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+##
+## Copyright (C) 2007 Async Open Source <http://www.async.com.br>
+## All rights reserved
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU Lesser General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., or visit: http://www.gnu.org/.
+##
+## Author(s):   George Kussumoto    <george at async.com.br>
+##
+""" Slaves for services """
+
+from stoqdrivers.enum import TaxType
+
+from stoqlib.gui.slaves.sellableslave import TributarySituationSlave
+from stoqlib.domain.sellable import SellableTaxConstant
+from stoqlib.domain.service import ServiceAdaptToSellable
+from stoqlib.lib.translation import stoqlib_gettext
+
+_ = stoqlib_gettext
+
+
+class ServiceTributarySituationSlave(TributarySituationSlave):
+    model_type = ServiceAdaptToSellable
+
+    def setup_combos(self):
+        service_tax = SellableTaxConstant.get_by_type(TaxType.SERVICE,
+                                                      self.conn)
+        taxes = [(_('No tax'), None),
+                 (service_tax.description, service_tax)]
+        self.tax_constant.prefill(taxes)


More information about the POS-commit mailing list