diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 7170c933b1..0849ce6b64 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -2879,6 +2879,162 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): {'amount_currency': 120.0, 'debit': 60.0, 'credit': 0.0, 'account_id': wizard.revenue_accrual_account.id, 'reconciled': True}, ]) + @freeze_time("2017-01-01") + def test_out_invoice_change_to_future_period_accrual_1(self): + move = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'date': '2017-01-01', + 'partner_id': self.partner_a.id, + 'invoice_date': fields.Date.from_string('2017-01-01'), + 'currency_id': self.currency_data['currency'].id, + 'invoice_payment_term_id': self.pay_terms_a.id, + 'invoice_line_ids': [ + (0, None, { + 'name': self.product_line_vals_1['name'], + 'product_id': self.product_line_vals_1['product_id'], + 'product_uom_id': self.product_line_vals_1['product_uom_id'], + 'quantity': self.product_line_vals_1['quantity'], + 'price_unit': self.product_line_vals_1['price_unit'], + 'tax_ids': self.product_line_vals_1['tax_ids'], + }), + (0, None, { + 'name': self.product_line_vals_2['name'], + 'product_id': self.product_line_vals_2['product_id'], + 'product_uom_id': self.product_line_vals_2['product_uom_id'], + 'quantity': self.product_line_vals_2['quantity'], + 'price_unit': self.product_line_vals_2['price_unit'], + 'tax_ids': self.product_line_vals_2['tax_ids'], + }), + ] + }) + move.action_post() + + wizard = self.env['account.automatic.entry.wizard']\ + .with_context(active_model='account.move.line', active_ids=move.invoice_line_ids.ids).create({ + 'action': 'change_period', + 'date': '2018-01-01', + 'percentage': 60, + 'journal_id': self.company_data['default_journal_misc'].id, + 'expense_accrual_account': self.env['account.account'].create({ + 'name': 'Accrual Expense Account', + 'code': '234567', + 'user_type_id': self.env.ref('account.data_account_type_expenses').id, + 'reconcile': True, + }).id, + 'revenue_accrual_account': self.env['account.account'].create({ + 'name': 'Accrual Revenue Account', + 'code': '765432', + 'user_type_id': self.env.ref('account.data_account_type_expenses').id, + 'reconcile': True, + }).id, + }) + wizard_res = wizard.do_action() + + self.assertInvoiceValues(move, [ + { + **self.product_line_vals_1, + 'currency_id': self.currency_data['currency'].id, + 'amount_currency': -1000.0, + 'debit': 0.0, + 'credit': 500.0, + }, + { + **self.product_line_vals_2, + 'currency_id': self.currency_data['currency'].id, + 'amount_currency': -200.0, + 'debit': 0.0, + 'credit': 100.0, + }, + { + **self.tax_line_vals_1, + 'currency_id': self.currency_data['currency'].id, + 'amount_currency': -180.0, + 'debit': 0.0, + 'credit': 90.0, + }, + { + **self.tax_line_vals_2, + 'currency_id': self.currency_data['currency'].id, + 'amount_currency': -30.0, + 'debit': 0.0, + 'credit': 15.0, + }, + { + **self.term_line_vals_1, + 'currency_id': self.currency_data['currency'].id, + 'name': 'INV/2017/01/0001', + 'amount_currency': 1410.0, + 'debit': 705.0, + 'credit': 0.0, + 'date_maturity': fields.Date.from_string('2017-01-01'), + }, + ], { + **self.move_vals, + 'currency_id': self.currency_data['currency'].id, + 'date': fields.Date.from_string('2017-01-01'), + 'payment_reference': 'INV/2017/01/0001', + }) + + accrual_lines = self.env['account.move'].browse(wizard_res['domain'][0][2]).line_ids.sorted('date') + self.assertRecordValues(accrual_lines, [ + { + 'amount_currency': 600.0, + 'debit': 300.0, + 'credit': 0.0, + 'account_id': self.product_line_vals_1['account_id'], + 'reconciled': False + }, + { + 'amount_currency': -600.0, + 'debit': 0.0, + 'credit': 300.0, + 'account_id': wizard.revenue_accrual_account.id, + 'reconciled': False + }, + { + 'amount_currency': 120.0, + 'debit': 60.0, + 'credit': 0.0, + 'account_id': self.product_line_vals_2['account_id'], + 'reconciled': False + }, + { + 'amount_currency': -120.0, + 'debit': 0.0, + 'credit': 60.0, + 'account_id': wizard.revenue_accrual_account.id, + 'reconciled': False + }, + { + 'amount_currency': -600.0, + 'debit': 0.0, + 'credit': 300.0, + 'account_id': self.product_line_vals_1['account_id'], + 'reconciled': False + }, + { + 'amount_currency': 600.0, + 'debit': 300.0, + 'credit': 0.0, + 'account_id': wizard.revenue_accrual_account.id, + 'reconciled': False + }, + { + 'amount_currency': -120.0, + 'debit': 0.0, + 'credit': 60.0, + 'account_id': self.product_line_vals_2['account_id'], + 'reconciled': False + }, + { + 'amount_currency': 120.0, + 'debit': 60.0, + 'credit': 0.0, + 'account_id': wizard.revenue_accrual_account.id, + 'reconciled': False + }, + ]) + def test_out_invoice_multi_date_change_period_accrual(self): dates = ['2017-01-01', '2017-01-01', '2017-02-01'] values = []