[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
|
{ # noqa: B018
|
||||||
"name": "Website Sale - Aplicoop",
|
"name": "Website Sale - Aplicoop",
|
||||||
"version": "18.0.1.0.3",
|
"version": "18.0.1.1.0",
|
||||||
"category": "Website/Sale",
|
"category": "Website/Sale",
|
||||||
"summary": "Modern replacement of legacy Aplicoop - Collaborative consumption group orders",
|
"summary": "Modern replacement of legacy Aplicoop - Collaborative consumption group orders",
|
||||||
"author": "Odoo Community Association (OCA), Criptomart",
|
"author": "Odoo Community Association (OCA), Criptomart",
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
# Vistas
|
# Vistas
|
||||||
"views/group_order_views.xml",
|
"views/group_order_views.xml",
|
||||||
"views/res_partner_views.xml",
|
"views/res_partner_views.xml",
|
||||||
|
"views/res_config_settings_views.xml",
|
||||||
"views/website_templates.xml",
|
"views/website_templates.xml",
|
||||||
"views/product_template_views.xml",
|
"views/product_template_views.xml",
|
||||||
"views/sale_order_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
|
# Get pricelist and calculate prices with taxes using Odoo's pricelist system
|
||||||
_logger.info("eskaera_shop: Starting price calculation for order %d", order_id)
|
_logger.info("eskaera_shop: Starting price calculation for order %d", order_id)
|
||||||
|
pricelist = None
|
||||||
|
|
||||||
|
# Try to get configured aplicoop pricelist first
|
||||||
try:
|
try:
|
||||||
pricelist = request.website._get_current_pricelist()
|
aplicoop_pricelist_id = (
|
||||||
_logger.info(
|
request.env["ir.config_parameter"]
|
||||||
"eskaera_shop: Pricelist obtained from website: %s (id=%s, currency=%s)",
|
.sudo()
|
||||||
pricelist.name if pricelist else "None",
|
.get_param("website_sale_aplicoop.pricelist_id")
|
||||||
pricelist.id if pricelist else "None",
|
|
||||||
(
|
|
||||||
pricelist.currency_id.name
|
|
||||||
if pricelist and 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:
|
except Exception as e:
|
||||||
_logger.warning(
|
_logger.warning(
|
||||||
"eskaera_shop: Error getting pricelist from website: %s. Trying default pricelist.",
|
"eskaera_shop: Error getting configured Aplicoop pricelist: %s",
|
||||||
str(e),
|
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(
|
pricelist = request.env["product.pricelist"].search(
|
||||||
[("active", "=", True)], limit=1
|
[("active", "=", True)], limit=1
|
||||||
)
|
)
|
||||||
if pricelist:
|
if pricelist:
|
||||||
_logger.info(
|
_logger.info(
|
||||||
"eskaera_shop: Default pricelist found: %s (id=%s)",
|
"eskaera_shop: Using first active pricelist as fallback: %s (id=%s)",
|
||||||
pricelist.name,
|
pricelist.name,
|
||||||
pricelist.id,
|
pricelist.id,
|
||||||
)
|
)
|
||||||
|
|
@ -756,24 +793,56 @@ class AplicoopWebsiteSale(WebsiteSale):
|
||||||
product.name,
|
product.name,
|
||||||
product_id,
|
product_id,
|
||||||
)
|
)
|
||||||
|
pricelist = None
|
||||||
|
|
||||||
|
# Try to get configured aplicoop pricelist first
|
||||||
try:
|
try:
|
||||||
pricelist = request.website._get_current_pricelist()
|
aplicoop_pricelist_id = (
|
||||||
_logger.info(
|
request.env["ir.config_parameter"]
|
||||||
"add_to_eskaera_cart: Pricelist: %s (id=%s)",
|
.sudo()
|
||||||
pricelist.name if pricelist else "None",
|
.get_param("website_sale_aplicoop.pricelist_id")
|
||||||
pricelist.id if pricelist else "None",
|
|
||||||
)
|
)
|
||||||
|
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:
|
except Exception as e:
|
||||||
_logger.warning(
|
_logger.warning(
|
||||||
"add_to_eskaera_cart: Error getting pricelist: %s. Trying default.",
|
"add_to_eskaera_cart: Error getting configured Aplicoop pricelist: %s",
|
||||||
str(e),
|
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(
|
pricelist = request.env["product.pricelist"].search(
|
||||||
[("active", "=", True)], limit=1
|
[("active", "=", True)], limit=1
|
||||||
)
|
)
|
||||||
if pricelist:
|
if pricelist:
|
||||||
_logger.info(
|
_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.name,
|
||||||
pricelist.id,
|
pricelist.id,
|
||||||
)
|
)
|
||||||
|
|
@ -787,7 +856,6 @@ class AplicoopWebsiteSale(WebsiteSale):
|
||||||
product_variant = (
|
product_variant = (
|
||||||
product.product_variant_ids[0] if product.product_variant_ids else False
|
product.product_variant_ids[0] if product.product_variant_ids else False
|
||||||
)
|
)
|
||||||
base_price = product.list_price # Fallback
|
|
||||||
|
|
||||||
if product_variant and pricelist:
|
if product_variant and pricelist:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from . import group_order
|
from . import group_order
|
||||||
from . import product_extension
|
from . import product_extension
|
||||||
|
from . import res_config_settings
|
||||||
from . import res_partner_extension
|
from . import res_partner_extension
|
||||||
from . import sale_order_extension
|
from . import sale_order_extension
|
||||||
from . import js_translations
|
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