]> git.parisson.com Git - teleforma.git/commitdiff
update register form and add billing
authorYoan Le Clanche <yoanl@pilotsystems.net>
Tue, 27 Jan 2026 13:56:39 +0000 (14:56 +0100)
committerYoan Le Clanche <yoanl@pilotsystems.net>
Tue, 27 Jan 2026 13:56:39 +0000 (14:56 +0100)
teleforma/forms.py
teleforma/migrations/0014_add_lawyer_country_and_billing_address.py [new file with mode: 0644]
teleforma/models/crfpa.py
teleforma/templates/registration/registration_form.html
teleforma/templates/registration/registration_pdf.html

index 57193a9127e081c8adf74d63a95c9fa06c053da5..c411e778bb4bd7c88cc02454aff1e8f9dfa09d55 100644 (file)
@@ -215,6 +215,19 @@ else:
         city = CharField(label=_('City'), max_length=255)
         country = CharField(label=_('Country'), max_length=255)
         telephone = CharField(label=_('Telephone'), max_length=255)
+        lawyer_country = CharField(label='Pays dans lequel vous êtes avocat', max_length=255, required=True)
+        different_billing_address = forms.ChoiceField(
+            choices=[('False', 'Non'), ('True', 'Oui')],
+            label='Adresse de facturation différente ?',
+            widget=forms.RadioSelect(),
+            initial='False',
+            required=False
+        )
+        billing_address = CharField(label='Adresse de facturation', max_length=255, required=False)
+        billing_address_detail = CharField(label='Complément adresse', max_length=255, required=False)
+        billing_postal_code = CharField(label='Code postal', max_length=255, required=False)
+        billing_city = CharField(label='Ville', max_length=255, required=False)
+        billing_country = CharField(label='Pays', max_length=255, required=False)
         # student
         platform_only = forms.ChoiceField(choices = TRUE_FALSE_CHOICES,
                                         label='E-learning uniquement',
@@ -249,9 +262,24 @@ else:
             self.fields['first_name'].required = True
             self.fields['last_name'].required = True
             self.fields['email'].required = True
-            self.user_fields = ['first_name', 'last_name', 'email', 'address', 'address_detail', 'postal_code', 'city', 'country', 'telephone']
+            self.user_fields = ['first_name', 'last_name', 'email', 'address', 'address_detail', 'postal_code', 'city', 'country', 'telephone', 'lawyer_country', 'different_billing_address', 'billing_address', 'billing_address_detail', 'billing_postal_code', 'billing_city', 'billing_country']
             self.training_fields = ['platform_only', 'period', 'training', 'courses']
 
+        def clean(self):
+            cleaned_data = super().clean()
+            different_billing = cleaned_data.get('different_billing_address')
+            if different_billing == 'True':
+                required_billing_fields = {
+                    'billing_address': 'Adresse de facturation',
+                    'billing_postal_code': 'Code postal de facturation',
+                    'billing_city': 'Ville de facturation',
+                    'billing_country': 'Pays de facturation',
+                }
+                for field_name, field_label in required_billing_fields.items():
+                    if not cleaned_data.get(field_name):
+                        self.add_error(field_name, f'{field_label} est obligatoire.')
+            return cleaned_data
+
         def save(self, commit=True):
 
             data = self.cleaned_data
@@ -270,7 +298,13 @@ else:
                             postal_code=data['postal_code'],
                             city=data['city'],
                             country=data['country'],
-                            telephone=data['telephone']
+                            telephone=data['telephone'],
+                            lawyer_country=data.get('lawyer_country'),
+                            billing_address=data.get('billing_address'),
+                            billing_address_detail=data.get('billing_address_detail'),
+                            billing_postal_code=data.get('billing_postal_code'),
+                            billing_city=data.get('billing_city'),
+                            billing_country=data.get('billing_country')
                             )
             if commit:
                 profile.save()
diff --git a/teleforma/migrations/0014_add_lawyer_country_and_billing_address.py b/teleforma/migrations/0014_add_lawyer_country_and_billing_address.py
new file mode 100644 (file)
index 0000000..7b394a5
--- /dev/null
@@ -0,0 +1,43 @@
+# Generated by Django 3.2.25 on 2026-01-27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('teleforma', '0013_auto_20240926_1615'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='profile',
+            name='lawyer_country',
+            field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Pays dans lequel vous êtes avocat'),
+        ),
+        migrations.AddField(
+            model_name='profile',
+            name='billing_address',
+            field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Adresse de facturation'),
+        ),
+        migrations.AddField(
+            model_name='profile',
+            name='billing_address_detail',
+            field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Complément adresse de facturation'),
+        ),
+        migrations.AddField(
+            model_name='profile',
+            name='billing_postal_code',
+            field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Code postal de facturation'),
+        ),
+        migrations.AddField(
+            model_name='profile',
+            name='billing_city',
+            field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Ville de facturation'),
+        ),
+        migrations.AddField(
+            model_name='profile',
+            name='billing_country',
+            field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Pays de facturation'),
+        ),
+    ]
index 4d2dcef66cd742e50889e0cfbdfae14b91ecf25a..a0a69f0345134f7d4b2b583ff9f8377bc1aaa746 100755 (executable)
@@ -227,6 +227,18 @@ class Profile(models.Model):
                                  max_length=15, blank=True, null=True)
     siret = models.CharField('Siret',
                              max_length=13, blank=True, null=True)
