<commit_before># © 2019 ForgeFlow S.L.
# © 2019 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError


class StockWarehouse(models.Model):
    _inherit = "stock.warehouse"

    def _default_operating_unit(self):
        if self.company_id:
            company = self.company_id
        else:
            company = self.env.company
        for ou in self.env.user.operating_unit_ids:
            if company == self.company_id:
                self.operating_unit_id = ou

    operating_unit_id = fields.Many2one(
        comodel_name="operating.unit",
        string="Operating Unit",
        default=_default_operating_unit,
    )

    @api.constrains("operating_unit_id", "company_id")
    def _check_company_operating_unit(self):
        for rec in self:
            if (
                rec.operating_unit_id
                and rec.company_id
                and rec.operating_unit_id
                and rec.company_id != rec.operating_unit_id.company_id
            ):
                raise UserError(
                    _(
                        "Configuration error. The Company in the Stock Warehouse"
                        " and in the Operating Unit must be the same."
                    )
                )


class StockWarehouseOrderPoint(models.Model):
    _inherit = "stock.warehouse.orderpoint"

    @api.constrains("operating_unit_id", "warehouse_id", "location_id")
    def _check_location(self):
        for rec in self:
            if (
                rec.warehouse_id.operating_unit_id
                and rec.warehouse_id
                and rec.location_id
                and rec.warehouse_id.operating_unit_id
                != rec.location_id.operating_unit_id
            ):
                raise UserError(
                    _(
                        "Configuration Error. The Operating Unit of the "
                        "Warehouse and the Location must be the same. "<commit_msg>[FIX] stock_operating_unit: fix warning in orderpoint constraint operating_unit_id is not field of model stock.warehouse.orderpoint<commit_after># © 2019 ForgeFlow S.L.
# © 2019 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError


class StockWarehouse(models.Model):
    _inherit = "stock.warehouse"

    def _default_operating_unit(self):
        if self.company_id:
            company = self.company_id
        else:
            company = self.env.company
        for ou in self.env.user.operating_unit_ids:
            if company == self.company_id:
                self.operating_unit_id = ou

    operating_unit_id = fields.Many2one(
        comodel_name="operating.unit",
        string="Operating Unit",
        default=_default_operating_unit,
    )

    @api.constrains("operating_unit_id", "company_id")
    def _check_company_operating_unit(self):
        for rec in self:
            if (
                rec.operating_unit_id
                and rec.company_id
                and rec.operating_unit_id
                and rec.company_id != rec.operating_unit_id.company_id
            ):
                raise UserError(
                    _(
                        "Configuration error. The Company in the Stock Warehouse"
                        " and in the Operating Unit must be the same."
                    )
                )


class StockWarehouseOrderPoint(models.Model):
    _inherit = "stock.warehouse.orderpoint"

    @api.constrains(
        "warehouse_id",
        "location_id",
        "location_id.operating_unit_id",
        "warehouse_id.operating_unit_id",
    )
    def _check_location(self):
        for rec in self:
            if (
                rec.warehouse_id.operating_unit_id
                and rec.warehouse_id
                and rec.location_id
                and rec.warehouse_id.operating_unit_id
                != rec.location_id.operating_unit_id
            ):
                raise UserError(
                    _(
                        "Configuration Error. The Operating Unit of the "
                        "Warehouse and the Location must be the same. "
{'fraction_non_alphanumeric': 0.07349872478553211, 'fraction_numerical': 0.005100857871551124, 'mean_word_length': 1.735573874445149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7311781', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1175, 'n_words': 275}