[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
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
{ # noqa: B018
|
||||
"name": "Website Sale - Aplicoop",
|
||||
"version": "18.0.1.0.3",
|
||||
"version": "18.0.1.1.0",
|
||||
"category": "Website/Sale",
|
||||
"summary": "Modern replacement of legacy Aplicoop - Collaborative consumption group orders",
|
||||
"author": "Odoo Community Association (OCA), Criptomart",
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
# Vistas
|
||||
"views/group_order_views.xml",
|
||||
"views/res_partner_views.xml",
|
||||
"views/res_config_settings_views.xml",
|
||||
"views/website_templates.xml",
|
||||
"views/product_template_views.xml",
|
||||
"views/sale_order_views.xml",
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from . import group_order
|
||||
from . import product_extension
|
||||
from . import res_config_settings
|
||||
from . import res_partner_extension
|
||||
from . import sale_order_extension
|
||||
from . import js_translations
|
||||
|
||||
|
|
|
|||
15
website_sale_aplicoop/models/res_config_settings.py
Normal file
15
website_sale_aplicoop/models/res_config_settings.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright 2026 Criptomart
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
|
||||
from odoo import fields
|
||||
from odoo import models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
aplicoop_pricelist_id = fields.Many2one(
|
||||
"product.pricelist",
|
||||
config_parameter="website_sale_aplicoop.pricelist_id",
|
||||
help="Pricelist to use for Aplicoop group orders. If not set, will use website default.",
|
||||
)
|
||||
29
website_sale_aplicoop/views/res_config_settings_views.xml
Normal file
29
website_sale_aplicoop/views/res_config_settings_views.xml
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">res.config.settings.view.form.inherit.aplicoop</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="inherit_id" ref="website_sale.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@id='website_sale_pricelist_setting']" position="after">
|
||||
<h2>Aplicoop Settings</h2>
|
||||
<div class="row mt16 o_settings_container">
|
||||
<div class="col-12 col-lg-6 o_setting_box">
|
||||
<div class="o_setting_left_pane"/>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="aplicoop_pricelist_id"/>
|
||||
<div class="text-muted">
|
||||
Pricelist used for Aplicoop group orders
|
||||
</div>
|
||||
<div class="content-group">
|
||||
<div class="mt16">
|
||||
<field name="aplicoop_pricelist_id" class="oe_inline"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue