|
| 1 | +from odoo import fields |
| 2 | +from odoo.tests import tagged, TransactionCase |
| 3 | + |
| 4 | + |
| 5 | +@tagged('post_install', '-at_install') |
| 6 | +class TestAccountMove(TransactionCase): |
| 7 | + def setUp(self): |
| 8 | + super().setUp() |
| 9 | + self.partner_overseas = self.env['res.partner'].create({ |
| 10 | + 'name': 'Overseas Supplier', |
| 11 | + 'l10n_in_gst_treatment': 'overseas', |
| 12 | + }) |
| 13 | + |
| 14 | + self.journal = self.env['account.journal'].search([('type', '=', 'purchase')], limit=1) |
| 15 | + self.expense_account = self.env['account.account'].search([('account_type', '=', 'expense')], limit=1) |
| 16 | + |
| 17 | + self.bill = self.env['account.move'].create({ |
| 18 | + 'move_type': 'in_invoice', |
| 19 | + 'partner_id': self.partner_overseas.id, |
| 20 | + 'invoice_date': fields.Date.today(), |
| 21 | + 'journal_id': self.journal.id, |
| 22 | + 'state': 'draft', |
| 23 | + 'line_ids': [(0, 0, { |
| 24 | + 'name': 'Test Product', |
| 25 | + 'quantity': 1, |
| 26 | + 'price_unit': 1000.0, |
| 27 | + 'account_id': self.expense_account.id, |
| 28 | + })] |
| 29 | + }) |
| 30 | + self.bill.action_post() |
| 31 | + |
| 32 | + def test_action_open_wizard(self): |
| 33 | + """Test that the Bill of Entry Wizard opens with correct context.""" |
| 34 | + action = self.bill.action_open_wizard() |
| 35 | + self.assertEqual(action["res_model"], "account.bill.of.entry.wizard") |
| 36 | + self.assertEqual(action["view_mode"], "form") |
| 37 | + self.assertEqual(action["target"], "new") |
| 38 | + self.assertEqual(action["context"]["default_move_id"], self.bill.id) |
| 39 | + self.assertEqual(action["context"]["default_l10n_in_reference"], self.bill.name) |
| 40 | + |
| 41 | + def test_wizard_computations(self): |
| 42 | + """Test computed fields in Account Move Line Wizard.""" |
| 43 | + self.wizard = self.env['account.bill.of.entry.wizard'].create({ |
| 44 | + 'move_id': self.bill.id, |
| 45 | + 'l10n_in_custom_currency_rate': 1.2, |
| 46 | + }) |
| 47 | + |
| 48 | + self.line = self.env['account.move.line.wizard'].create({ |
| 49 | + 'wizard_id': self.wizard.id, |
| 50 | + 'quantity': 10, |
| 51 | + 'price_unit': 200, |
| 52 | + 'l10n_in_custom_duty_additional': 50, |
| 53 | + 'tax_ids': [(6, 0, self.env['account.tax'].search([('type_tax_use', '=', 'purchase')], limit=1).ids)], |
| 54 | + }) |
| 55 | + |
| 56 | + self.line._compute_l10n_in_assessable_value() |
| 57 | + self.line._compute_l10n_in_taxable_amount() |
| 58 | + self.line._compute_l10n_in_tax_amount() |
| 59 | + |
| 60 | + expected_assessable_value = 10 * 200 * 1.2 |
| 61 | + expected_taxable_amount = expected_assessable_value + 50 |
| 62 | + expected_tax_amount = sum((expected_taxable_amount * tax.amount) / 100 for tax in self.line.tax_ids) |
| 63 | + |
| 64 | + self.assertEqual(self.line.l10n_in_assessable_value, expected_assessable_value, "Assessable Value computation is incorrect.") |
| 65 | + self.assertEqual(self.line.l10n_in_taxable_amount, expected_taxable_amount, "Taxable Amount computation is incorrect.") |
| 66 | + self.assertEqual(self.line.l10n_in_tax_amount, expected_tax_amount, "Total Tax Amount computation is incorrect.") |
| 67 | + |
| 68 | + def test_journal_entry_creation(self): |
| 69 | + """Test that confirming the wizard creates a journal entry.""" |
| 70 | + self.wizard = self.env['account.bill.of.entry.wizard'].create({ |
| 71 | + 'move_id': self.bill.id, |
| 72 | + 'l10n_in_custom_currency_rate': 1.2, |
| 73 | + }) |
| 74 | + |
| 75 | + self.wizard.action_confirm() |
| 76 | + journal_entry = self.env['account.move'].search([ |
| 77 | + ('name', '=', self.bill.name), |
| 78 | + ('journal_id', '=', self.journal.id), |
| 79 | + ('state', '=', 'posted') |
| 80 | + ], limit=1) |
| 81 | + |
| 82 | + self.assertTrue(journal_entry, "Journal entry was not created.") |
| 83 | + self.assertEqual(journal_entry.state, 'posted', "Journal entry is not posted.") |
0 commit comments