<commit_before># Copyright 2017-2018 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF
from datetime import datetime
from odoo.exceptions import Warning
from odoo import fields


class TestAccountCostSpread(AccountingTestCase):

    def setUp(self):
        super(TestAccountCostSpread, self).setUp()
        receivable = self.env.ref('account.data_account_type_receivable')
        expenses = self.env.ref('account.data_account_type_expenses')

        def get_account(obj):
            res = self.env['account.account'].search([
                ('user_type_id', '=', obj.id)
            ], limit=1)
            return res

        self.invoice_account = get_account(receivable)
        self.invoice_line_account = get_account(expenses)

        self.spread_account = self.env['account.account'].search([
            ('user_type_id', '=', expenses.id),
            ('id', '!=', self.invoice_line_account.id)
        ], limit=1).id

        self.partner = self.env['res.partner'].create({
            'name': '<NAME>',
            'supplier': True,
        })
        self.invoice = self.env['account.invoice'].with_context(
            default_type='in_invoice'
        ).create({
            'partner_id': self.partner.id,
            'account_id': self.invoice_account.id,
            'type': 'in_invoice',
        })
        self.invoice_line = self.env['account.invoice.line'].create({
            'quantity': 1.0,
            'price_unit': 1000.0,
            'invoice_id': self.invoice.id,
            'name': 'product that cost 1000',
            'account_id': self.invoice_line_account.id,
            'spread_account_id': self.spread_account,
            'period_number': 12,
            'period_type': 'month',
            'spread_date': '2017-02-01'
        })

        self.invoice_2 = self.env['account.invoice'].with_context(
            default_type='in_invoice'
        ).create({
            'partner_id': self.partner.id,
            'account_id': self.invoice_account.id,
            'type': 'in_invoice',
        })
        self.invoice_line_2 = self.env['account.invoice.line'].create({
            'quantity': 1.0,
            'price_unit': 1000.0,
            'invoice_id': self.invoice_2.id,
            'name': 'product that cost 1000',
            'account_id': self.invoice_line_account.id,
            'spread_account_id': self.spread_account,
            'period_number': 12,
            'period_type': 'month',
            'spread_date': '2017-02-01'
        })

    def test_01_supplier_invoice(self):
        # spread date set
        self.invoice_line.write({
            'period_number': 12,
            'period_type': 'month',
            'spread_date': '2017-02-01'
        })

        # change the state of invoice to open by clicking Validate button
        self.invoice.action_invoice_open()
        self.assertEqual(len(self.invoice_line.spread_line_ids), 12)
        self.assertEqual(81.77, self.invoice_line.spread_line_ids[0].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[1].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[2].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[3].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[4].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[5].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[6].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[7].amount)<commit_msg>Test account_cost_spread<commit_after># Copyright 2017-2018 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF
from datetime import datetime
from odoo.exceptions import Warning
from odoo import fields


class TestAccountCostSpread(AccountingTestCase):

    def setUp(self):
        super(TestAccountCostSpread, self).setUp()
        receivable = self.env.ref('account.data_account_type_receivable')
        expenses = self.env.ref('account.data_account_type_expenses')

        def get_account(obj):
            res = self.env['account.account'].search([
                ('user_type_id', '=', obj.id)
            ], limit=1)
            return res

        self.invoice_account = get_account(receivable)
        self.invoice_line_account = get_account(expenses)

        self.spread_account = self.env['account.account'].search([
            ('user_type_id', '=', expenses.id),
            ('id', '!=', self.invoice_line_account.id)
        ], limit=1).id

        self.partner = self.env['res.partner'].create({
            'name': '<NAME>',
            'supplier': True,
        })
        self.invoice = self.env['account.invoice'].with_context(
            default_type='in_invoice'
        ).create({
            'partner_id': self.partner.id,
            'account_id': self.invoice_account.id,
            'type': 'in_invoice',
        })
        self.invoice_line = self.env['account.invoice.line'].create({
            'quantity': 1.0,
            'price_unit': 1000.0,
            'invoice_id': self.invoice.id,
            'name': 'product that cost 1000',
            'account_id': self.invoice_line_account.id,
            'spread_account_id': self.spread_account,
            'period_number': 12,
            'period_type': 'month',
            'spread_date': '2017-02-01'
        })

        self.invoice_2 = self.env['account.invoice'].with_context(
            default_type='in_invoice'
        ).create({
            'partner_id': self.partner.id,
            'account_id': self.invoice_account.id,
            'type': 'in_invoice',
        })
        self.invoice_line_2 = self.env['account.invoice.line'].create({
            'quantity': 1.0,
            'price_unit': 1000.0,
            'invoice_id': self.invoice_2.id,
            'name': 'product that cost 1000',
            'account_id': self.invoice_line_account.id,
            'spread_account_id': self.spread_account,
            'period_number': 12,
            'period_type': 'month',
            'spread_date': '2017-02-01'
        })

    def test_01_supplier_invoice(self):
        # spread date set
        self.invoice_line.write({
            'period_number': 12,
            'period_type': 'month',
            'spread_date': '2017-02-01'
        })

        # change the state of invoice to open by clicking Validate button
        self.invoice.action_invoice_open()
        self.assertEqual(len(self.invoice_line.spread_line_ids), 12)
        self.assertEqual(83.37, self.invoice_line.spread_line_ids[0].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[1].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[2].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[3].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[4].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[5].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[6].amount)
        self.assertEqual(83.33, self.invoice_line.spread_line_ids[7].amount)
{'fraction_non_alphanumeric': 0.12958731012232827, 'fraction_numerical': 0.02984272079580589, 'mean_word_length': 2.4444444444444446, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '1552071', 'n_tokens_mistral': 2517, 'n_tokens_neox': 2320, 'n_words': 352}