Commit 66ddb107 authored by Jérome Perrin's avatar Jérome Perrin

accounting: suggest date based on trade conditions in create related payment

This introduce a new utility script Invoice_getDueDate
parent 8d752a68
from DateTime import DateTime
source = False
if context.getPortalType() in ('Purchase Invoice', 'Purchase Invoice Transaction',):
source = False
elif context.getPortalType() in ('Sale Invoice', 'Sale Invoice Transaction',):
source = True
else: # internal invoices
source = context.AccountingTransaction_isSourceView()
delivery = context
payment_condition = context.getSpecialiseValue().getDefaultPaymentConditionValue()
# Absolute payment date has priority
if payment_condition.getPaymentDate():
return payment_condition.getPaymentDate()
def OrderDateGetter(invoice):
def getter():
packing_list = invoice.getCausalityValue(
portal_type=context.getPortalDeliveryTypeList())
if packing_list:
order = packing_list.getCausalityValue(
portal_type=context.getPortalOrderTypeList())
return order.getStartDate() if source else order.getStopDate()
return getter
def PackingListDateGetter(invoice):
def getter():
packing_list = invoice.getCausalityValue(
portal_type=context.getPortalDeliveryTypeList())
if packing_list:
return packing_list.getStartDate() if source else packing_list.getStopDate()
return getter
case = {
'invoice': delivery.getStartDate if source else delivery.getStopDate,
'order': OrderDateGetter(delivery),
'packing list': PackingListDateGetter(delivery),
}
due_date = case.get(payment_condition.getTradeDate(), delivery.getStartDate)()
if not due_date:
return None
due_date += payment_condition.getPaymentTerm(0)
pat = payment_condition.getPaymentAdditionalTerm()
if payment_condition.getPaymentEndOfMonth():
i = 0
month = due_date.month()
while (month == (due_date + i).month()):
i += 1
due_date = (due_date + i - 1)
if pat:
due_date += pat
else:
if pat:
i = 0
month = due_date.month()
while (month == (due_date + i).month()):
i -= 1
due_date = (due_date + i + pat)
return due_date
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Invoice_getDueDate</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -9,7 +9,9 @@
<item>
<key> <string>delegated_list</string> </key>
<value>
<list/>
<list>
<string>default</string>
</list>
</value>
</item>
<item>
......@@ -50,6 +52,12 @@
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
......@@ -69,6 +77,12 @@
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>your_date</string> </value>
......@@ -87,4 +101,17 @@
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>context/Invoice_getDueDate</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment