Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDR : add multiple tickets generation #544

Merged
merged 27 commits into from
Sep 7, 2024
Merged

CDR : add multiple tickets generation #544

merged 27 commits into from
Sep 7, 2024

Conversation

Malem38
Copy link
Contributor

@Malem38 Malem38 commented Aug 26, 2024

Description

Please explain the changes you made here.

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the documentation, if necessary

@Malem38 Malem38 force-pushed the feat/generate-tickets branch 6 times, most recently from 183fc8e to 3b37163 Compare August 28, 2024 16:13
Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 57.07317% with 88 lines in your changes missing coverage. Please review.

Project coverage is 81.24%. Comparing base (ad3f599) to head (a64a5ca).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
app/modules/cdr/endpoints_cdr.py 50.98% 75 Missing ⚠️
app/modules/cdr/cruds_cdr.py 48.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #544      +/-   ##
==========================================
- Coverage   81.97%   81.24%   -0.73%     
==========================================
  Files         125      125              
  Lines        9518     9773     +255     
==========================================
+ Hits         7802     7940     +138     
- Misses       1716     1833     +117     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Rotheem Rotheem merged commit 43cef6e into main Sep 7, 2024
7 checks passed
recipient=email.email,
subject=f"Résultats de ventes pour {seller.name}",
content=f"Bonjour,\n\nVous trouverez en pièce jointe le fichier Excel contenant les résultats de ventes pour la CdR pour l'association {seller.name}.",
settings=get_settings(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can not call get_settings directly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

freeze_panes=(2, 3),
engine="xlsxwriter",
)
send_email(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should always call send_email in a background task

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, you might need to look at the endpoint_users.py file, there was quite a few missed, anyway it is fixed for this one

data_fields=product_fields,
users_answers=users_answers,
)
file_path = f"/tmp/CdR {datetime.now(tz=UTC).year} ventes {seller.name}.xlsx" # noqa: S108
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not completely sure if it would work, but S108 looks interesting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't use a temp file as proposed by S108, please place this file in /data/... which is gitignored.
Always use file manipulation utils to access the file system, to prevent injections in filepath

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file creation is done by pandas it does not seem to be compatible

subject: str,
content: str,
settings: "Settings",
file_path: str | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ask for folder name and file uuid, then use file manipulation utils, to prevent access to files outside /data

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from app.core.config import Settings


def send_email(recipient: str, subject: str, content: str, settings: "Settings"):
def send_email(
recipient: str | list[str],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could ask for a list[str] directly instead of allowing str | list[str]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a convenient system which allow to not have inconsistency such as using a list of email when trying to send a personal token, moreover I didn't want to touch the old system

@@ -12,6 +12,7 @@ google-auth-oauthlib==1.2.1
icalendar==5.0.13
jellyfish==1.0.4 # String Matching
Jinja2==3.1.4 # template engine for html files
pandas==2.2.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but I think we could use python list instead of pandas dataframe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to create a ready-to-use excel, added to the fact that it was a way I knew and it took me far less time than finding a new one

@@ -351,6 +355,197 @@ async def get_online_sellers(
return await cruds_cdr.get_online_sellers(db)


def construct_dataframe_from_users_purchases(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the util to app/modules/cdr/utils_cdr.py

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants