[POS-commit] r7451 - in stoqlib/trunk/stoqlib: domain domain/payment domain/test gui/slaves

george at async.com.br george at async.com.br
Fri Feb 22 16:59:48 BRT 2008


Author: george
Date: Fri Feb 22 16:59:48 2008
New Revision: 7451

Log:
#3168: Em uma venda a prestacao com cartao de credito, a data das
parcelas nao e atualizada. r=jdahlin


Modified:
   stoqlib/trunk/stoqlib/domain/exampledata.py
   stoqlib/trunk/stoqlib/domain/payment/methods.py
   stoqlib/trunk/stoqlib/domain/test/test_payment_method.py
   stoqlib/trunk/stoqlib/gui/slaves/paymentslave.py

Modified: stoqlib/trunk/stoqlib/domain/exampledata.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/exampledata.py	(original)
+++ stoqlib/trunk/stoqlib/domain/exampledata.py	Fri Feb 22 16:59:48 2008
@@ -443,6 +443,12 @@
                                     destination=None,
                                     connection=self.trans)
 
+    def create_card_installment_settings(self, payment_day=15, closing_day=15):
+        from stoqlib.domain.payment.methods import CardInstallmentSettings
+        return CardInstallmentSettings(payment_day=payment_day,
+                                        closing_day=closing_day,
+                                        connection=self.trans)
+
     def create_payment(self):
         from stoqlib.domain.payment.payment import Payment
         return Payment(group=None,

Modified: stoqlib/trunk/stoqlib/domain/payment/methods.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/payment/methods.py	(original)
+++ stoqlib/trunk/stoqlib/domain/payment/methods.py	Fri Feb 22 16:59:48 2008
@@ -122,7 +122,7 @@
 
     def calculate_payment_duedate(self, first_duedate):
         if first_duedate.day > self.closing_day:
-            first_duedate += relativedelta(month=+1)
+            first_duedate += relativedelta(months=+1)
         return first_duedate.replace(day=self.payment_day)
 
 

Modified: stoqlib/trunk/stoqlib/domain/test/test_payment_method.py
==============================================================================
--- stoqlib/trunk/stoqlib/domain/test/test_payment_method.py	(original)
+++ stoqlib/trunk/stoqlib/domain/test/test_payment_method.py	Fri Feb 22 16:59:48 2008
@@ -314,3 +314,24 @@
         method_details = PaymentMethodDetails.get_active_method_details(
             provider=provider, conn=self.trans)
         self.failIf(method_details)
+
+
+class TestCardInstallmentSettings(DomainTest):
+
+        def testCalculatePaymentDueDate(self):
+            # default settings: payment_day = closing_day = 15
+            settings = self.create_card_installment_settings()
+            today = datetime.datetime.today()
+            # Reset day and month here, so we can avoid the bound cases
+            # of 'today' attributes
+            start_due_dates = [today.replace(day=14, month=3),
+                               today.replace(day=15, month=3),
+                               today.replace(day=16, month=3)]
+            for date in start_due_dates:
+                due_date = settings.calculate_payment_duedate(date)
+                if date.day > settings.closing_day:
+                    self.assertEqual(due_date.day, settings.payment_day)
+                    self.assertEqual(due_date.month, date.month + 1)
+                else:
+                    self.assertEqual(due_date.day, settings.payment_day)
+                    self.assertEqual(due_date.month, date.month)

Modified: stoqlib/trunk/stoqlib/gui/slaves/paymentslave.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/slaves/paymentslave.py	(original)
+++ stoqlib/trunk/stoqlib/gui/slaves/paymentslave.py	Fri Feb 22 16:59:48 2008
@@ -28,6 +28,7 @@
 
 from decimal import Decimal
 import datetime
+from dateutil.relativedelta import relativedelta
 
 from kiwi.datatypes import format_price, currency, ValidationError
 from kiwi.utils import gsignal
@@ -761,10 +762,16 @@
         self._setup_payment_types()
 
     def _setup_payments(self):
-        # FIXME: This is broken, should create multiple methods
-        self.method.create_inpayment(self.wizard.payment_group,
-                                     self.total_value,
-                                     self.sale.open_date)
+        payment_type = self.model.payment_type
+        due_dates = []
+        start_due_date = datetime.datetime.today()
+        for i in range(self.model.installments_number):
+            due_dates.append(payment_type.calculate_payment_duedate(
+                start_due_date))
+            start_due_date += relativedelta(months=+1)
+
+        self.method.create_inpayments(self.wizard.payment_group,
+                                      self.total_value, due_dates)
 
     #
     # PaymentMethodStep hooks


More information about the POS-commit mailing list