Skip to content

Commit

Permalink
Merge pull request #202 from maltaesousa/blurrypricing
Browse files Browse the repository at this point in the history
Blurrypricing
  • Loading branch information
maltaesousa authored Apr 1, 2021
2 parents 6da6066 + 59f37a9 commit 22ec0ad
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
10 changes: 8 additions & 2 deletions back/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,7 @@ class OrderStatus(models.TextChoices):
blank=True,
null=True)
invoice_reference = models.CharField(_('invoice_reference'), max_length=255, blank=True)
order_type = models.ForeignKey(
OrderType, models.PROTECT, verbose_name=_('order_type'), blank=True, null=True)
order_type = models.ForeignKey(OrderType, models.PROTECT, verbose_name=_('order_type'))
status = models.CharField(
_('status'), max_length=20, choices=OrderStatus.choices, default=OrderStatus.DRAFT)
date_ordered = models.DateTimeField(_('date_ordered'), blank=True, null=True)
Expand Down Expand Up @@ -573,6 +572,13 @@ def set_price(self, price=None, base_fee=None):
self.price_status = OrderItem.PricingStatus.CALCULATED
return

# prices are 0 when order is for public authorities or academic purposes
if self.order.order_type.name in ( 'Communal', 'Cantonal', 'Fédéral', 'Académique'):
self._price = Money(0, 'CHF')
self._base_fee = Money(0, 'CHF')
self.price_status = OrderItem.PricingStatus.CALCULATED
return

if self.product.pricing.pricing_type != Pricing.PricingType.MANUAL:
self._price, self._base_fee = self.product.pricing.get_price(self.order.geom)
if self._price is not None:
Expand Down
26 changes: 25 additions & 1 deletion back/api/tests/test_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.gis.geos import Polygon, Point
from djmoney.money import Money
from rest_framework.test import APITestCase
from api.models import Contact, Pricing, Product, PricingGeometry, Order, OrderItem
from api.models import Contact, Pricing, Product, PricingGeometry, Order, OrderItem, OrderType

UserModel = get_user_model()

Expand Down Expand Up @@ -135,6 +135,13 @@ def setUp(self):
geom=self.order_geom
)

self.orderTypePrivate = OrderType.objects.create(
name="Privé",
)
self.orderTypePublic = OrderType.objects.create(
name="Communal",
)

for geom in self.building_pricing_geometry:
geom.pricing = Pricing.objects.filter(
name="Par nombre d'objets").first()
Expand Down Expand Up @@ -179,6 +186,7 @@ def test_manual_price(self):
order=self.order,
product=self.products[5]
)
self.order.order_type = self.orderTypePrivate
self.order.save()
self.assertEqual(self.order.status, Order.OrderStatus.DRAFT)
self.assertEqual(order_item.price_status, OrderItem.PricingStatus.PENDING, 'princing status stays pending')
Expand Down Expand Up @@ -217,6 +225,7 @@ def test_base_fee(self):
order=self.order,
product=self.products[3]
)
self.order.order_type = self.orderTypePrivate
self.order.save()
orderitem1.set_price()
orderitem1.save()
Expand All @@ -234,6 +243,7 @@ def test_user_subscribed_to_product(self):
order=self.order,
product=self.products[3]
)
self.order.order_type = self.orderTypePrivate
self.order.save()
orderitem2.set_price()
orderitem2.save()
Expand All @@ -260,6 +270,20 @@ def test_invoice_contact_subscribed_to_product(self):
subscribed=True
)
self.order.invoice_contact = contact
self.order.order_type = self.orderTypePrivate
self.order.save()
orderitem2.set_price()
orderitem2.save()
self.order.set_price()
self.assertEqual(self.order.processing_fee, Money(0, 'CHF'), 'Processing fee is free')
self.assertEqual(self.order.total_with_vat, Money(0, 'CHF'), 'Order is free')

def test_public_order_is_free(self):
orderitem2 = OrderItem.objects.create(
order=self.order,
product=self.products[3]
)
self.order.order_type = self.orderTypePublic
self.order.save()
orderitem2.set_price()
orderitem2.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

<button [disabled]="order && !order.geom" mat-raised-button color="primary" class="action-button"
(click)="naviguateToNewOrder()">
Passer la commande
Poursuivre la commande...
</button>

<div *ngIf="order && !order?.geom" class="flex-row warning-container">
<mat-icon>warning</mat-icon>
<span>Vous devez sélectionner un périmètre avant de passer la commande.</span>
<span>Vous devez sélectionner un périmètre avant de poursuivre la commande.</span>
</div>
2 changes: 2 additions & 0 deletions front/src/app/account/new-order/new-order.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,10 @@ export class NewOrderComponent implements OnInit, OnDestroy {
const mandatoryContactOrders = ['Communal', 'Cantonal', 'Fédéral', 'Académique'];
if (mandatoryContactOrders.indexOf(orderTypeValue.name) > -1) {
// Force enable contact form because it's a public mandate
this.addressChoiceCtrl?.setValue('2');
this.updateContactForm('2');
} else {
this.addressChoiceCtrl?.setValue('1');
this.updateContactForm('1');
}
this.orderFormGroup.get('title')?.setValue('');
Expand Down
11 changes: 10 additions & 1 deletion front/src/app/welcome/catalog/catalog.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
<img class="item-logo rounded-image" alt="Logo du produit" aria-label="Logo du produit"
src="{{mediaUrl}}/{{product.thumbnail_link}}">
<div class="item-label text-ellipsis-2" [matTooltip]="product.label">{{product.label}}</div>
<span class="item-price text-secondary">{{product.pricing}}</span>

<ng-container *ngIf="product.pricing === 'Gratuit'; then gratuit; else payant">
</ng-container>
<ng-template #gratuit>
<span class="item-price text-secondary">Gratuit</span>
</ng-template>
<ng-template #payant>
<span class="item-price text-secondary">Tarification selon le type de mandat</span>
</ng-template>

<button class="item-help" matTooltip="Voir les meta données" aria-label="Voir les meta données"
[disabled]="!product.metadata"
color="primary" mat-button
Expand Down
9 changes: 7 additions & 2 deletions scripts/triggers.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
CREATE TEXT SEARCH CONFIGURATION fr ( COPY = french );
ALTER TEXT SEARCH CONFIGURATION fr
ALTER MAPPING FOR hword, hword_part, word
WITH unaccent, french_stem;

CREATE FUNCTION geoshop.update_product_tsvector()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$
BEGIN
NEW.ts := to_tsvector('french', NEW.label || ' ' || (
NEW.ts := to_tsvector('fr', NEW.label || ' ' || (
SELECT concat(description_long, ' ' , description_short) FROM geoshop.metadata WHERE id = NEW.metadata_id
));
RETURN NEW;
Expand All @@ -20,7 +25,7 @@ CREATE FUNCTION geoshop.update_metadata_tsvector()
AS $BODY$
BEGIN
UPDATE geoshop.product p
SET ts = to_tsvector('french', label || ' ' || concat(NEW.description_long, ' ' , NEW.description_short))
SET ts = to_tsvector('fr', label || ' ' || concat(NEW.description_long, ' ' , NEW.description_short))
WHERE NEW.id = p.metadata_id;
RETURN NEW;
END;
Expand Down

0 comments on commit 22ec0ad

Please sign in to comment.