Commit 709180ed authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Open Sale Order are archived earlier

    If the user has just archived OSO, it means he destroyed everything (also).
    Update Tests, Open sale order with no Lines are automatically archived
    Update Test, Email isn't send if there isn't any invoice to cancel for the user.
parent eee128a4
...@@ -625,8 +625,14 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin): ...@@ -625,8 +625,14 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self.assertEqual(2, len(open_sale_order_list)) self.assertEqual(2, len(open_sale_order_list))
open_sale_order = [q for q in open_sale_order_list archived_open_sale_order_list = [q for q in open_sale_order_list
if q.getValidationState() == 'archived'][0] if q.getValidationState() == 'archived']
archived_open_sale_order_list.sort(key=lambda x: x.getCreationDate())
# Select the first archived
open_sale_order = archived_open_sale_order_list[0]
line_list = open_sale_order.contentValues( line_list = open_sale_order.contentValues(
portal_type='Open Sale Order Line') portal_type='Open Sale Order Line')
self.assertEqual(len(hosting_subscription_list), len(line_list)) self.assertEqual(len(hosting_subscription_list), len(line_list))
...@@ -635,9 +641,14 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin): ...@@ -635,9 +641,14 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
[q.getAggregate() for q in line_list] [q.getAggregate() for q in line_list]
) )
validated_open_sale_order = [q for q in open_sale_order_list validated_open_sale_order_list = [q for q in open_sale_order_list
if q.getValidationState() == 'validated'][0] if q.getValidationState() == 'validated']
line_list = validated_open_sale_order.contentValues(
# if no line, all open orders are kept archived
self.assertEqual(len(validated_open_sale_order_list), 0)
latest_open_sale_order = archived_open_sale_order_list[-1]
line_list = latest_open_sale_order.contentValues(
portal_type='Open Sale Order Line') portal_type='Open Sale Order Line')
self.assertEqual(len(line_list), 0) self.assertEqual(len(line_list), 0)
......
...@@ -100,24 +100,28 @@ ...@@ -100,24 +100,28 @@
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>validate</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>validate</string> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>validated</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>validated</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -10,38 +10,61 @@ person = context.getSourceProjectValue(portal_type="Person") ...@@ -10,38 +10,61 @@ person = context.getSourceProjectValue(portal_type="Person")
if (state != 'suspended') or \ if (state != 'suspended') or \
(person is None): (person is None):
return mail_message, invoice_list return mail_message, invoice_list
else:
portal = context.getPortalObject()
open_order = portal.portal_catalog.getResultValue( portal = context.getPortalObject()
open_order = portal.portal_catalog.getResultValue(
portal_type="Open Sale Order",
validation_state="validated",
default_destination_decision_uid=person.getUid())
if (open_order is not None) and (
(open_order.getValidationState() != "validated") or \
(len(open_order.contentValues(portal_type="Open Sale Order Line")) != 0)):
return mail_message, invoice_list
if open_order is None:
# No open order was found, check if the latest archived order
# exists and contains no line.
open_order_list = portal.portal_catalog(
portal_type="Open Sale Order", portal_type="Open Sale Order",
validation_state="validated", validation_state="archived",
default_destination_decision_uid=person.getUid()) sort_on=(('creation_date', 'DESC'),),
default_destination_decision_uid=person.getUid(),
limit=10)
if (open_order is None) or \ if len(open_order_list):
(open_order.getValidationState() != "validated") or \ # Ensure the list is indeed sorted to maximum know presicision
(len(open_order.contentValues(portal_type="Open Sale Order Line")) != 0): open_order = sorted(open_order_list, key=lambda x: x.getCreationDate(), reverse=True)[0]
return mail_message, invoice_list if len(open_order.contentValues(portal_type="Open Sale Order Line")) != 0:
raise ValueError("Something is wrong, this Open Sale Order should had no Line")
else: else:
assert open_order.getDestinationDecisionUid() == person.getUid() return mail_message, invoice_list
ticket = context
assert open_order.getDestinationDecisionUid() == person.getUid()
for payment in portal.portal_catalog( ticket = context
portal_type="Payment Transaction",
payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(), for payment in portal.portal_catalog(
default_destination_section_uid=person.getUid(), portal_type="Payment Transaction",
simulation_state=["started"], payment_mode_uid=[
): portal.portal_categories.payment_mode.wechat.getUid(),
portal.portal_categories.payment_mode.payzen.getUid()],
if payment.PaymentTransaction_getPayzenId()[1] is None: default_destination_section_uid=person.getUid(),
invoice = payment.getCausalityValue(portal_type="Sale Invoice Transaction") simulation_state=["started"],
assert payment.getDestinationSectionUid() == person.getUid() ):
invoice.SaleInvoiceTransaction_createReversalPayzenTransaction()
invoice_list.append(invoice.getRelativeUrl()) if payment.getPaymentMode() == "payzen" and payment.PaymentTransaction_getPayzenId()[1] is None:
invoice = payment.getCausalityValue(portal_type="Sale Invoice Transaction")
# XXX Hardcoded assert payment.getDestinationSectionUid() == person.getUid()
cancel_service = portal.service_module.slapos_crm_invoice_cancellation invoice.SaleInvoiceTransaction_createReversalPayzenTransaction()
mail_message = ticket.RegularisationRequest_checkToSendUniqEvent( invoice_list.append(invoice.getRelativeUrl())
# Missing wechat cancellation
if len(invoice_list) > 0:
cancel_service = portal.service_module.slapos_crm_invoice_cancellation
mail_message = ticket.RegularisationRequest_checkToSendUniqEvent(
cancel_service.getRelativeUrl(), cancel_service.getRelativeUrl(),
'Cancellation of your bill', 'Cancellation of your bill',
"""Hello, """Hello,
......
...@@ -616,7 +616,7 @@ The slapos team ...@@ -616,7 +616,7 @@ The slapos team
event, invoice_list = \ event, invoice_list = \
ticket.RegularisationRequest_cancelInvoiceIfPersonOpenOrderIsEmpty() ticket.RegularisationRequest_cancelInvoiceIfPersonOpenOrderIsEmpty()
self.assertEqual(event, "fooevent") self.assertNotEqual(event, "fooevent")
self.assertEqual(invoice_list, []) self.assertEqual(invoice_list, [])
class TestSlapOSRegularisationRequest_checkToTriggerNextEscalationStep( class TestSlapOSRegularisationRequest_checkToTriggerNextEscalationStep(
......
...@@ -100,24 +100,28 @@ ...@@ -100,24 +100,28 @@
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>validate</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>validate</string> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>validated</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>validated</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </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