diff --git a/back/api/models.py b/back/api/models.py index d2faf568..a6b84da1 100644 --- a/back/api/models.py +++ b/back/api/models.py @@ -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) @@ -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: diff --git a/back/api/tests/test_pricing.py b/back/api/tests/test_pricing.py index cb534258..8ba93b1e 100644 --- a/back/api/tests/test_pricing.py +++ b/back/api/tests/test_pricing.py @@ -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() @@ -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() @@ -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') @@ -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() @@ -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() @@ -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() diff --git a/front/src/app/_components/cart-overlay/cart-overlay.component.html b/front/src/app/_components/cart-overlay/cart-overlay.component.html index 6c6cdf72..52aaa69f 100644 --- a/front/src/app/_components/cart-overlay/cart-overlay.component.html +++ b/front/src/app/_components/cart-overlay/cart-overlay.component.html @@ -19,10 +19,10 @@
warning - Vous devez sélectionner un périmètre avant de passer la commande. + Vous devez sélectionner un périmètre avant de poursuivre la commande.
diff --git a/front/src/app/account/new-order/new-order.component.ts b/front/src/app/account/new-order/new-order.component.ts index e28a7abd..e1bece1e 100644 --- a/front/src/app/account/new-order/new-order.component.ts +++ b/front/src/app/account/new-order/new-order.component.ts @@ -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(''); diff --git a/front/src/app/welcome/catalog/catalog.component.html b/front/src/app/welcome/catalog/catalog.component.html index 93de83d8..7e7e5318 100644 --- a/front/src/app/welcome/catalog/catalog.component.html +++ b/front/src/app/welcome/catalog/catalog.component.html @@ -21,7 +21,16 @@
{{product.label}}
- {{product.pricing}} + + + + + Gratuit + + + Tarification selon le type de mandat + +