[POS-commit] r8142 - in stoqlib/trunk: data/glade stoqlib/domain stoqlib/domain/test stoqlib/gui/dialogs stoqlib/reporting

george at async.com.br george at async.com.br
Fri Jul 3 16:10:58 BRT 2009


Author: george
Date: Fri Jul  3 16:10:58 2009
New Revision: 8142

Log:
#3093: Qualquer aplicacao que possui a opcao de cadastro de notas nao
retorna estes textos. (stoqlib) r=romaia

Modified:
   stoqlib/trunk/data/glade/DeliveryEditor.glade
   stoqlib/trunk/stoqlib/domain/sale.py
   stoqlib/trunk/stoqlib/domain/test/test_sale.py
   stoqlib/trunk/stoqlib/gui/dialogs/saledetails.py
   stoqlib/trunk/stoqlib/reporting/sale.py

Modified: stoqlib/trunk/data/glade/DeliveryEditor.glade
==============================================================================
--- stoqlib/trunk/data/glade/DeliveryEditor.glade	Fri Jul  3 15:26:27 2009	(r8141)
+++ stoqlib/trunk/data/glade/DeliveryEditor.glade	Fri Jul  3 16:10:58 2009	(r8142)
@@ -66,7 +66,7 @@
                         <child>
                             <widget class="GtkLabel" id="label1">
                                 <property name="label" context="yes" translatable="yes">Estimated Delivery _Date:</property>
-                                <property name="mnemonic_widget">delivery_date</property>
+                                <property name="mnemonic_widget">estimated_fix_date</property>
                                 <property name="sizegroup">sizegroup1</property>
                                 <property name="use_underline">True</property>
                                 <property name="visible">True</property>
@@ -77,7 +77,7 @@
                             </packing>
                         </child>
                         <child>
-                            <widget class="ProxyDateEntry" id="delivery_date">
+                            <widget class="ProxyDateEntry" id="estimated_fix_date">
                                 <property name="data_type">date</property>
                                 <property name="model_attribute">estimated_fix_date</property>
                                 <property name="visible">True</property>

Modified: stoqlib/trunk/stoqlib/domain/sale.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/sale.py	Fri Jul  3 15:26:27 2009	(r8141)
+++ stoqlib/trunk/stoqlib/domain/sale.py	Fri Jul  3 16:10:58 2009	(r8142)
@@ -2,7 +2,7 @@
 # vi:si:et:sw=4:sts=4:ts=4
 
 ##
-## Copyright (C) 2005-2008 Async Open Source <http://www.async.com.br>
+## Copyright (C) 2005-2009 Async Open Source <http://www.async.com.br>
 ## All rights reserved
 ##
 ## This program is free software; you can redistribute it and/or modify
@@ -149,6 +149,11 @@
     def get_description(self):
         return self.sellable.base_sellable_info.get_description()
 
+    def is_service(self):
+        service = Service.selectOneBy(sellable=self.sellable,
+                                      connection=self.get_connection())
+        return service is not None
+
 
 class DeliveryItem(Domain):
     """Class responsible to store all the products for a certain delivery"""
@@ -203,7 +208,6 @@
     def remove_item(self, item):
         DeliveryItem.delete(item.id, connection=item.get_connection())
 
-
     #
     # General methods
     #
