[IMP] website_sale_aplicoop: Phase 2 - Refactor eskaera_shop() and add_to_eskaera_cart()
Phase 2 of cyclomatic complexity reduction refactoring. Code Quality Improvements: - eskaera_shop(): 426 → 317 lines (-109 lines, 25.6% reduction) - eskaera_shop(): C901 complexity 42 → 33 (-9 points, 21.4% improvement) - add_to_eskaera_cart(): Refactored to use _resolve_pricelist() - Eliminated duplicate pricelist resolution code (2 instances consolidated) Status: Ready for Phase 3 (confirm_eskaera refactoring)
This commit is contained in:
parent
23e156a13e
commit
8b728b8b7c
2 changed files with 297 additions and 114 deletions
|
|
@ -696,71 +696,17 @@ class AplicoopWebsiteSale(WebsiteSale):
|
|||
|
||||
# Get pricelist and calculate prices with taxes using Odoo's pricelist system
|
||||
_logger.info("eskaera_shop: Starting price calculation for order %d", order_id)
|
||||
pricelist = None
|
||||
pricelist = self._resolve_pricelist()
|
||||
|
||||
# Try to get configured aplicoop pricelist first
|
||||
try:
|
||||
aplicoop_pricelist_id = (
|
||||
request.env["ir.config_parameter"]
|
||||
.sudo()
|
||||
.get_param("website_sale_aplicoop.pricelist_id")
|
||||
# Log pricelist selection status
|
||||
if pricelist:
|
||||
_logger.info(
|
||||
"eskaera_shop: Using pricelist %s (id=%s, currency=%s)",
|
||||
pricelist.name,
|
||||
pricelist.id,
|
||||
pricelist.currency_id.name if pricelist.currency_id else "None",
|
||||
)
|
||||
if aplicoop_pricelist_id:
|
||||
pricelist = request.env["product.pricelist"].browse(
|
||||
int(aplicoop_pricelist_id)
|
||||
)
|
||||
if pricelist.exists():
|
||||
_logger.info(
|
||||
"eskaera_shop: Using configured Aplicoop pricelist: %s (id=%s, currency=%s)",
|
||||
pricelist.name,
|
||||
pricelist.id,
|
||||
pricelist.currency_id.name if pricelist.currency_id else "None",
|
||||
)
|
||||
else:
|
||||
pricelist = None
|
||||
_logger.warning(
|
||||
"eskaera_shop: Configured Aplicoop pricelist (id=%s) not found",
|
||||
aplicoop_pricelist_id,
|
||||
)
|
||||
except Exception as e:
|
||||
_logger.warning(
|
||||
"eskaera_shop: Error getting configured Aplicoop pricelist: %s",
|
||||
str(e),
|
||||
)
|
||||
|
||||
# Fallback to website pricelist
|
||||
if not pricelist:
|
||||
try:
|
||||
pricelist = request.website._get_current_pricelist()
|
||||
_logger.info(
|
||||
"eskaera_shop: Using website pricelist: %s (id=%s, currency=%s)",
|
||||
pricelist.name if pricelist else "None",
|
||||
pricelist.id if pricelist else "None",
|
||||
(
|
||||
pricelist.currency_id.name
|
||||
if pricelist and pricelist.currency_id
|
||||
else "None"
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
_logger.warning(
|
||||
"eskaera_shop: Error getting pricelist from website: %s. Trying default pricelist.",
|
||||
str(e),
|
||||
)
|
||||
|
||||
# Final fallback to any active pricelist
|
||||
if not pricelist:
|
||||
pricelist = request.env["product.pricelist"].search(
|
||||
[("active", "=", True)], limit=1
|
||||
)
|
||||
if pricelist:
|
||||
_logger.info(
|
||||
"eskaera_shop: Using first active pricelist as fallback: %s (id=%s)",
|
||||
pricelist.name,
|
||||
pricelist.id,
|
||||
)
|
||||
|
||||
if not pricelist:
|
||||
else:
|
||||
_logger.error(
|
||||
"eskaera_shop: ERROR - No pricelist found! All prices will use list_price as fallback."
|
||||
)
|
||||
|
|
@ -987,57 +933,8 @@ class AplicoopWebsiteSale(WebsiteSale):
|
|||
)
|
||||
pricelist = None
|
||||
|
||||
# Try to get configured aplicoop pricelist first
|
||||
try:
|
||||
aplicoop_pricelist_id = (
|
||||
request.env["ir.config_parameter"]
|
||||
.sudo()
|
||||
.get_param("website_sale_aplicoop.pricelist_id")
|
||||
)
|
||||
if aplicoop_pricelist_id:
|
||||
pricelist = request.env["product.pricelist"].browse(
|
||||
int(aplicoop_pricelist_id)
|
||||
)
|
||||
if pricelist.exists():
|
||||
_logger.info(
|
||||
"add_to_eskaera_cart: Using configured Aplicoop pricelist: %s (id=%s)",
|
||||
pricelist.name,
|
||||
pricelist.id,
|
||||
)
|
||||
else:
|
||||
pricelist = None
|
||||
except Exception as e:
|
||||
_logger.warning(
|
||||
"add_to_eskaera_cart: Error getting configured Aplicoop pricelist: %s",
|
||||
str(e),
|
||||
)
|
||||
|
||||
# Fallback to website pricelist
|
||||
if not pricelist:
|
||||
try:
|
||||
pricelist = request.website._get_current_pricelist()
|
||||
_logger.info(
|
||||
"add_to_eskaera_cart: Using website pricelist: %s (id=%s)",
|
||||
pricelist.name if pricelist else "None",
|
||||
pricelist.id if pricelist else "None",
|
||||
)
|
||||
except Exception as e:
|
||||
_logger.warning(
|
||||
"add_to_eskaera_cart: Error getting website pricelist: %s",
|
||||
str(e),
|
||||
)
|
||||
|
||||
# Final fallback to any active pricelist
|
||||
if not pricelist:
|
||||
pricelist = request.env["product.pricelist"].search(
|
||||
[("active", "=", True)], limit=1
|
||||
)
|
||||
if pricelist:
|
||||
_logger.info(
|
||||
"add_to_eskaera_cart: Using first active pricelist: %s (id=%s)",
|
||||
pricelist.name,
|
||||
pricelist.id,
|
||||
)
|
||||
# Resolve pricelist using centralized helper
|
||||
pricelist = self._resolve_pricelist()
|
||||
|
||||
if not pricelist:
|
||||
_logger.error(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue