[I18N] website_sale_aplicoop: remove legacy week draft strings
This commit is contained in:
parent
ff87243476
commit
813c8071d9
6 changed files with 106 additions and 85 deletions
|
|
@ -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", "=", order_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(
|
||||
[
|
||||
("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.",
|
||||
|
|
|
|||
|
|
@ -240,15 +240,8 @@ msgstr "<span>Día de Recogida</span>"
|
|||
#. module: website_sale_aplicoop
|
||||
#. odoo-python
|
||||
#: code:addons/website_sale_aplicoop/controllers/website_sale.py:0
|
||||
msgid "A draft already exists for this week."
|
||||
msgstr "Ya existe un borrador para esta semana."
|
||||
|
||||
#. module: website_sale_aplicoop
|
||||
#. odoo-python
|
||||
#: code:addons/website_sale_aplicoop/controllers/website_sale.py:0
|
||||
#: code:addons/website_sale_aplicoop/models/js_translations.py:0
|
||||
msgid "A saved draft already exists for this week."
|
||||
msgstr "Ya existe un borrador guardado para esta semana."
|
||||
msgid "A saved draft already exists for the current order period."
|
||||
msgstr "Ya existe un borrador guardado para el período actual del pedido."
|
||||
|
||||
#. module: website_sale_aplicoop
|
||||
#: model_terms:ir.ui.view,arch_db:website_sale_aplicoop.eskaera_shop
|
||||
|
|
@ -914,13 +907,8 @@ msgid ""
|
|||
"orders"
|
||||
msgstr ""
|
||||
|
||||
#. module: website_sale_aplicoop
|
||||
#. odoo-python
|
||||
#: code:addons/website_sale_aplicoop/controllers/website_sale.py:0
|
||||
#: code:addons/website_sale_aplicoop/models/js_translations.py:0
|
||||
#, fuzzy
|
||||
msgid "No draft orders found for this week"
|
||||
msgstr "Ya existe un borrador para esta semana."
|
||||
msgid "No draft orders found for the current order period"
|
||||
msgstr "No se encontraron borradores para el período actual del pedido"
|
||||
|
||||
#. module: website_sale_aplicoop
|
||||
#: model_terms:ir.ui.view,arch_db:website_sale_aplicoop.eskaera_page
|
||||
|
|
|
|||
|
|
@ -241,15 +241,8 @@ msgstr "<span>Biltzeko Lekua:</span>"
|
|||
#. module: website_sale_aplicoop
|
||||
#. odoo-python
|
||||
#: code:addons/website_sale_aplicoop/controllers/website_sale.py:0
|
||||
msgid "A draft already exists for this week."
|
||||
msgstr "Zirriborro bat dagoeneko existitzen da astean honetan."
|
||||
|
||||
#. module: website_sale_aplicoop
|
||||
#. odoo-python
|
||||
#: code:addons/website_sale_aplicoop/controllers/website_sale.py:0
|
||||
#: code:addons/website_sale_aplicoop/models/js_translations.py:0
|
||||
msgid "A saved draft already exists for this week."
|
||||
msgstr "Gordetako zirriborro bat dagoeneko existitzen da astean honetan."
|
||||
msgid "A saved draft already exists for the current order period."
|
||||
msgstr "Gordetako zirriborro bat dagoeneko badago uneko eskaera-aldirako."
|
||||
|
||||
#. module: website_sale_aplicoop
|
||||
#: model_terms:ir.ui.view,arch_db:website_sale_aplicoop.eskaera_shop
|
||||
|
|
@ -913,13 +906,8 @@ msgid ""
|
|||
"orders"
|
||||
msgstr ""
|
||||
|
||||
#. module: website_sale_aplicoop
|
||||
#. odoo-python
|
||||
#: code:addons/website_sale_aplicoop/controllers/website_sale.py:0
|
||||
#: code:addons/website_sale_aplicoop/models/js_translations.py:0
|
||||
#, fuzzy
|
||||
msgid "No draft orders found for this week"
|
||||
msgstr "Zirriborro bat dagoeneko existitzen da astean honetan."
|
||||
msgid "No draft orders found for the current order period"
|
||||
msgstr "Ez da zirriborrorik aurkitu uneko eskaera-aldirako"
|
||||
|
||||
#. module: website_sale_aplicoop
|
||||
#: model_terms:ir.ui.view,arch_db:website_sale_aplicoop.eskaera_page
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ def _register_translations():
|
|||
# Draft Modal Labels
|
||||
# ========================
|
||||
_("Draft Already Exists")
|
||||
_("A saved draft already exists for this week.")
|
||||
_("A saved draft already exists for the current order period.")
|
||||
_("You have two options:")
|
||||
_("Option 1: Merge with Existing Draft")
|
||||
_("Combine your current cart with the existing draft.")
|
||||
|
|
@ -89,7 +89,7 @@ def _register_translations():
|
|||
# Error Messages
|
||||
# ========================
|
||||
_("Error: Order ID not found")
|
||||
_("No draft orders found for this week")
|
||||
_("No draft orders found for the current order period")
|
||||
_("Connection error")
|
||||
_("Error loading order")
|
||||
_("Error loading draft")
|
||||
|
|
|
|||
|
|
@ -1015,7 +1015,7 @@
|
|||
all_categories: "All categories",
|
||||
// Draft modal labels
|
||||
draft_already_exists: "Draft Already Exists",
|
||||
draft_exists_message: "A saved draft already exists for this week.",
|
||||
draft_exists_message: "A saved draft already exists for the current order period.",
|
||||
draft_two_options: "You have two options:",
|
||||
draft_option1_title: "Option 1: Merge with Existing Draft",
|
||||
draft_option1_desc: "Combine your current cart with the existing draft.",
|
||||
|
|
|
|||
|
|
@ -667,3 +667,54 @@ class TestConfirmEskaera_Integration(TransactionCase):
|
|||
existing_order.invalidate_recordset()
|
||||
self.assertEqual(len(existing_order.order_line), 1)
|
||||
self.assertEqual(existing_order.order_line[0].product_uom_qty, 5)
|
||||
|
||||
@patch("odoo.http.request")
|
||||
def test_confirm_eskaera_ignores_old_period_draft(self, mock_request):
|
||||
"""Old draft from previous pickup_date must not be reused."""
|
||||
mock_request.env = self.env.with_user(self.user)
|
||||
mock_request.env.lang = "es_ES"
|
||||
mock_request.httprequest = Mock()
|
||||
|
||||
old_draft = self.env["sale.order"].create(
|
||||
{
|
||||
"partner_id": self.partner.id,
|
||||
"group_order_id": self.group_order.id,
|
||||
"state": "draft",
|
||||
"pickup_date": date.today() - timedelta(days=7),
|
||||
"order_line": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"product_id": self.product.id,
|
||||
"product_uom_qty": 1,
|
||||
"price_unit": 20.0,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
data = {
|
||||
"order_id": self.group_order.id,
|
||||
"items": [
|
||||
{
|
||||
"product_id": self.product.id,
|
||||
"quantity": 4,
|
||||
"product_price": 20.0,
|
||||
}
|
||||
],
|
||||
"is_delivery": False,
|
||||
}
|
||||
|
||||
mock_request.httprequest.data = json.dumps(data).encode("utf-8")
|
||||
|
||||
response = self.controller.confirm_eskaera()
|
||||
response_data = json.loads(response.data.decode("utf-8"))
|
||||
|
||||
self.assertTrue(response_data.get("success"))
|
||||
self.assertNotEqual(response_data["sale_order_id"], old_draft.id)
|
||||
|
||||
old_draft.invalidate_recordset()
|
||||
self.assertEqual(old_draft.state, "draft")
|
||||
self.assertEqual(old_draft.order_line[0].product_uom_qty, 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue