From 57707b0275409fb782bbbf9c9345c907e07c553d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Thu, 17 Jan 2008 16:00:21 +0000
Subject: [PATCH] Fix a bit TradeCondition_getDueDate (don't consider it's
 working though)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18776 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5_trade/TradeCondition_getDueDate.xml  | 70 ++++++++++++-------
 bt5/erp5_trade/bt/revision                    |  2 +-
 2 files changed, 45 insertions(+), 27 deletions(-)

diff --git a/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/TradeCondition_getDueDate.xml b/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/TradeCondition_getDueDate.xml
index 50744e603c..aac876acc2 100644
--- a/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/TradeCondition_getDueDate.xml
+++ b/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/TradeCondition_getDueDate.xml
@@ -67,42 +67,60 @@
             <key> <string>_body</string> </key>
             <value> <string encoding="cdata"><![CDATA[
 
-# TODO: this script is not well tested and not fully implemented (look at the case dict) \n
+# TODO: this script is not well tested and not fully implemented\n
 \n
 from DateTime import DateTime\n
-LOG = lambda msg:context.log("TradeCondition_getDueDate", msg)\n
-LOG = lambda msg:None\n
+\n
+if context.getPortalType() == \'Payment Condition\':\n
+  delivery = context.getParentValue()\n
+  payment_condition = context\n
+else:\n
+  delivery = context\n
+  payment_condition = context.getDefaultPaymentConditionValue()\n
+\n
+# Absolute payment date has priority\n
+if payment_condition.getPaymentDate():\n
+  return payment_condition.getPaymentDate()\n
+\n
+def OrderDateGetter(invoice):\n
+  def getter():\n
+    packing_list = invoice.getCausalityValue(\n
+                     portal_type=context.getPortalDeliveryTypeList())\n
+    if packing_list:\n
+      order = packing_list.getCausalityValue(\n
+                     portal_type=context.getPortalOrderTypeList())\n
+      return order.getStartDate() # TODO start or stop ? -> based on source/destination\n
+  return getter\n
+\n
+def PackingListDateGetter(invoice):\n
+  def getter():\n
+    packing_list = invoice.getCausalityValue(\n
+                     portal_type=context.getPortalDeliveryTypeList())\n
+    if packing_list:\n
+      return packing_list.getStartDate() # TODO start or stop ? -> based on source/destination\n
+  return getter\n
 \n
 case = {\n
-  None:           context.getStartDate,\n
-  \'invoice\':      context.getStartDate,\n
-  \'order\':        context.getStartDate,   #order.getStartDate,\n
-  \'packing list\': context.getStartDate,   #packing_list.getTargetStopDate,\n
+  \'invoice\':      delivery.getStartDate,\n
+  \'order\':        OrderDateGetter(delivery),\n
+  \'packing list\': PackingListDateGetter(delivery),\n
 }\n
-LOG("context.getTradeDateId() => %s "%context.getPaymentConditionTradeDate())\n
-due_date = case.get(context.getPaymentConditionTradeDate(), context.getStartDate)()\n
-due_date += context.getPaymentConditionPaymentTerm(0)\n
 \n
-peom = context.getPaymentConditionPaymentEndOfMonth()\n
-LOG("poem : %s"%peom)\n
-pt = context.getPaymentConditionPaymentTerm()\n
-LOG("pt : %s"%pt)\n
-pat = context.getPaymentConditionPaymentAdditionalTerm()\n
-LOG("pat : %s"%pat)\n
+due_date = case.get(payment_condition.getTradeDate(), delivery.getStartDate)()\n
+due_date += payment_condition.getPaymentTerm(0)\n
+\n
+pat = payment_condition.getPaymentAdditionalTerm()\n
 \n
-if peom:\n
+if payment_condition.getPaymentEndOfMonth():\n
   i = 0\n
   month = due_date.month()\n
   while (month == (due_date + i).month()):\n
     i += 1\n
   due_date = (due_date + i - 1)\n
-  if pt != None:\n
-    due_date += pt\n
-  if pat != None:\n
+  if pat:\n
     due_date += pat\n
 else:\n
-  ##TODO: test this part\n
-  if pat not in [None,\'\',0]:\n
+  if pat:\n
     i = 0\n
     month = due_date.month()\n
     while (month == (due_date + i).month()):\n
@@ -161,15 +179,15 @@ return due_date\n
                         <value>
                           <tuple>
                             <string>DateTime</string>
-                            <string>LOG</string>
-                            <string>None</string>
                             <string>_getattr_</string>
                             <string>context</string>
+                            <string>delivery</string>
+                            <string>payment_condition</string>
+                            <string>OrderDateGetter</string>
+                            <string>PackingListDateGetter</string>
                             <string>case</string>
                             <string>due_date</string>
                             <string>_inplacevar_</string>
-                            <string>peom</string>
-                            <string>pt</string>
                             <string>pat</string>
                             <string>i</string>
                             <string>month</string>
diff --git a/bt5/erp5_trade/bt/revision b/bt5/erp5_trade/bt/revision
index b912dc118c..34bba940d1 100644
--- a/bt5/erp5_trade/bt/revision
+++ b/bt5/erp5_trade/bt/revision
@@ -1 +1 @@
-155
\ No newline at end of file
+156
\ No newline at end of file
-- 
2.30.9