<commit_before># Copyright 2020 Tecnativa - <NAME>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import json

from odoo import http
from odoo.http import request

from odoo.addons.website_form.controllers.main import WebsiteForm


class WebsiteForm(WebsiteForm):
    def insert_record(self, request, model, values, custom, meta=None):
        res = super().insert_record(request, model, values, custom, meta)
        # Add the customer to the followers, the same as when creating
        # an RMA from a sales order in the portal.
        rma = request.env["rma"].browse(res).sudo()
        rma.message_subscribe([rma.partner_id.id])
        return res


class WebsiteRMA(http.Controller):
    def _get_website_rma_product_domain(self, q):
        """Domain used for the products to be shown in selection of
        the web form.
        """
        return [
            ("name", "=ilike", "%{}%".format(q or "")),
            ("sale_ok", "=", True),
        ]

    @http.route(["/requestrma"], type="http", auth="user", website=True)
    def request_rma(self, **kw):
        return http.request.render("website_rma.request_rma", {})

    @http.route(
        "/website_rma/get_products",
        type="http",
        auth="user",
        methods=["GET"],
        website=True,
    )
    def rma_product_read(self, q="", limit=25, **post):
        data = (
            request.env["product.product"]
            .sudo()
            .search_read(
                domain=self._get_website_rma_product_domain(q),
                fields=["id", "display_name", "uom_id"],
                limit=int(limit),
            )
        )
        return json.dumps(data)<commit_msg>[IMP] *rma*: Avoid RMAs of kits until rma_mrp is installed<commit_after># Copyright 2020 Tecnativa - <NAME>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import json

from odoo import http
from odoo.http import request

from odoo.addons.website_form.controllers.main import WebsiteForm


class WebsiteForm(WebsiteForm):
    def insert_record(self, request, model, values, custom, meta=None):
        res = super().insert_record(request, model, values, custom, meta)
        # Add the customer to the followers, the same as when creating
        # an RMA from a sales order in the portal.
        rma = request.env["rma"].browse(res).sudo()
        rma.message_subscribe([rma.partner_id.id])
        return res


class WebsiteRMA(http.Controller):
    def _get_website_rma_product_domain(self, q):
        """Domain used for the products to be shown in selection of
        the web form.
        """
        domain = [
            ("name", "=ilike", "%{}%".format(q or "")),
            ("sale_ok", "=", True),
        ]
        # HACK: As there is no glue module for this purpose we have put
        # this this condition to check that the mrp module is installed.
        if "bom_ids" in request.env["product.product"]._fields:
            domain += [
                "|",
                ("bom_ids.type", "!=", "phantom"),
                ("bom_ids", "=", False),
            ]
        return domain

    @http.route(["/requestrma"], type="http", auth="user", website=True)
    def request_rma(self, **kw):
        return http.request.render("website_rma.request_rma", {})

    @http.route(
        "/website_rma/get_products",
        type="http",
        auth="user",
        methods=["GET"],
        website=True,
    )
    def rma_product_read(self, q="", limit=25, **post):
        data = (
            request.env["product.product"]
            .sudo()
            .search_read(
                domain=self._get_website_rma_product_domain(q),
                fields=["id", "display_name", "uom_id"],
                limit=int(limit),
            )
        )
        return json.dumps(data)
{'fraction_non_alphanumeric': 0.13410465422035237, 'fraction_numerical': 0.004207204838285564, 'mean_word_length': 2.3107049608355092, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2863922', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1145, 'n_words': 285}