@@ -535,16 +539,33 @@
         """
         return self.get_items().sum('quantity') or Decimal(0)
 
-    def get_delivery_item(self):
-        """Returns the delivery item of the sale, if any.
-
-        @returns: The sale item that represents the delivery or None if there
-                  is no delivery service in the sale.
-        """
-        conn = self.get_connection()
-        delivery_service = sysparam(conn).DELIVERY_SERVICE
-        return SaleItem.selectOneBy(sellable=delivery_service, sale=self,
-                                    connection=conn)
+    def get_details_str(self):
+        """Returns the sale details. The details are composed by the sale
+        notes, the items notes, the delivery address and the estimated fix
+        date.
+        @returns: the sale details string.
+        """
+        details = []
+        if self.notes:
+            self.details.append(_(u'Sale Details: %s') % self.notes)
+        delivery_added = False
+        for sale_item in self.get_items():
+            if delivery_added is False:
+                delivery = IDelivery(sale_item, None)
+            if delivery is not None:
+                details.append(_(u'Delivery Address: %s' % delivery.address))
+                # At the moment, we just support only one delivery per sale.
+                delivery_added = True
+                delivery = None
+            else:
+                if sale_item.notes:
+                    details.append(_(u'"%s" Notes: %s' % (
+                        sale_item.get_description(), sale_item.notes)))
+            if sale_item.is_service() and sale_item.estimated_fix_date:
+                details.append(_(u'"%s" Estimated Fix Date: %s') % (
+                                 sale_item.get_description(),
+                                 sale_item.estimated_fix_date.strftime('%x')))
+        return u'\n'.join(details)
 
     def get_order_number_str(self):
         return u'%05d' % self.id

Modified: stoqlib/trunk/stoqlib/domain/test/test_sale.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/test/test_sale.py	Fri Jul  3 15:26:27 2009	(r8141)
+++ stoqlib/trunk/stoqlib/domain/test/test_sale.py	Fri Jul  3 16:10:58 2009	(r8142)
@@ -2,7 +2,7 @@
 # vi:si:et:sw=4:sts=4:ts=4
 
 ##
-## Copyright (C) 2006-2008 Async Open Source <http://www.async.com.br>
+## Copyright (C) 2006-2009 Async Open Source <http://www.async.com.br>
 ## All rights reserved
 ##
 ## This program is free software; you can redistribute it and/or modify
@@ -21,6 +21,7 @@
 ##
 ## Author(s):     Lincoln Molica <lincoln at async.com.br>
 ##                Johan Dahlin <jdahlin at async.com.br>
+##                George Kussumoto <george at async.com.br>
 ##
 
 import datetime
@@ -31,8 +32,7 @@
 from stoqlib.database.orm import AND
 from stoqlib.domain.commission import CommissionSource, Commission
 from stoqlib.domain.fiscal import CfopData, FiscalBookEntry
-from stoqlib.domain.interfaces import (IStorable,
-                                       IOutPayment)
+from stoqlib.domain.interfaces import IStorable, IOutPayment
 from stoqlib.domain.payment.group import PaymentGroup
 from stoqlib.domain.payment.method import PaymentMethod
 from stoqlib.domain.payment.payment import Payment, PaymentAdaptToOutPayment
@@ -604,26 +604,6 @@
         self.add_payments(sale)
         sale.confirm()
 
-    def testGetDeliveryItem(self):
-        # Without delivery
-        sale = self.create_sale()
-        self.failIf(sale.can_set_paid())
-
-        self.add_product(sale)
-        delivery = sale.get_delivery_item()
-        self.failUnless(delivery is None)
-
-        # With delivery
-        sale = self.create_sale()
-        self.failIf(sale.can_set_paid())
-
-        self.add_product(sale)
-        sellable = sysparam(self.trans).DELIVERY_SERVICE
-        sale.add_sellable(sellable, quantity=1)
-        delivery = sale.get_delivery_item()
-        self.failIf(delivery is None)
-        self.failIf(delivery.sellable is not sellable)
-
     def testCommissionAmount(self):
         sale = self.create_sale()
         sellable = self.add_product(sale, price=200)
@@ -742,3 +722,13 @@
         product = self.create_product()
         sale_item = sale.add_sellable(product.sellable)
         self.assertEqual(sale_item.get_description(), 'Description')
+
+    def testIsService(self):
+        sale = self.create_sale()
+        product = self.create_product(price=10)
+        sale_item = sale.add_sellable(product.sellable, quantity=5)
+        self.failIf(sale_item.is_service() is True)
+
+        service = self.create_service()
+        sale_item = sale.add_sellable(service.sellable, quantity=2)
+        self.failIf(sale_item.is_service() is False)

Modified: stoqlib/trunk/stoqlib/gui/dialogs/saledetails.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/dialogs/saledetails.py	Fri Jul  3 15:26:27 2009	(r8141)
+++ stoqlib/trunk/stoqlib/gui/dialogs/saledetails.py	Fri Jul  3 16:10:58 2009	(r8142)
@@ -31,7 +31,7 @@
 import pango
 import gtk
 from kiwi.datatypes import currency
-from kiwi.ui.widgets.list import Column, SummaryLabel, ColoredColumn
+from kiwi.ui.widgets.list import Column, ColoredColumn
 
 from stoqlib.exceptions import StoqlibError
 from stoqlib.lib.translation import stoqlib_gettext
@@ -127,10 +127,8 @@
         sale_items = self.sale_order.get_items()
         self.items_list.add_list(sale_items)
 
-        notes = [self.sale_order.notes]
-        notes.extend([s.notes for s in sale_items if s.notes])
         buffer = gtk.TextBuffer()
-        buffer.set_text(u'\n'.join(notes))
+        buffer.set_text(self.sale_order.get_details_str())
         self.notes.set_buffer(buffer)
 
         self.payments_list.add_list(self._get_payments(self.sale_order))

Modified: stoqlib/trunk/stoqlib/reporting/sale.py
==============================================================================
--- stoqlib/trunk/stoqlib/reporting/sale.py	Fri Jul  3 15:26:27 2009	(r8141)
+++ stoqlib/trunk/stoqlib/reporting/sale.py	Fri Jul  3 16:10:58 2009	(r8142)
@@ -30,7 +30,6 @@
 from stoqlib.database.runtime import get_connection, get_current_branch
 from stoqlib.domain.commission import CommissionView
 from stoqlib.domain.sale import SaleView
-from stoqlib.domain.interfaces import IDelivery
 from stoqlib.reporting.base.default_style import TABLE_LINE_BLANK
 from stoqlib.reporting.base.tables import (ObjectTableColumn as OTC,
                                            TableColumn as TC, HIGHLIGHT_NEVER)
@@ -116,27 +115,11 @@
         self._add_sale_notes()
 
     def _add_sale_notes(self):
-        delivery = self.sale.get_delivery_item()
-        delivery_notes = ''
-        if delivery is not None:
-            delivery_notes = delivery.notes
-
-        if delivery_notes:
-            self.add_paragraph(_(u'Additional Instructions:'), style='Normal-Bold')
-            self.add_preformatted_text(delivery_notes, style='Normal-Notes')
-
-        delivery_address = ''
-        for sale_item in self.sale.get_items():
-            delivery_item = IDelivery(sale_item, None)
-            if delivery_item is not None:
-                # At the moment, the delivery items should be delivered at only
-                # one address, so we take the first address that we find.
-                delivery_address = delivery_item.address
-                break
-
-        if delivery_address:
-            self.add_paragraph(_(u'Delivery Address:'), style='Normal-Bold')
-            self.add_preformatted_text(delivery_address, style='Normal-Notes')
+        details_str = self.sale.get_details_str()
+
+        if details_str:
+            self.add_paragraph(_(u'Additional Information'), style='Normal-Bold')
+            self.add_preformatted_text(details_str, style='Normal-Notes')
 
     #
     # BaseReportTemplate hooks


More information about the POS-commit mailing list