Commit 37c4905e authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: WIP selling project subscription

parent c5835275
......@@ -110,7 +110,40 @@ class TestSlapOSVirtualMasterSubscriptionRequestScenario(TestSlapOSVirtualMaster
# the erp5 manager
self.addSaleManagerAssignment(person)
# Remove customer project assignment
#person.manage_delObjects(ids=[x.getId() for x in person.contentValues(portal_type="Assignment") if x.getFunction() == 'customer'])
person.manage_delObjects(ids=[x.getId() for x in person.contentValues(portal_type="Assignment") if x.getFunction() == 'customer'])
self.tic()
return person
def addAccountingManagerAssignment(self, person):
person.newContent(
portal_type='Assignment',
function='function/accounting/manager'
).open()
def createAccountingAdministrator(self, web_site):
self.logout()
login = 'accounting-%s' % self.generateNewId()
self.joinSlapOS(web_site, login)
self.login()
person = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login",
reference=login).getParentValue()
# first slapos administrator assignment can only be created by
# the erp5 manager
self.addAccountingManagerAssignment(person)
# Remove customer project assignment
person.manage_delObjects(ids=[x.getId() for x in person.contentValues(portal_type="Assignment") if x.getFunction() == 'customer'])
self.tic()
return person
def createCustomer(self, web_site):
self.logout()
login = 'customer-%s' % self.generateNewId()
self.joinSlapOS(web_site, login)
self.login()
person = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login",
reference=login).getParentValue()
self.tic()
return person
......@@ -153,32 +186,29 @@ class TestSlapOSVirtualMasterSubscriptionRequestScenario(TestSlapOSVirtualMaster
web_site = self.web_site
sale_person = self.createSaleAdministrator(web_site)
accountant_person = self.createAccountingAdministrator(web_site)
#################################
# Create accounting data
self.logout()
self.login(accountant_person.getUserId())
currency = self.portal.currency_module.newContent(
portal_type='Currency',
title="fake currency"
)
currency.validate()
return web_site, currency, sale_person
def test_virtual_master_subscribe_to_project(self):
_, currency, sale_person = self.bootstrapSubscriptionRequestScenario()
self.tic()
#################################
# Prepare saling virtual master
#################################
# Prepare providing free virtual master to sale users
self.logout()
self.login(sale_person.getUserId())
now = DateTime()
seller_organisation = self.portal.organisation_module.newContent(
portal_type="Organisation",
title="seller-orga"
)
seller_organisation.validate()
sale_person.setCareerSubordinationValue(seller_organisation)
internal_trade_condition = self.portal.sale_trade_condition_module.newContent(
portal_type="Sale Trade Condition",
reference='internal_for_%s' % seller_organisation.getTitle(),
......@@ -192,24 +222,36 @@ class TestSlapOSVirtualMasterSubscriptionRequestScenario(TestSlapOSVirtualMaster
)
internal_trade_condition.validate()
"""
virtual_master_sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply"
)
virtual_master_sale_supply.validate()
"""
self.tic()
self.tic()
return web_site, now, currency, sale_person, seller_organisation
def checkSiteConsistency(self):
self.logout()
for _ in range(20):
self.stepCallAlarmList()
self.tic()
self.login()
self.stepcheckERP5Consistency()
# after accept, an email is send containing the reset link
last_message = self.portal.MailHost._last_message
assert last_message is None, last_message
def checkVirtualMasterSubscription(self, user_person, now):
#################################
# Buy the first project
#################################
self.logout()
self.login(user_person.getUserId())
# XXX How to list possible service to sell?
# Search product with `time` unit ?
service = self.portal.restrictedTraverse('service_module/slapos_virtual_master_subscription')
# XXX This is a script like: Product_submitSubscriptionRequest()
source_decision_value = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
source_section_value = seller_organisation#source_decision_value#source_decision_value.getCareerSubordinationValue() or source_decision_value
source_section_value = source_decision_value.getCareerSubordinationValue(source_decision_value)
source_section_value = source_decision_value.getCareerSubordinationValue(source_decision_value)
# Find trade condition / price
......@@ -288,12 +330,6 @@ class TestSlapOSVirtualMasterSubscriptionRequestScenario(TestSlapOSVirtualMaster
"""
open_sale_order.SaleOrder_applySaleTradeCondition(batch_mode=1, force=1)
price = open_order_line.getPrice()
open_order_line.edit(
price=price
)
subscription_request = self.portal.subscription_request_module.newContent(
portal_type='Subscription Request',
......@@ -308,8 +344,8 @@ class TestSlapOSVirtualMasterSubscriptionRequestScenario(TestSlapOSVirtualMaster
specialise_value=open_sale_order.getSpecialiseValue(),
destination_value=open_sale_order.getSourceValue(),
destination_section_value=open_sale_order.getSourceSectionValue(),
price_currency_value=open_sale_order.getPriceCurrencyValue()
price_currency_value=open_sale_order.getPriceCurrencyValue(),
price=open_order_line.getPrice()
)
"""
invoicing_type=invoicing_type,
......@@ -349,6 +385,9 @@ class TestSlapOSVirtualMasterSubscriptionRequestScenario(TestSlapOSVirtualMaster
delivery_address_autocompleted=has_delivery_address and bool(int(request_form.get('field_your_delivery_address_autocompleted', "0"))),
)
"""
if len(subscription_request.checkConsistency()) != 0:
self.tic()
raise NotImplementedError('nope')
subscription_request.submit()
self.tic()
......@@ -365,11 +404,24 @@ class TestSlapOSVirtualMasterSubscriptionRequestScenario(TestSlapOSVirtualMaster
)
item.validate()
subscription_trade_condition = subscription_request.getSpecialiseValue()
project_trade_condition = self.portal.sale_trade_condition_module.newContent(
portal_type="Sale Trade Condition",
reference='for_project_%s' % item.getTitle(),
# XXX hardcoded
specialise="business_process_module/slapos_ultimate_business_process",
source_value=subscription_trade_condition.getSourceValue(),
source_section_value=subscription_trade_condition.getSourceSectionValue(),
destination_project_value=item,
effective_date=now.earliestTime(),
price_currency_value=subscription_trade_condition.getPriceCurrencyValue()
)
project_trade_condition.validate()
subscription_request.getSourceDecisionValue().newContent(
portal_type="Assignment",
destination_project_value=item,
function='production/manager'
).open()
hosting_subscription = self.portal.hosting_subscription_module.newContent(
......@@ -475,13 +527,56 @@ class TestSlapOSVirtualMasterSubscriptionRequestScenario(TestSlapOSVirtualMaster
self.logout()
self.login(customer.getUserId())
"""
return subscription_request
def test_virtual_master_sale_subscribe_to_project(self):
_, now, _, sale_person, _ = self.bootstrapSubscriptionRequestScenario()
self.tic()
self.checkVirtualMasterSubscription(sale_person, now)
self.checkSiteConsistency()
def test_virtual_master_customer_subscribe_to_project(self):
web_site, now, _, sale_person, _ = self.bootstrapSubscriptionRequestScenario()
self.tic()
main_project_subscription = self.checkVirtualMasterSubscription(sale_person, now)
self.logout()
for _ in range(20):
self.stepCallAlarmList()
self.tic()
self.login()
self.tic()
project = main_project_subscription.getCausalityRelatedValue(portal_type="Open Sale Order")\
.contentValues(portal_type="Open Sale Order Line")[0]\
.getAggregateValue(portal_type="Project")
# Setup preferences
preference = self.portal.portal_preferences.slapos_default_system_preference
preference.edit(
preferred_subscription_assignment_category_list=[
'function/customer',
'role/client',
'destination_project/%s' % project.getRelativeUrl()
]
)
self.stepcheckERP5Consistency()
# after accept, an email is send containing the reset link
last_message = self.portal.MailHost._last_message
assert last_message is None, last_message
\ No newline at end of file
"""
sale_person.setCareerSubordinationValue(seller_organisation)
internal_trade_condition = self.portal.sale_trade_condition_module.newContent(
portal_type="Sale Trade Condition",
reference='internal_for_%s' % seller_organisation.getTitle(),
# XXX hardcoded
specialise="business_process_module/slapos_ultimate_business_process",
source_value=seller_organisation,
source_section_value=seller_organisation,
destination_section_value=seller_organisation,
effective_date=now.earliestTime(),
price_currency_value=currency
)
internal_trade_condition.validate()
"""
#################################
# Buy the first project
customer_person = self.createCustomer(web_site)
self.logout()
self.login(customer_person.getUserId())
self.checkVirtualMasterSubscription(customer_person, now)
self.checkSiteConsistency()
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