Skip to content

Commit

Permalink
feat(Besoins): pouvoir rattacher un utilisateur à une mise en relation (
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Mar 28, 2024
1 parent 48fa4fe commit a4e2f1f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions lemarche/fixtures/django/11_tender_siaes.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"fields": {
"tender": 1,
"siae": 2653,
"user": 5,
"source": "EMAIL",
"email_send_date": "2021-07-02T12:44:39Z",
"email_link_click_date": "2021-07-02T12:44:39Z",
Expand Down
44 changes: 44 additions & 0 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,48 @@ def get_queryset(self, request):
return qs


class TenderSiaeUserInterestedInline(admin.TabularInline):
model = TenderSiae
verbose_name = "Utilisateur intéressé"
verbose_name_plural = "Utilisateurs intéressés"
fields = [
"id",
"user_full_name",
"user_phone",
"user",
"siae",
"detail_contact_click_date",
]
readonly_fields = [field.name for field in TenderSiae._meta.fields if field.name not in ["transactioned"]] + [
"user_full_name",
"user_phone",
]
extra = 0
show_change_link = True
can_delete = False
classes = ["collapse"]

def has_add_permission(self, request, obj=None):
return False

def get_queryset(self, request):
qs = super().get_queryset(request)
qs = qs.filter(user__isnull=False, detail_contact_click_date__isnull=False)
return qs

def user_full_name(self, obj):
return obj.full_name

user_full_name.admin_order_field = "user_full_name"
user_full_name.short_description = "Prénom Nom"

def user_phone(self, obj):
return obj.phone

user_phone.admin_order_field = "user_phone"
user_phone.short_description = User._meta.get_field("phone").verbose_name


class TenderForm(forms.ModelForm):
class Meta:
model = Tender
Expand Down Expand Up @@ -385,6 +427,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
},
),
TenderSiaeInterestedInline,
TenderSiaeUserInterestedInline,
(
"Transaction ?",
{
Expand Down Expand Up @@ -871,6 +914,7 @@ class TenderSiaeAdmin(admin.ModelAdmin):
"Transaction ?",
{"fields": (*TenderSiae.FIELDS_SURVEY_TRANSACTIONED, "transactioned", "transactioned_source")},
),
("Utilisateur", {"fields": ("user",)}),
("Stats", {"fields": ("logs_display",)}),
("Dates", {"fields": ("created_at", "updated_at")}),
)
Expand Down
26 changes: 26 additions & 0 deletions lemarche/tenders/migrations/0083_tendersiae_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.9 on 2024-03-25 15:37

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("tenders", "0082_tendersiae_transactioned_and_transactioned_source"),
]

operations = [
migrations.AddField(
model_name="tendersiae",
name="user",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to=settings.AUTH_USER_MODEL,
verbose_name="Utilisateur",
),
),
]
3 changes: 3 additions & 0 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,9 @@ class TenderSiae(models.Model):

tender = models.ForeignKey("tenders.Tender", verbose_name="Besoin d'achat", on_delete=models.CASCADE)
siae = models.ForeignKey("siaes.Siae", verbose_name="Structure", on_delete=models.CASCADE)
user = models.ForeignKey(
to=settings.AUTH_USER_MODEL, verbose_name="Utilisateur", null=True, blank=True, on_delete=models.SET_NULL
)

source = models.CharField(
max_length=20,
Expand Down
6 changes: 6 additions & 0 deletions lemarche/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,12 @@ def setUp(cls):
"tendersiae_set-MAX_NUM_FORMS": "1000",
"tendersiae_set-__prefix__-id": "",
"tendersiae_set-__prefix__-text": "",
"tendersiae_set-2-TOTAL_FORMS": "0",
"tendersiae_set-2-INITIAL_FORMS": "0",
"tendersiae_set-2-MIN_NUM_FORMS": "0",
"tendersiae_set-2-MAX_NUM_FORMS": "1000",
"tendersiae_set-2-__prefix__-id": "",
"tendersiae_set-2-__prefix__-text": "",
}
for key, value in cls.form_data.items():
if value is None:
Expand Down

0 comments on commit a4e2f1f

Please sign in to comment.