Skip to content

Commit

Permalink
♻️(backend) remove has_consent_to_terms for Order model
Browse files Browse the repository at this point in the history
From now on, the terms and conditions (CGV in French) must be
specific to each organization. We can no longer use a global
version for the entire platform. These terms will be included
directly in the contract's context, so the Order model no longer
needs to track user acceptance, as this will happen during contract
signing. The terms and conditions will be written and stored in the
contract definition body field. There's no need to prepare them
separately for the contract context anymore. We've updated the
contract preparation template by removing the terms_and_conditions
from the Appendices section. The use of SiteConfig to prepare
terms and conditions for a contract in Markdown is now deprecated.

Fix #816
  • Loading branch information
jonathanreveille committed Jun 10, 2024
1 parent 0f3663a commit d1b2e4c
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 170 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to

### Changed

- Terms and conditions are stored into contract definition body
and `has_consent_to_terms` been removed from `Order` model
- Add `currency` field to `OrderPaymentSerializer` serializer
- Allow an order with `no_payment` state to pay for failed installment
on a payment schedule
Expand Down
1 change: 0 additions & 1 deletion src/backend/joanie/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ class OrderAdmin(DjangoObjectActions, admin.ModelAdmin):
readonly_fields = (
"state",
"total",
"has_consent_to_terms",
"invoice",
"certificate",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.13 on 2024-06-10 12:45

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0033_alter_order_state'),
]

operations = [
migrations.RemoveField(
model_name='order',
name='has_consent_to_terms',
),
]
6 changes: 0 additions & 6 deletions src/backend/joanie/core/models/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,6 @@ class Order(BaseModel):
on_delete=models.RESTRICT,
db_index=True,
)
has_consent_to_terms = models.BooleanField(
verbose_name=_("has consent to terms"),
editable=False,
default=False,
help_text=_("User has consented to the platform terms and conditions."),
)
state = models.CharField(
default=enums.ORDER_STATE_DRAFT,
choices=enums.ORDER_STATE_CHOICES,
Expand Down
1 change: 1 addition & 0 deletions src/backend/joanie/core/models/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Meta:
def __str__(self):
return f"Site config for {self.site.name}"

# DEPRECATED : The terms and conditions will be stored into the contract definition context
def get_terms_and_conditions_in_html(self, language=None):
"""Return the terms and conditions in html format."""
content = self.safe_translation_getter(
Expand Down
1 change: 0 additions & 1 deletion src/backend/joanie/core/serializers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,6 @@ class Meta:
"contract",
"certificate",
"main_invoice",
"has_consent_to_terms",
)
read_only_fields = fields

Expand Down
11 changes: 0 additions & 11 deletions src/backend/joanie/core/serializers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,6 @@ class OrderSerializer(serializers.ModelSerializer):
read_only=True, slug_field="id", source="certificate"
)
contract = ContractSerializer(read_only=True, exclude_abilities=True)
has_consent_to_terms = serializers.BooleanField(write_only=True)
payment_schedule = OrderPaymentSerializer(many=True, read_only=True)

class Meta:
Expand All @@ -1151,7 +1150,6 @@ class Meta:
"target_enrollments",
"total",
"total_currency",
"has_consent_to_terms",
"payment_schedule",
]
read_only_fields = fields
Expand All @@ -1166,14 +1164,6 @@ def get_target_enrollments(self, order) -> list[dict]:
context=self.context,
).data

def validate_has_consent_to_terms(self, value):
"""Check that user has accepted terms and conditions."""
if not value:
message = _("You must accept the terms and conditions to proceed.")
raise serializers.ValidationError(message)

return value

def create(self, validated_data):
"""
Create a new order and set the organization if provided.
Expand All @@ -1196,7 +1186,6 @@ def update(self, instance, validated_data):
validated_data.pop("organization", None)
validated_data.pop("product", None)
validated_data.pop("order_group", None)
validated_data.pop("has_consent_to_terms", None)
return super().update(instance, validated_data)

def get_total_currency(self, *args, **kwargs) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,8 @@ <h1>{{ contract.title }}</h1>
{% if contract %}
{{ contract.body|safe }}
{% endif %}
{% if contract.terms_and_conditions or syllabus %}
<h2>{% translate "Appendices" %}</h2>
{% endif %}
{% if contract.terms_and_conditions %}
<h3>{% translate "Terms and conditions" %}</h3>
{{ contract.terms_and_conditions|safe }}
{% endif %}
{% if syllabus %}
<h2>{% translate "Appendices" %}</h2>
<h3>{% translate "Catalog syllabus" %}</h3>
{% include "contract_definition/fragment_appendice_syllabus.html" with syllabus=syllabus %}
{% endif %}
Expand Down
11 changes: 0 additions & 11 deletions src/backend/joanie/core/utils/contract_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from datetime import date, timedelta

from django.conf import settings
from django.contrib.sites.models import Site
from django.utils.duration import duration_iso_string
from django.utils.module_loading import import_string
from django.utils.translation import gettext as _
Expand Down Expand Up @@ -80,15 +79,6 @@ def generate_document_context(contract_definition=None, user=None, order=None):
contract_definition.language if contract_definition else settings.LANGUAGE_CODE
)

try:
site_config = Site.objects.get_current().site_config
except Site.site_config.RelatedObjectDoesNotExist: # pylint: disable=no-member
terms_and_conditions = ""
else:
terms_and_conditions = site_config.get_terms_and_conditions_in_html(
contract_language
)

organization_logo = organization_fallback_logo
organization_name = _("<ORGANIZATION_NAME>")
organization_representative = _("<REPRESENTATIVE>")
Expand Down Expand Up @@ -186,7 +176,6 @@ def generate_document_context(contract_definition=None, user=None, order=None):
"title": contract_title,
"description": contract_description,
"body": contract_body,
"terms_and_conditions": terms_and_conditions,
"language": contract_language,
},
"course": {
Expand Down
1 change: 0 additions & 1 deletion src/backend/joanie/tests/core/api/order/test_abort.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def test_api_order_abort(self, mock_abort_payment):
"product_id": str(product.id),
"course_code": course.code,
"billing_address": billing_address,
"has_consent_to_terms": True,
}
response = self.client.post(
"/api/v1.0/orders/",
Expand Down
Loading

0 comments on commit d1b2e4c

Please sign in to comment.