# Copyright 2026 Your Name
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class ProductTemplate(models.Model):
    _inherit = "product.template"

    @api.onchange("sale_ok")
    def _onchange_sale_ok_link_available_in_pos(self):
        for product in self:
            product.available_in_pos = product.sale_ok

    def write(self, vals):
        if "sale_ok" in vals:
            vals["available_in_pos"] = vals["sale_ok"]
        return super().write(vals)


class ProductProduct(models.Model):
    _inherit = "product.product"

    @api.onchange("sale_ok")
    def _onchange_sale_ok_link_available_in_pos(self):
        for product in self:
            product.available_in_pos = product.sale_ok

    def write(self, vals):
        if "sale_ok" in vals:
            vals["available_in_pos"] = vals["sale_ok"]
        return super().write(vals)
