odex25_standard/odex25_donation/ensan_donation_request/models/website.py

28 lines
1.1 KiB
Python

from odoo import models, fields, api
from odoo.http import request
from odoo.osv import expression
import logging
_logger = logging.getLogger(__name__)
class Website(models.Model):
_inherit = 'website'
def sale_product_domain(self):
domain = super().sale_product_domain()
if '/shop' in request.httprequest.full_path:
domain = expression.AND([domain, [('hide_from_shop_front', '=', False)]])
if '/campaigns' in request.httprequest.full_path:
products = request.env['donation.request'].search([('stage_type', '=', 'approve'), ('show_in_most_active_page', '=', True)]).product_id
domain = expression.AND([domain, [('id', 'in', products.ids)]])
params = request.httprequest.args
if params.get('branch'):
try:
branch_id = int(params.get('branch'))
domain = expression.AND([domain, [('department_ids', 'in', [branch_id])]])
except:
_logger.error(f"Invalid branch: {params.get('branch')}")
pass
return domain