[POS-commit] r6461 - in stoqlib/trunk/stoqlib/domain: . examples test

fabio morbec fabio at async.com.br
Fri Apr 27 09:20:20 BRT 2007


Author: fabio
Date: Fri Apr 27 09:20:20 2007
New Revision: 6461

Modified:
   stoqlib/trunk/stoqlib/domain/exampledata.py
   stoqlib/trunk/stoqlib/domain/examples/purchase.py
   stoqlib/trunk/stoqlib/domain/receiving.py
   stoqlib/trunk/stoqlib/domain/test/test_receiving.py

Log:
Base de exemplos gerava informação errada, era comprado 5 produtos e recebidos 10.
Resolvido junto com o bug 3295. r=jdahlin



Modified: stoqlib/trunk/stoqlib/domain/exampledata.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/exampledata.py	(original)
+++ stoqlib/trunk/stoqlib/domain/exampledata.py	Fri Apr 27 09:20:20 2007
@@ -372,9 +372,10 @@
                               branch=self.create_branch(),
                               cfop=self.create_cfop_data())
 
-    def create_receiving_order_item(self):
+    def create_receiving_order_item(self, receiving_order=None):
         from stoqlib.domain.receiving import ReceivingOrderItem
-        receiving_order = self.create_receiving_order()
+        if receiving_order is None:
+            receiving_order = self.create_receiving_order()
         purchase_item = self.create_purchase_order_item()
         return ReceivingOrderItem(connection=self.trans,
                                   quantity=8, cost=125,

Modified: stoqlib/trunk/stoqlib/domain/examples/purchase.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/examples/purchase.py	(original)
+++ stoqlib/trunk/stoqlib/domain/examples/purchase.py	Fri Apr 27 09:20:20 2007
@@ -81,7 +81,6 @@
 
     for sellable in sellables:
         purchase_item = order.add_item(sellable, 5)
-        order.receive_item(purchase_item, 5)
 
         ReceivingOrderItem(connection=trans,
                            cost=sellable.cost / 2,

Modified: stoqlib/trunk/stoqlib/domain/receiving.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/receiving.py	(original)
+++ stoqlib/trunk/stoqlib/domain/receiving.py	Fri Apr 27 09:20:20 2007
@@ -35,6 +35,7 @@
 from stoqlib.database.columns import PriceCol, DecimalCol
 from stoqlib.domain.base import Domain
 from stoqlib.domain.interfaces import IStorable, IPaymentGroup
+from stoqlib.domain.product import ProductHistory
 from stoqlib.domain.purchase import PurchaseOrder
 from stoqlib.lib.defaults import quantize
 from stoqlib.lib.parameters import sysparam
@@ -123,22 +124,32 @@
         Domain._create(self, id, **kw)
 
     def confirm(self):
+        conn = self.get_connection()
         # Stock management
         for item in self.get_items():
             # FIXME: Don't use sellable.get_adapted() here
             storable = IStorable(item.sellable.get_adapted(), None)
-            quantity = item.quantity
+            if item.quantity > item.get_remaining_quantity():
+                raise ValueError(
+                    "Quantity received (%d) is greater than "
+                    "quantity ordered (%d)" % (
+                        item.quantity,
+                        item.get_remaining_quantity()))
             if storable is not None:
-                storable.increase_stock(quantity, self.branch)
-            if self.purchase:
-                self.purchase.increase_quantity_received(item.sellable,
-                                                         quantity)
+                storable.increase_stock(item.quantity, self.branch)
+                ProductHistory(connection=conn,
+                                quantity_received=item.quantity,
+                                branch=self.branch, sellable=item.sellable,
+                                description=item.sellable.get_description(),
+                                received_date=self.receival_date)
+            self.purchase.increase_quantity_received(item.sellable,
+                                                     item.quantity)
 
         group = IPaymentGroup(self.purchase)
         group.create_icmsipi_book_entry(self.cfop, self.invoice_number,
                                         self.icms_total, self.ipi_total)
 
-        if self.purchase and self.purchase.can_close():
+        if self.purchase.can_close():
             self.purchase.close()
 
     def get_items(self):
@@ -190,8 +201,6 @@
         return currency(total)
 
     def get_order_number(self):
-        if not self.purchase:
-            return _(u'No order set')
         return self.purchase.get_order_number_str()
 
     def get_receival_date_str(self):

Modified: stoqlib/trunk/stoqlib/domain/test/test_receiving.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/test/test_receiving.py	(original)
+++ stoqlib/trunk/stoqlib/domain/test/test_receiving.py	Fri Apr 27 09:20:20 2007
@@ -59,6 +59,15 @@
         order.surcharge_value = 15
         self.assertEqual(order.get_total(), currency(408))
 
+    def testConfirm(self):
+        order = self.create_receiving_order()
+        order.quantity = 8
+        order_item = self.create_receiving_order_item(order)
+        order_item.quantity_received = 10
+        self.assertRaises(ValueError, order.confirm)
+        order_item.quantity_received = 8
+        self.assertRaises(ValueError, order.confirm)
+        self.assertRaises(ValueError, order.confirm)
 
 class TestReceivingOrderItem(DomainTest):
 


More information about the POS-commit mailing list