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):
self.assertEqual(2, len(open_sale_order_list))
open_sale_order = [q for q in open_sale_order_list
if q.getValidationState() == 'archived'][0]
archived_open_sale_order_list = [q for q in open_sale_order_list
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(
portal_type='Open Sale Order Line')
self.assertEqual(len(hosting_subscription_list), len(line_list))
......@@ -635,9 +641,14 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
[q.getAggregate() for q in line_list]
)
validated_open_sale_order = [q for q in open_sale_order_list
if q.getValidationState() == 'validated'][0]
line_list = validated_open_sale_order.contentValues(
validated_open_sale_order_list = [q for q in open_sale_order_list
if q.getValidationState() == 'validated']
# 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')
self.assertEqual(len(line_list), 0)
......
......@@ -100,11 +100,13 @@
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -117,7 +119,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -10,36 +10,59 @@ person = context.getSourceProjectValue(portal_type="Person")
if (state != 'suspended') or \
(person is None):
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 None) or \
if (open_order is not None) and (
(open_order.getValidationState() != "validated") or \
(len(open_order.contentValues(portal_type="Open Sale Order Line")) != 0):
(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",
validation_state="archived",
sort_on=(('creation_date', 'DESC'),),
default_destination_decision_uid=person.getUid(),
limit=10)
if len(open_order_list):
# Ensure the list is indeed sorted to maximum know presicision
open_order = sorted(open_order_list, key=lambda x: x.getCreationDate(), reverse=True)[0]
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:
assert open_order.getDestinationDecisionUid() == person.getUid()
ticket = context
return mail_message, invoice_list
assert open_order.getDestinationDecisionUid() == person.getUid()
ticket = context
for payment in portal.portal_catalog(
for payment in portal.portal_catalog(
portal_type="Payment Transaction",
payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),
payment_mode_uid=[
portal.portal_categories.payment_mode.wechat.getUid(),
portal.portal_categories.payment_mode.payzen.getUid()],
default_destination_section_uid=person.getUid(),
simulation_state=["started"],
):
if payment.PaymentTransaction_getPayzenId()[1] is None:
if payment.getPaymentMode() == "payzen" and payment.PaymentTransaction_getPayzenId()[1] is None:
invoice = payment.getCausalityValue(portal_type="Sale Invoice Transaction")
assert payment.getDestinationSectionUid() == person.getUid()
invoice.SaleInvoiceTransaction_createReversalPayzenTransaction()
invoice_list.append(invoice.getRelativeUrl())
# XXX Hardcoded
# 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(),
......
......@@ -616,7 +616,7 @@ The slapos team
event, invoice_list = \
ticket.RegularisationRequest_cancelInvoiceIfPersonOpenOrderIsEmpty()
self.assertEqual(event, "fooevent")
self.assertNotEqual(event, "fooevent")
self.assertEqual(invoice_list, [])
class TestSlapOSRegularisationRequest_checkToTriggerNextEscalationStep(
......
......@@ -100,11 +100,13 @@
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -117,7 +119,9 @@
</item>
</dictionary>
</list>
</tuple>
</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