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

(PC-32783)[BO] feat: extend search reimbursment rules by offerer #15816

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _get_custom_reimbursement_rules(
) -> list[finance_models.CustomReimbursementRule]:
base_query = (
finance_models.CustomReimbursementRule.query.outerjoin(offers_models.Offer)
.outerjoin(offerers_models.Venue)
.outerjoin(offerers_models.Venue, offers_models.Offer.venue)
.outerjoin(offerers_models.Offerer, offerers_models.Venue.managingOfferer)
.options(
sa.orm.joinedload(finance_models.CustomReimbursementRule.offerer).load_only(
Expand Down Expand Up @@ -108,9 +108,11 @@ def _get_custom_reimbursement_rules(
if form.offerer.data:
# search on offererId for custom rules on offerers, on offer's venue's offerer id
# for custom rules on venues and on offer's offerer id for custom rules on offers
base_query = base_query.filter(
aliased_venue = sa.orm.aliased(offerers_models.Venue)
base_query = base_query.outerjoin(aliased_venue, finance_models.CustomReimbursementRule.venue).filter(
sa.or_(
finance_models.CustomReimbursementRule.offererId.in_(form.offerer.data),
aliased_venue.managingOffererId.in_(form.offerer.data),
offerers_models.Venue.managingOffererId.in_(form.offerer.data),
offerers_models.Offerer.id.in_(form.offerer.data),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ <h2 class="fw-light">Tarifs dérogatoires</h2>
</td>
<td>{{ reimbursement_rule.id }}</td>
{% if reimbursement_rule.offerer %}
<td>{{ links.build_offerer_name_to_pc_pro_link(reimbursement_rule.offerer) }}</td>
<td>{{ links.build_offerer_name_to_details_link(reimbursement_rule.offerer) }}</td>
<td>{{ reimbursement_rule.offerer.siren }}</td>
<td></td>
<td></td>
{% elif reimbursement_rule.venue %}
<td>{{ links.build_offerer_name_to_pc_pro_link(reimbursement_rule.venue.managingOfferer) }}</td>
<td>{{ links.build_offerer_name_to_details_link(reimbursement_rule.venue.managingOfferer) }}</td>
<td>{{ reimbursement_rule.venue.managingOfferer.siren }}</td>
<td>{{ links.build_venue_name_to_pc_pro_link(reimbursement_rule.venue, siret=true) }}</td>
<td>{{ links.build_venue_name_to_details_link(reimbursement_rule.venue) }}</td>
<td></td>
{% else %}
<td>{{ links.build_offerer_name_to_pc_pro_link(reimbursement_rule.offer.venue.managingOfferer) }}</td>
<td>{{ links.build_offerer_name_to_details_link(reimbursement_rule.offer.venue.managingOfferer) }}</td>
<td>{{ reimbursement_rule.offer.venue.managingOfferer.siren }}</td>
<td>{{ links.build_venue_name_to_pc_pro_link(reimbursement_rule.offer.venue) }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(reimbursement_rule.offer) }}</td>
<td>{{ links.build_venue_name_to_details_link(reimbursement_rule.offer.venue) }}</td>
<td>{{ links.build_offer_name_to_details_link(reimbursement_rule.offer) }}</td>
{% endif %}
<td>{{ reimbursement_rule.rate | format_rate_multiply_by_100 }}</td>
<td>{{ reimbursement_rule.amount | format_cents if reimbursement_rule.amount else "" }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
def create_industrial_offerer_with_custom_reimbursement_rule() -> None:
logger.info("create_industrial_offerer_with_custom_reimbursement_rule")
offerer = offerers_factories.OffererFactory(name="Structure avec des tarifs dérogatoires")
offerers_factories.VenueFactory(name="Structure avec des tarifs dérogatoires", managingOfferer=offerer)
finance_factories.CustomReimbursementRuleFactory(
offerer=offerer,
subcategories=["FESTIVAL_LIVRE", "FESTIVAL_CINE"],
Expand Down Expand Up @@ -49,4 +50,15 @@ def create_industrial_offerer_with_custom_reimbursement_rule() -> None:
amount=None,
rate=0.9,
)

venue = offerers_factories.VenueFactory(
name="Partenaire avec un tarif dérogatoire", managingOfferer__name="Partenaire avec un tarif dérogatoire"
)
finance_factories.CustomReimbursementRuleFactory(
venue=venue,
timespan=[datetime.datetime.utcnow() - datetime.timedelta(days=10), None],
amount=None,
rate=0.97,
)

logger.info("Created offerer with custom reimbursement rule")
12 changes: 10 additions & 2 deletions api/tests/routes/backoffice/custom_reimbursement_rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_list_custom_reimbursement_rules(self, authenticated_client):
assert rows[1]["ID règle"] == str(venue_rule.id)
assert rows[1]["Entité juridique"] == venue_rule.venue.managingOfferer.name
assert rows[1]["SIREN"] == venue_rule.venue.managingOfferer.siren
assert rows[1]["Lieu"] == f"{venue_rule.venue.name} - {venue_rule.venue.siret}"
assert rows[1]["Lieu"] == venue_rule.venue.name
assert rows[1]["Offre"] == ""
assert rows[1]["Taux de remboursement"] == "98,00 %"
assert rows[1]["Montant remboursé"] == ""
Expand Down Expand Up @@ -164,14 +164,22 @@ def test_list_rules_by_offerer(self, authenticated_client):
finance_factories.CustomReimbursementRuleFactory(offerer=other_offerer)
offer = offers_factories.OfferFactory(venue__managingOfferer=offerer_1)
offerer_rule_3 = finance_factories.CustomReimbursementRuleFactory(offer=offer)
venue_rule = finance_factories.CustomReimbursementRuleFactory(
venue=offerers_factories.VenueFactory(managingOfferer=offerer_1)
)

offerer_ids = [offerer_1.id, offerer_2.id]
with assert_num_queries(self.expected_num_queries + 1):
response = authenticated_client.get(url_for(self.endpoint, offerer=offerer_ids))
assert response.status_code == 200

rows = html_parser.extract_table_rows(response.data)
assert set(int(row["ID règle"]) for row in rows) == {offerer_rule_1.id, offerer_rule_2.id, offerer_rule_3.id}
assert set(int(row["ID règle"]) for row in rows) == {
offerer_rule_1.id,
offerer_rule_2.id,
offerer_rule_3.id,
venue_rule.id,
}

def test_list_rules_more_than_max(self, authenticated_client):
finance_factories.CustomReimbursementRuleFactory.create_batch(30)
Expand Down
Loading