planitech: add a pricing code on users (#30261)
This commit is contained in:
parent
62e683f378
commit
1660716b26
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.18 on 2019-04-03 17:38
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('planitech', '0003_pairing'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='pairing',
|
||||
name='price_code',
|
||||
field=models.CharField(blank=True, max_length=128, verbose_name='Price code'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='planitechconnector',
|
||||
name='price_code',
|
||||
field=models.CharField(blank=True, max_length=128, verbose_name='Price code'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='planitechconnector',
|
||||
name='slug',
|
||||
field=models.SlugField(unique=True, verbose_name='Identifier'),
|
||||
),
|
||||
]
|
|
@ -254,6 +254,7 @@ class PlanitechConnector(BaseResource):
|
|||
verify_cert = models.BooleanField(
|
||||
default=True, verbose_name=_('Check HTTPS Certificate validity'))
|
||||
custom_fields = JSONField(_('Custom places fields'), blank=True, null=True)
|
||||
price_code = models.CharField(max_length=128, verbose_name=_('Price code'), blank=True)
|
||||
|
||||
category = _('Business Process Connectors')
|
||||
|
||||
|
@ -386,13 +387,14 @@ class PlanitechConnector(BaseResource):
|
|||
with transaction.atomic():
|
||||
pairing, created = Pairing.objects.get_or_create(
|
||||
resource=self, name_id=post_data['name_id'],
|
||||
defaults={'external_id': uuid.uuid4().get_hex()})
|
||||
defaults={'external_id': uuid.uuid4().get_hex(), 'price_code': self.price_code})
|
||||
if created:
|
||||
params = {
|
||||
"externalUserIdentifier": pairing.external_id,
|
||||
"name": post_data['last_name'],
|
||||
"firstName": post_data['first_name'],
|
||||
"mail": post_data['email']
|
||||
"mail": post_data['email'],
|
||||
"pricingCode": self.price_code
|
||||
}
|
||||
data = self._call_planitech(self.requests.post, 'createPerson', params)
|
||||
if data.get('creationStatus') != 'OK':
|
||||
|
@ -720,3 +722,4 @@ class Pairing(models.Model):
|
|||
name_id = models.CharField(blank=False, max_length=256)
|
||||
external_id = models.CharField(blank=False, max_length=256)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
price_code = models.CharField(max_length=128, verbose_name=_('Price code'), blank=True)
|
||||
|
|
|
@ -74,7 +74,7 @@ def connector(db):
|
|||
connector = PlanitechConnector.objects.create(
|
||||
url='http://example.planitech.com/', username='admin', password='admin',
|
||||
verify_cert=False, slug='slug-planitech',
|
||||
custom_fields=[{'name': 'some_custom_field', 'type': 'string'}])
|
||||
custom_fields=[{'name': 'some_custom_field', 'type': 'string'}], price_code='T1')
|
||||
obj_type = ContentType.objects.get_for_model(connector)
|
||||
AccessRight.objects.create(
|
||||
codename='can_access', apiuser=api, resource_type=obj_type, resource_pk=connector.pk)
|
||||
|
@ -183,9 +183,11 @@ def test_create_reservation(app, connector, monkeypatch):
|
|||
assert person_args['mail'] == 'jon.doe@localhost'
|
||||
assert person_args['firstName'] == 'jon'
|
||||
assert person_args['name'] == 'doe'
|
||||
assert person_args['pricingCode'] == 'T1'
|
||||
external_id = person_args['externalUserIdentifier']
|
||||
pairing = Pairing.objects.get(resource=connector, name_id='john-doe')
|
||||
assert pairing.external_id == external_id
|
||||
assert pairing.price_code == 'T1'
|
||||
|
||||
reservation_args = mock_call_planitech.call_args_list[1][0]
|
||||
assert reservation_args[1] == 'createReservation'
|
||||
|
@ -273,9 +275,11 @@ def test_get_reservation_price(app, connector, monkeypatch):
|
|||
assert person_args['mail'] == 'jon.doe@localhost'
|
||||
assert person_args['firstName'] == 'jon'
|
||||
assert person_args['name'] == 'doe'
|
||||
assert person_args['pricingCode'] == 'T1'
|
||||
external_id = person_args['externalUserIdentifier']
|
||||
pairing = Pairing.objects.get(resource=connector, name_id='john-doe')
|
||||
assert pairing.external_id == external_id
|
||||
assert pairing.price_code == 'T1'
|
||||
|
||||
reservation_args = mock_call_planitech.call_args_list[1][0]
|
||||
assert reservation_args[1] == 'getFutureReservationPrice'
|
||||
|
|
Loading…
Reference in New Issue