Tarification + écran récap avec prix
Config admin : - Tarification activable avec paliers (ex: 1-5 = 0.50€, 6-10 = 0.40€) - Fonction calculate_price() utilitaire Galerie : - Affiche "X impressions — Y.YY €" quand tarification activée Écran impression/récap : - Galerie des photos sélectionnées avec miniatures + quantité (xN) - Prix total en haut - Choix du format d'impression - Bouton IMPRIMER Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -37,6 +37,16 @@ DEFAULT_CONFIG = {
|
||||
"13x18": {"enabled": False, "printer": "", "ratio": 1.385},
|
||||
"15x20": {"enabled": False, "printer": "", "ratio": 1.333},
|
||||
},
|
||||
# Tarification
|
||||
"pricing": {
|
||||
"enabled": True,
|
||||
"currency": "€",
|
||||
"tiers": [
|
||||
{"from": 1, "to": 5, "price": 0.50},
|
||||
{"from": 6, "to": 10, "price": 0.40},
|
||||
{"from": 11, "to": 999, "price": 0.30},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +61,25 @@ def load_config():
|
||||
return dict(DEFAULT_CONFIG)
|
||||
|
||||
|
||||
def calculate_price(quantity, config=None):
|
||||
"""Calcule le prix total pour une quantité donnée selon les paliers."""
|
||||
if config is None:
|
||||
config = load_config()
|
||||
pricing = config.get("pricing", DEFAULT_CONFIG.get("pricing", {}))
|
||||
if not pricing.get("enabled", False) or quantity <= 0:
|
||||
return 0.0
|
||||
tiers = pricing.get("tiers", [])
|
||||
# Trouver le palier applicable
|
||||
unit_price = 0.0
|
||||
for tier in tiers:
|
||||
if tier["from"] <= quantity <= tier["to"]:
|
||||
unit_price = tier["price"]
|
||||
break
|
||||
if unit_price == 0.0 and tiers:
|
||||
unit_price = tiers[-1]["price"]
|
||||
return quantity * unit_price
|
||||
|
||||
|
||||
def save_config(config):
|
||||
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
|
||||
with open(CONFIG_PATH, "w") as f:
|
||||
@@ -235,6 +264,47 @@ class ConfigDialog(QDialog):
|
||||
self.format_widgets[fmt_name] = {"checkbox": cb, "printer": printer}
|
||||
row += 1
|
||||
|
||||
# ── Tarification ──
|
||||
grid.addWidget(self._section_title("Tarification"), row, 0, 1, 2)
|
||||
row += 1
|
||||
|
||||
pricing = self.config.get("pricing", DEFAULT_CONFIG["pricing"])
|
||||
|
||||
grid.addWidget(self._label("Activer :"), row, 0)
|
||||
self.pricing_enabled_cb = QCheckBox("Afficher les prix")
|
||||
self.pricing_enabled_cb.setFont(QFont("", 12))
|
||||
self.pricing_enabled_cb.setChecked(pricing.get("enabled", True))
|
||||
grid.addWidget(self.pricing_enabled_cb, row, 1)
|
||||
row += 1
|
||||
|
||||
self.tier_widgets = []
|
||||
tiers = pricing.get("tiers", [])
|
||||
for i, tier in enumerate(tiers):
|
||||
lbl = QLabel(f"De {tier['from']} à {tier['to']} :")
|
||||
lbl.setFont(QFont("", 12))
|
||||
lbl.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
|
||||
grid.addWidget(lbl, row, 0)
|
||||
|
||||
price_row = QHBoxLayout()
|
||||
from_sb = self._spinbox(tier["from"], 1, 999)
|
||||
to_sb = self._spinbox(tier["to"], 1, 999)
|
||||
price_input = self._input(f"{tier['price']:.2f}", "0.50")
|
||||
price_input.setMaximumWidth(80)
|
||||
price_row.addWidget(QLabel("de"))
|
||||
price_row.addWidget(from_sb)
|
||||
price_row.addWidget(QLabel("à"))
|
||||
price_row.addWidget(to_sb)
|
||||
price_row.addWidget(QLabel("="))
|
||||
price_row.addWidget(price_input)
|
||||
price_row.addWidget(QLabel("€/photo"))
|
||||
|
||||
tier_container = QWidget()
|
||||
tier_container.setLayout(price_row)
|
||||
grid.addWidget(tier_container, row, 1)
|
||||
|
||||
self.tier_widgets.append({"from": from_sb, "to": to_sb, "price": price_input})
|
||||
row += 1
|
||||
|
||||
scroll.setWidget(content)
|
||||
layout.addWidget(scroll, 1)
|
||||
|
||||
@@ -286,6 +356,23 @@ class ConfigDialog(QDialog):
|
||||
formats[fmt_name]["enabled"] = widgets["checkbox"].isChecked()
|
||||
formats[fmt_name]["printer"] = widgets["printer"].text()
|
||||
self.config["formats"] = formats
|
||||
# Tarification
|
||||
tiers = []
|
||||
for tw in self.tier_widgets:
|
||||
try:
|
||||
price = float(tw["price"].text().replace(",", "."))
|
||||
except ValueError:
|
||||
price = 0.0
|
||||
tiers.append({
|
||||
"from": tw["from"].value(),
|
||||
"to": tw["to"].value(),
|
||||
"price": price,
|
||||
})
|
||||
self.config["pricing"] = {
|
||||
"enabled": self.pricing_enabled_cb.isChecked(),
|
||||
"currency": "€",
|
||||
"tiers": tiers,
|
||||
}
|
||||
save_config(self.config)
|
||||
self.accept()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user