<commit_before># Copyright (C) 2014 Forest and Biomass Romania
# Copyright (C) 2020 NextERP Romania
# Copyright (C) 2020 Terrabit
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models


class StockValuationLayer(models.Model):
    _inherit = "stock.valuation.layer"

    valued_type = fields.Char()
    invoice_line_id = fields.Many2one("account.move.line", string="Invoice Line")
    invoice_id = fields.Many2one("account.move", string="Invoice")
    account_id = fields.Many2one(
        "account.account", compute="_compute_account", store=True
    )

    @api.depends("product_id", "account_move_id")
    def _compute_account(self):
        for svl in self:
            account = self.env["account.account"]
            if not svl.account_move_id:
                loc_dest = svl.stock_move_id.location_dest_id
                loc_scr = svl.stock_move_id.location_id
                account = (
                    svl.product_id.property_stock_valuation_account_id
                    or svl.product_id.categ_id.property_stock_valuation_account_id
                )
                if svl.value > 0 and loc_dest.property_stock_valuation_account_id:
                    account = loc_dest.property_stock_valuation_account_id
                if svl.value < 0 and loc_scr.property_stock_valuation_account_id:
                    account = loc_scr.property_stock_valuation_account_id
            else:
                for aml in svl.account_move_id.line_ids:
                    if aml.account_id.code[0] in ["2", "3"]:
                        if aml.balance <= 0 and svl.value <= 0:
                            account = aml.account_id
                            break
                        if aml.balance > 0 and svl.value > 0:
                            account = aml.account_id
                            break
            svl.account_id = account

    def init(self):
        """This method will compute values for valuation layer valued_type"""
        val_layers = self.search(
            ["|", ("valued_type", "=", False), ("valued_type", "=", "")]
        )
        val_types = self.env["stock.move"]._get_valued_types()
        val_types = [<commit_msg>Add company in svl compute account<commit_after># Copyright (C) 2014 Forest and Biomass Romania
# Copyright (C) 2020 NextERP Romania
# Copyright (C) 2020 Terrabit
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models


class StockValuationLayer(models.Model):
    _inherit = "stock.valuation.layer"

    valued_type = fields.Char()
    invoice_line_id = fields.Many2one("account.move.line", string="Invoice Line")
    invoice_id = fields.Many2one("account.move", string="Invoice")
    account_id = fields.Many2one(
        "account.account", compute="_compute_account", store=True
    )

    @api.depends("product_id", "account_move_id")
    def _compute_account(self):
        for svl in self:
            account = self.env["account.account"]
            svl = svl.with_company(svl.stock_move_id.company_id)
            if not svl.account_move_id:
                loc_dest = svl.stock_move_id.location_dest_id
                loc_scr = svl.stock_move_id.location_id
                account = (
                    svl.product_id.property_stock_valuation_account_id
                    or svl.product_id.categ_id.property_stock_valuation_account_id
                )
                if svl.value > 0 and loc_dest.property_stock_valuation_account_id:
                    account = loc_dest.property_stock_valuation_account_id
                if svl.value < 0 and loc_scr.property_stock_valuation_account_id:
                    account = loc_scr.property_stock_valuation_account_id
            else:
                for aml in svl.account_move_id.line_ids:
                    if aml.account_id.code[0] in ["2", "3"]:
                        if aml.balance <= 0 and svl.value <= 0:
                            account = aml.account_id
                            break
                        if aml.balance > 0 and svl.value > 0:
                            account = aml.account_id
                            break
            svl.account_id = account

    def init(self):
        """This method will compute values for valuation layer valued_type"""
        val_layers = self.search(
            ["|", ("valued_type", "=", False), ("valued_type", "=", "")]
        )
        val_types = self.env["stock.move"]._get_valued_types()
        val_types = [
{'fraction_non_alphanumeric': 0.09452296819787986, 'fraction_numerical': 0.011484098939929329, 'mean_word_length': 1.9796052631578946, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '131695', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1306, 'n_words': 267}