[ADD] website_sale_aplicoop: Configurable pricelist for Aplicoop orders
This commit is contained in:
parent
713acd065e
commit
115c9c0cc4
5 changed files with 135 additions and 22 deletions
|
|
@ -504,29 +504,66 @@ 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
|
||||
|
||||
# Try to get configured aplicoop pricelist first
|
||||
try:
|
||||
pricelist = request.website._get_current_pricelist()
|
||||
_logger.info(
|
||||
"eskaera_shop: Pricelist obtained from website: %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"
|
||||
),
|
||||
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(
|
||||
"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 pricelist from website: %s. Trying default pricelist.",
|
||||
"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: Default pricelist found: %s (id=%s)",
|
||||
"eskaera_shop: Using first active pricelist as fallback: %s (id=%s)",
|
||||
pricelist.name,
|
||||
pricelist.id,
|
||||
)
|
||||
|
|
@ -756,24 +793,56 @@ class AplicoopWebsiteSale(WebsiteSale):
|
|||
product.name,
|
||||
product_id,
|
||||
)
|
||||
pricelist = None
|
||||
|
||||
# Try to get configured aplicoop pricelist first
|
||||
try:
|
||||
pricelist = request.website._get_current_pricelist()
|
||||
_logger.info(
|
||||
"add_to_eskaera_cart: Pricelist: %s (id=%s)",
|
||||
pricelist.name if pricelist else "None",
|
||||
pricelist.id if pricelist else "None",
|
||||
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 pricelist: %s. Trying default.",
|
||||
"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: Default pricelist found: %s (id=%s)",
|
||||
"add_to_eskaera_cart: Using first active pricelist: %s (id=%s)",
|
||||
pricelist.name,
|
||||
pricelist.id,
|
||||
)
|
||||
|
|
@ -787,7 +856,6 @@ class AplicoopWebsiteSale(WebsiteSale):
|
|||
product_variant = (
|
||||
product.product_variant_ids[0] if product.product_variant_ids else False
|
||||
)
|
||||
base_price = product.list_price # Fallback
|
||||
|
||||
if product_variant and pricelist:
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue