Commit c1baaf12 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Include script to automatic cancel Payments payed by other channels

   If Sale Invoice Transaction is already Grouped (Lettered), Cancel the related payment.
parent ca8b5eea
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_cancelStartedPaymentTransactionPaid</string> </value>
</item>
<item>
<key> <string>automatic_solve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_cancel_sale_invoice_transaction_paied_payment_list</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_hour_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>2</int> </value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_day</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1288051200.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>periodicity_week</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>sense_method_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Handles cancellation Payment Transactions when Invoice is Paied</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
kw = {}
if params is None:
params = {}
from DateTime import DateTime
portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
portal_type="Payment Transaction",
simulation_state=["started"],
causality_state=["draft"],
payment_mode_uid=[
portal.portal_categories.payment_mode.payzen.getUid(),
portal.portal_categories.payment_mode.wechat.getUid()],
method_id='PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped',
packet_size=1, # just one to minimise errors
activate_kw={'tag': tag},
**kw
)
context.activate(after_tag=tag).getId()
<?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>tag, fixit, params</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_cancelStartedPaymentTransactionPaid</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
simulation_state = context.getSimulationState()
if simulation_state != "started":
# The payment isn't started, so ignore it
return "Not Started"
portal = context.getPortalObject()
paid = False
def isNodeFromLineReceivable(line):
node_value = line.getSourceValue(portal_type='Account')
return node_value.getAccountType() == 'asset/receivable'
invoice = context.getCausalityValue()
if invoice is None:
# No invoice Related, so skip and ignore
return
line_found = False
line_list = invoice.getMovementList(portal.getPortalAccountingMovementTypeList())
if not len(line_list):
# Ignore since lines to group don't exist yet
return
for line in invoice.getMovementList(portal.getPortalAccountingMovementTypeList()):
if isNodeFromLineReceivable(line):
line_found = True
if line.hasGroupingReference():
paid = True
letter = line.getGroupingReference()
break
if line_found and paid:
# We should ensure that the order builder won't create another document.
context.edit(payment_mode=None)
context.cancel(comment="Payment is cancelled since the invoice is payed by other document,\
with grouping reference %s" % letter)
# Should be safe now to fix everything XXXXXXX
context.SaleInvoiceTransaction_resetPaymentMode()
return
<?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>PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -1393,3 +1393,90 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin): ...@@ -1393,3 +1393,90 @@ class TestSlapOSGeneratePackingListFromTioXML(SlapOSTestCaseMixin):
self._test_alarm_not_visited( self._test_alarm_not_visited(
alarm, document, script_name) alarm, document, script_name)
class TestSlapOSCancelSaleTnvoiceTransactionPaiedPaymentListAlarm(SlapOSTestCaseMixin):
def _test_payment_is_draft(self, payment_mode):
new_id = self.generateNewId()
payment_transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode=payment_mode
)
self.tic()
self.portal.portal_alarms.slapos_cancel_sale_invoice_transaction_paied_payment_list.activeSense()
self.tic()
self.assertNotEqual(
'Not visited by PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped',
payment_transaction.getTitle())
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped')
def test_payment_is_draft_payzen(self):
self._test_payment_is_draft(payment_mode="payzen")
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped')
def test_payment_is_draft_wechat(self):
self._test_payment_is_draft(payment_mode="wechat")
def _test_payment_is_stopped(self, payment_mode):
new_id = self.generateNewId()
payment_transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode=payment_mode
)
payment_transaction.setStartDate(DateTime())
payment_transaction.confirm()
payment_transaction.start()
payment_transaction.stop()
self.tic()
self.portal.portal_alarms.slapos_cancel_sale_invoice_transaction_paied_payment_list.activeSense()
self.tic()
self.assertNotEqual(
'Not visited by PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped',
payment_transaction.getTitle())
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped')
def test_payment_is_stopped_payzen(self):
self._test_payment_is_stopped(payment_mode="payzen")
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped')
def test_payment_is_stopped_wechat(self):
self._test_payment_is_stopped(payment_mode="wechat")
def _test_payment_is_started(self, payment_mode):
new_id = self.generateNewId()
payment_transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode=payment_mode
)
payment_transaction.setStartDate(DateTime())
payment_transaction.confirm()
payment_transaction.start()
self.tic()
self.portal.portal_alarms.slapos_cancel_sale_invoice_transaction_paied_payment_list.activeSense()
self.tic()
self.assertNotEqual(
'Visited by PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped',
payment_transaction.getTitle())
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped')
def test_payment_is_started_payzen(self):
self._test_payment_is_started(payment_mode="payzen")
@simulateByTitlewMark('PaymentTransaction_cancelIfSaleInvoiceTransactionIsGrouped')
def test_payment_is_started_wechat(self):
self._test_payment_is_started(payment_mode="wechat")
...@@ -28,6 +28,7 @@ open_sale_order_module/slapos_accounting_open_sale_order_template ...@@ -28,6 +28,7 @@ open_sale_order_module/slapos_accounting_open_sale_order_template
organisation_module/slapos organisation_module/slapos
organisation_module/slapos/bank_account organisation_module/slapos/bank_account
portal_alarms/slapos_accounting_generate_packing_list_from_tioxml portal_alarms/slapos_accounting_generate_packing_list_from_tioxml
portal_alarms/slapos_cancel_sale_invoice_transaction_paied_payment_list
portal_alarms/slapos_contract_request_validation_payment portal_alarms/slapos_contract_request_validation_payment
portal_alarms/slapos_deliver_started_aggregated_sale_packing_list portal_alarms/slapos_deliver_started_aggregated_sale_packing_list
portal_alarms/slapos_manage_building_calculating_delivery portal_alarms/slapos_manage_building_calculating_delivery
......
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