[I18N] website_sale_aplicoop: remove legacy week draft strings

This commit is contained in:
snt 2026-03-31 19:07:43 +02:00
parent ff87243476
commit 813c8071d9
6 changed files with 106 additions and 85 deletions

View file

@ -188,7 +188,9 @@ class AplicoopWebsiteSale(WebsiteSale):
"error_unknown": env_lang._("Unknown error"),
"error_invalid_data": env_lang._("Invalid data provided"),
"error_order_not_found": env_lang._("Order not found"),
"error_no_draft_orders": env_lang._("No draft orders found for this week"),
"error_no_draft_orders": env_lang._(
"No draft orders found for the current order period"
),
"invalid_quantity": env_lang._("Please enter a valid quantity"),
# ============ CONFIRMATION MESSAGES ============
"save_draft_confirm": env_lang._(
@ -207,7 +209,7 @@ class AplicoopWebsiteSale(WebsiteSale):
# ============ DRAFT MODAL LABELS ============
"draft_already_exists": env_lang._("Draft Already Exists"),
"draft_exists_message": env_lang._(
"A saved draft already exists for this week."
"A saved draft already exists for the current order period."
),
"draft_two_options": env_lang._("You have two options:"),
"draft_option1_title": env_lang._("Option 1: Merge with Existing Draft"),
@ -1428,34 +1430,41 @@ class AplicoopWebsiteSale(WebsiteSale):
status=status,
)
def _find_recent_draft_order(self, partner_id, order_id):
"""Find most recent draft sale.order for partner and group_order in current week.
def _find_recent_draft_order(self, partner_id, group_order):
"""Find most recent draft sale.order for partner in the active order period.
Returns the record or empty recordset.
Priority for period matching:
1) If group_order.pickup_date is set, match that exact pickup_date
(prevents reusing stale drafts from previous cycles of same group.order).
2) Fallback to current-week create_date bounds when pickup_date is not set.
Returns the recordset (limit=1) or empty recordset.
"""
from datetime import datetime
from datetime import timedelta
today = datetime.now().date()
start_of_week = today - timedelta(days=today.weekday())
end_of_week = start_of_week + timedelta(days=6)
drafts = (
request.env["sale.order"]
.sudo()
.search(
domain = [
("partner_id", "=", partner_id),
("group_order_id", "=", group_order.id),
("state", "=", "draft"),
]
if group_order.pickup_date:
domain.append(("pickup_date", "=", group_order.pickup_date))
else:
domain.extend(
[
("partner_id", "=", partner_id),
("group_order_id", "=", order_id),
("state", "=", "draft"),
("create_date", ">=", f"{start_of_week} 00:00:00"),
("create_date", "<=", f"{end_of_week} 23:59:59"),
],
order="create_date desc",
limit=1,
]
)
return (
request.env["sale.order"]
.sudo()
.search(domain, order="create_date desc", limit=1)
)
return drafts
@http.route(["/eskaera/<int:order_id>"], type="http", auth="user", website=True)
def eskaera_shop(self, order_id, **post):
@ -2258,7 +2267,7 @@ class AplicoopWebsiteSale(WebsiteSale):
csrf=False,
)
def load_draft_cart(self, **post):
"""Load items from the most recent draft sale.order for this week."""
"""Load items from the most recent draft sale.order for current period."""
import json
try:
@ -2318,16 +2327,18 @@ class AplicoopWebsiteSale(WebsiteSale):
status=400,
)
# Find the most recent draft sale.order for this partner from this week
# The helper _find_recent_draft_order computes the week bounds itself,
# Find the most recent draft sale.order for this partner in active period
# The helper _find_recent_draft_order computes the period criteria itself,
# so we only need to call it here.
# Find the most recent matching draft order using helper
draft_orders = self._find_recent_draft_order(
current_user.partner_id.id, order_id
current_user.partner_id.id, group_order
)
if not draft_orders:
error_msg = request.env._("No draft orders found for this week")
error_msg = request.env._(
"No draft orders found for the current order period"
)
return request.make_response(
json.dumps({"error": error_msg}),
[("Content-Type", "application/json")],
@ -2496,17 +2507,9 @@ class AplicoopWebsiteSale(WebsiteSale):
status=400,
)
# Check if a draft already exists for this group order and user
existing_drafts = (
request.env["sale.order"]
.sudo()
.search(
[
("group_order_id", "=", order_id),
("partner_id", "=", current_user.partner_id.id),
("state", "=", "draft"),
]
)
# Check if a draft already exists for this user in current order period
existing_drafts = self._find_recent_draft_order(
current_user.partner_id.id, group_order
)
_logger.info(
@ -2633,18 +2636,9 @@ class AplicoopWebsiteSale(WebsiteSale):
status=400,
)
# First, check if there's already a draft sale.order for this user in this group order
existing_order = (
request.env["sale.order"]
.sudo()
.search(
[
("partner_id", "=", current_user.partner_id.id),
("group_order_id", "=", group_order.id),
("state", "=", "draft"),
],
limit=1,
)
# Reuse only draft from the current group_order cycle (not stale ones)
existing_order = self._find_recent_draft_order(
current_user.partner_id.id, group_order
)
if existing_order:
@ -2934,7 +2928,7 @@ class AplicoopWebsiteSale(WebsiteSale):
translations = {
"es_ES": {
"Draft Already Exists": "El Borrador Ya Existe",
"A saved draft already exists for this week.": "Un borrador guardado ya existe para esta semana.",
"A saved draft already exists for the current order period.": "Un borrador guardado ya existe para el período actual del pedido.",
"You have two options:": "Tienes dos opciones:",
"Option 1: Merge with Existing Draft": "Opción 1: Fusionar con Borrador Existente",
"Combine your current cart with the existing draft.": "Combina tu carrito actual con el borrador existente.",
@ -2957,7 +2951,7 @@ class AplicoopWebsiteSale(WebsiteSale):
},
"eu_ES": {
"Draft Already Exists": "Zirriborro Dagoeneko Badago",
"A saved draft already exists for this week.": "Gordetako zirriborro bat dagoeneko badago asteburu honetarako.",
"A saved draft already exists for the current order period.": "Gordetako zirriborro bat dagoeneko badago uneko eskaera-aldirako.",
"You have two options:": "Bi aukera dituzu:",
"Option 1: Merge with Existing Draft": "1. Aukera: Existentea Duen Zirriborroarekin Batu",
"Combine your current cart with the existing draft.": "Batu zure gaur-oraingo saskia existentea duen zirriborroarekin.",
@ -2981,7 +2975,7 @@ class AplicoopWebsiteSale(WebsiteSale):
# Also support 'eu' as a variant
"eu": {
"Draft Already Exists": "Zirriborro Dagoeneko Badago",
"A saved draft already exists for this week.": "Gordetako zirriborro bat dagoeneko badago asteburu honetarako.",
"A saved draft already exists for the current order period.": "Gordetako zirriborro bat dagoeneko badago uneko eskaera-aldirako.",
"You have two options:": "Bi aukera dituzu:",
"Option 1: Merge with Existing Draft": "1. Aukera: Existentea Duen Zirriborroarekin Batu",
"Combine your current cart with the existing draft.": "Batu zure gaur-oraingo saskia existentea duen zirriborroarekin.",