<commit_before># Copyright 2015 Akretion (http://www.akretion.com/) - <NAME>
# Copyright 2016 <NAME>. - <NAME>
# Copyright 2017 Tecnativa - <NAME>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models

INV_TYPE_MAP = {
    "out_invoice": "income",
    "out_refund": "income",
    "in_invoice": "expense",
    "in_refund": "expense",
}


class AccountMoveLine(models.Model):
    _inherit = "account.move.line"

    @api.onchange("product_id")
    def _onchange_product_id(self):
        res = super()._onchange_product_id()
        inv_type = self.move_id.move_type
        if self.product_id and inv_type:
            ana_accounts = (
                self.product_id.product_tmpl_id._get_product_analytic_accounts()
            )
            ana_account = ana_accounts[INV_TYPE_MAP[inv_type]]
            self.analytic_account_id = ana_account.id
        return res

    @api.model_create_multi
    def create(self, vals_list):
        for vals in vals_list:
            inv_type = self.env["account.move"].browse([vals.get("move_id")]).move_type
            if (
                vals.get("product_id")
                and inv_type != "entry"
                and not vals.get("analytic_account_id")
            ):
                product = self.env["product.product"].browse(vals.get("product_id"))
                ana_accounts = product.product_tmpl_id._get_product_analytic_accounts()
                ana_account = ana_accounts[INV_TYPE_MAP[inv_type]]<commit_msg>[14.0][IMP] product_analytic: Use onchange multi implementation<commit_after># Copyright 2015 Akretion (http://www.akretion.com/) - <NAME>re
# Copyright 2016 <NAME>. - <NAME>
# Copyright 2017 Tecnativa - <NAME>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models

INV_TYPE_MAP = {
    "out_invoice": "income",
    "out_refund": "income",
    "in_invoice": "expense",
    "in_refund": "expense",
}


class AccountMoveLine(models.Model):
    _inherit = "account.move.line"

    @api.onchange("product_id")
    def _onchange_product_id(self):
        res = super()._onchange_product_id()
        for line in self:
            inv_type = line.move_id.move_type
            if line.product_id and inv_type:
                ana_accounts = (
                    line.product_id.product_tmpl_id._get_product_analytic_accounts()
                )
                ana_account = ana_accounts[INV_TYPE_MAP[inv_type]]
                line.analytic_account_id = ana_account.id
        return res

    @api.model_create_multi
    def create(self, vals_list):
        for vals in vals_list:
            inv_type = self.env["account.move"].browse([vals.get("move_id")]).move_type
            if (
                vals.get("product_id")
                and inv_type != "entry"
                and not vals.get("analytic_account_id")
            ):
                product = self.env["product.product"].browse(vals.get("product_id"))
                ana_accounts = product.product_tmpl_id._get_product_analytic_accounts()
                ana_account = ana_accounts[INV_TYPE_MAP[inv_type]]
{'fraction_non_alphanumeric': 0.11740243122200895, 'fraction_numerical': 0.009916826615483045, 'mean_word_length': 2.4705882352941178, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2479048', 'n_tokens_mistral': 1089, 'n_tokens_neox': 996, 'n_words': 168}