Skip to content

Commit

Permalink
manage lots
Browse files Browse the repository at this point in the history
  • Loading branch information
kolok committed Feb 3, 2025
1 parent 23fd1a1 commit 779ab7e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions siap/siap_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,26 @@ def get_or_create_lots_and_conventions(
return (lots, conventions)


def _create_convention(programme: Programme, user: User):
(convention, _) = Convention.objects.exclude(
statut=ConventionStatut.ANNULEE.label,
).get_or_create(
programme=programme,
# When comes from SIAP through API, the user doesn't exist in DB
defaults={
"cree_par": (user if user.id else None),
},
def _create_convention(programme: Programme, financement: str, user: User):

conventions = Convention.objects.filter(
programme=programme, lots__financement=financement
)
convention = None
if conventions.count() == 0:
convention = Convention.objects.create(
programme=programme,
financement=financement,
)
elif conventions.count() == 1:
convention = conventions.first()
else:
raise Exception(
"More than one convention found for the same programme/financement"
)

# When convention was created by SIAP through API and the user doesn't exist
# the forst user how access it will be the creator
# the first user how access it will be the creator
if convention.cree_par is None and user.id is not None:
convention.cree_par = user
convention.save()
Expand Down

0 comments on commit 779ab7e

Please sign in to comment.