Commit c86f24e3 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Don't create "Accounting Creation" Invoice for release account

    The user should request to Mantainence to "Open" a contract.
parent 71e9f196
Pipeline #11786 failed with stage
in 0 seconds
......@@ -42,8 +42,6 @@ if (contract is None):
contract.reindexObject(activate_kw={'tag': tag})
if (contract.getValidationState() == "invalidated"):
# Prevent concurrent transaction to create 2 invoices for the same person
person.serialize()
# search if the user already paid anything
payment = portal.portal_catalog.getResultValue(
......@@ -52,69 +50,7 @@ if (contract.getValidationState() == "invalidated"):
simulation_state=['stopped'],
)
if (payment is None):
# Manually create an invoice to request payment validation
current_invoice = contract.getCausalityValue()
if current_invoice is None:
# Create the validation invoice
# XXX Hardcoded
invoice_template = portal.restrictedTraverse("accounting_module/template_contract_sale_invoice_transaction")
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
contract.edit(causality_value=current_invoice)
contract.reindexObject(activate_kw={'tag': tag})
current_invoice.edit(
title="Account validation",
source_value=person,
destination_value=person,
destination_section_value=person,
destination_decision_value=person,
start_date=DateTime(),
stop_date=None,
)
comment = "Validation invoice for contract %s" % contract.getRelativeUrl()
current_invoice.plan(comment=comment)
current_invoice.confirm(comment=comment)
current_invoice.startBuilding(comment=comment)
current_invoice.reindexObject(activate_kw={'tag': tag})
else:
# Check if the invoice is still ongoing
simulation_state = current_invoice.getSimulationState()
if simulation_state in ("planned", "confirmed", "ordered", "started"):
# Waiting for payment
result = "ongoing"
elif simulation_state in ("cancelled", "deleted", "draft"):
result = "cancelled"
elif simulation_state in ("stopped", "delivered"):
# Invoice is in final state.
paid = True
for line in current_invoice.getMovementList(portal.getPortalAccountingMovementTypeList()):
node_value = line.getSourceValue(portal_type='Account')
if node_value.getAccountType() == 'asset/receivable':
if not line.hasGroupingReference():
paid = False
break
if paid:
result = "paid"
else:
result = "ongoing"
else:
raise NotImplementedError, "Unknow state %s" % simulation_state
if result in ("paid", "cancelled"):
# Maybe have been paid or not (mirror invoice may have been created)
# Check in next alarm loop for a payment
contract.edit(causality_value=None)
contract.reindexObject(activate_kw={'tag': tag})
else:
if (payment is not None):
# Found one payment, the contract can be validated
comment = "Contract validated as paid payment %s found" % payment.getRelativeUrl()
contract.validate(comment=comment)
......
......@@ -2,7 +2,6 @@
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort
from zExceptions import Unauthorized
from DateTime import DateTime
class TestSlapOSSoftwareInstance_requestValidationPayment(SlapOSTestCaseMixinWithAbort):
......@@ -137,34 +136,6 @@ class TestSlapOSSoftwareInstance_requestValidationPayment(SlapOSTestCaseMixinWit
self.assertEqual(contract2.getCausality(""), "")
self.assertEqual(contract2.getValidationState(), "validated")
def test_create_invoice_if_needed_and_no_payment_found(self):
person, instance, _ = self.createNeededDocuments()
contract = self.createCloudContract()
contract.edit(destination_section_value=person)
self.assertEqual(contract.getValidationState(), "invalidated")
self.tic()
before_date = DateTime()
contract2 = instance.SoftwareInstance_requestValidationPayment()
after_date = DateTime()
self.assertEqual(contract2.getRelativeUrl(), contract.getRelativeUrl())
self.assertNotEqual(contract2.getCausality(""), "")
self.assertEqual(contract2.getValidationState(), "invalidated")
invoice = contract2.getCausalityValue()
self.assertEqual(invoice.getPortalType(), 'Sale Invoice Transaction')
self.assertEqual(len(invoice.contentValues()), 1)
self.assertEqual(invoice.getSimulationState(), 'confirmed')
self.assertEqual(invoice.getCausalityState(), 'building')
self.assertEqual(invoice.getTitle(), 'Account validation')
self.assertEqual(invoice.getSource(), person.getRelativeUrl())
self.assertEqual(invoice.getDestination(), person.getRelativeUrl())
self.assertEqual(invoice.getDestinationSection(), person.getRelativeUrl())
self.assertEqual(invoice.getDestinationDecision(), person.getRelativeUrl())
self.assertTrue(invoice.getStartDate() >= before_date)
self.assertTrue(invoice.getStartDate() <= after_date)
self.assertEqual(invoice.getStartDate(), invoice.getStopDate())
def test_do_nothing_if_invoice_is_ongoing(self):
person, instance, _ = self.createNeededDocuments()
contract = self.createCloudContract()
......@@ -182,24 +153,7 @@ class TestSlapOSSoftwareInstance_requestValidationPayment(SlapOSTestCaseMixinWit
self.assertEqual(contract2.getCausality(""), invoice.getRelativeUrl())
self.assertEqual(contract2.getValidationState(), "invalidated")
def test_forget_current_cancelled_invoice(self):
person, instance, _ = self.createNeededDocuments()
contract = self.createCloudContract()
invoice = self.createInvoiceTransaction()
self.portal.portal_workflow._jumpToStateFor(invoice, 'cancelled')
contract.edit(
destination_section_value=person,
causality_value=invoice,
)
self.assertEqual(contract.getValidationState(), "invalidated")
self.tic()
contract2 = instance.SoftwareInstance_requestValidationPayment()
self.assertEqual(contract2.getRelativeUrl(), contract.getRelativeUrl())
self.assertEqual(contract2.getCausality(""), "")
self.assertEqual(contract2.getValidationState(), "invalidated")
def test_forget_current_grouped_invoice(self):
def test_dont_forget_current_grouped_invoice(self):
person, instance, _ = self.createNeededDocuments()
contract = self.createCloudContract()
invoice = self.createInvoiceTransaction()
......@@ -219,7 +173,7 @@ class TestSlapOSSoftwareInstance_requestValidationPayment(SlapOSTestCaseMixinWit
contract2 = instance.SoftwareInstance_requestValidationPayment()
self.assertEqual(contract2.getRelativeUrl(), contract.getRelativeUrl())
self.assertEqual(contract2.getCausality(""), "")
self.assertEqual(contract2.getCausality(""), invoice.getRelativeUrl())
self.assertEqual(contract2.getValidationState(), "invalidated")
def test_do_nothing_if_invoice_is_not_grouped(self):
......
......@@ -413,6 +413,8 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
def checkCloudContract(self, person_user_id, person_reference,
instance_title, software_release, software_type, server):
self.assertTrue(self.portal.portal_preferences.getPreferredCloudContractEnabled())
self.stepCallSlaposContractRequestValidationPaymentAlarm()
self.tic()
......@@ -463,23 +465,23 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self.stepCallSlaposCrmCreateRegularisationRequestAlarm()
self.tic()
self.usePayzenManually(self.web_site, person_user_id)
self.tic()
self.login()
payment = self.portal.portal_catalog.getResultValue(
portal_type="Payment Transaction",
simulation_state="started")
person = self.portal.portal_catalog.getResultValue(
portal_type="Person",
user_id=person_user_id)
self.logout()
self.login()
contract = self.portal.portal_catalog.getResultValue(
portal_type="Cloud Contract",
default_destination_section_uid=person.getUid(),
validation_state=['invalidated', 'validated'])
data_kw = {
'errorCode': '0',
'transactionStatus': '6',
'authAmount': 200,
'authDevise': '978',
}
payment.PaymentTransaction_createPayzenEvent().PayzenEvent_processUpdate(data_kw, True)
self.assertNotEqual(contract, None)
self.assertEqual(contract.getValidationState(), "invalidated")
# HACK FOR NOW
contract.validate()
self.tic()
self.login(person_user_id)
......
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