+    lawyer_country = models.CharField(
+        'Pays dans lequel vous êtes avocat', max_length=255, blank=True, null=True)
+    billing_address = models.CharField(
+        'Adresse de facturation', max_length=255, blank=True, null=True)
+    billing_address_detail = models.CharField(
+        'Complément adresse de facturation', max_length=255, blank=True, null=True)
+    billing_postal_code = models.CharField(
+        'Code postal de facturation', max_length=255, blank=True, null=True)
+    billing_city = models.CharField(
+        'Ville de facturation', max_length=255, blank=True, null=True)
+    billing_country = models.CharField(
+        'Pays de facturation', max_length=255, blank=True, null=True)
 
     class Meta(MetaCore):
         db_table = app_label + '_' + 'profiles'
index e898d848242dbc0f5a5096303f0469b9bfa337c4..c1eaeedf57352c8c85dd2caf02353ad6c1bfb123 100644 (file)
             $("[name='fascicule']").parent().hide();
     }
 
+    function updateBillingAddress() {
+        var differentBilling = $("[name='different_billing_address']:checked").val() === 'True';
+        var requiredBillingFields = ['billing_address', 'billing_postal_code', 'billing_city', 'billing_country'];
+        var optionalBillingFields = ['billing_address_detail'];
+        var allBillingFields = requiredBillingFields.concat(optionalBillingFields);
+
+        allBillingFields.forEach(function(fieldName) {
+            var fieldContainer = $("[name='" + fieldName + "']").closest('.info_champs');
+            var label = fieldContainer.find('label');
+            if(differentBilling) {
+                fieldContainer.show();
+                // Ajouter l'astérisque pour les champs obligatoires
+                if(requiredBillingFields.indexOf(fieldName) !== -1) {
+                    if(label.find('.required').length === 0) {
+                        label.append('<span class="required">*</span>');
+                    }
+                }
+            } else {
+                fieldContainer.hide();
+                // Retirer l'astérisque
+                label.find('.required').remove();
+            }
+        });
+    }
+
     $(document).ready(function () {
         trainingId = $("#id_training").val();
         updateTrainings();
         $("#id_period,  #id_platform_only").change(updateTrainings);
         updateFascicule();
         $("[name='platform_only']").change(updateFascicule);
+        updateBillingAddress();
+        $("[name='different_billing_address']").change(updateBillingAddress);
     });
 </script>
 <style>
     select {
         width: 222px;
     }
+    #id_different_billing_address {
+        display: flex;
+        gap: 20px;
+    }
+    #id_different_billing_address li {
+        list-style: none;
+        display: flex;
+        align-items: center;
+        gap: 5px;
+    }
+    #id_different_billing_address label {
+        margin: 0;
+        font-weight: normal;
+    }
 </style>
 {% endblock %}
index 470c2837f4b44a44588f2d8684de6742b6f84d0e..1b0b450783eea2e62cda4e3e92f2ce9336281630 100644 (file)
                 </tr>
                 <tr>
                     <td class="bold">{% trans "Address" %} : </td>
-                    <td>{{ profile.address }} {{ profile.postal_code }} {{ profile.city }}, {{ profile.country }}</td>
+                    <td>{{ profile.address }}{% if profile.address_detail %}, {{ profile.address_detail }}{% endif %} {{ profile.postal_code }} {{ profile.city }}, {{ profile.country }}</td>
                 </tr>
+                <tr>
+                    <td class="bold">Pays dans lequel vous êtes avocat : </td>
+                    <td>{{ profile.lawyer_country }}</td>
+                </tr>
+                {% if profile.billing_address %}
+                <tr>
+                    <td class="bold">Adresse de facturation : </td>
+                    <td>{{ profile.billing_address }}{% if profile.billing_address_detail %}, {{ profile.billing_address_detail }}{% endif %} {{ profile.billing_postal_code }} {{ profile.billing_city }}, {{ profile.billing_country }}</td>
+                </tr>
+                {% endif %}
                 <tr>
                     <td class="bold">{% trans "Telephone" %} : </td>
                     <td>{{ profile.telephone }}</td>