Skip to content

Commit 221588d

Browse files
committed
[IMP] accountant: Added Test cases and made improvements
With this Commit ================ - Added test cases to ensure functionality and reliability. - Improved the conditional display of the Bill of Entry button by validating the Import-Export setting from the configuration menu. - Refactored and optimized code for better maintainability and performance.
1 parent fb367ac commit 221588d

11 files changed

+113
-26
lines changed

accountant_custom_duty/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import models
22
from . import wizard
3+
from . import tests

accountant_custom_duty/models/account_move.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class AccountMove(models.Model):
55
_inherit = "account.move"
66

77
is_confirmed = fields.Boolean(string="Confirmed", default=False)
8+
l10n_in_custom_duty = fields.Boolean(related="company_id.l10n_in_custom_duty", readonly=False)
89
l10n_in_journal_entry_number = fields.Char(string="Journal Entry Number")
910
l10n_in_company_currency_id = fields.Many2one("res.currency", string="Company Currency ID", default=lambda self: self.env.ref("base.INR"))
1011
l10n_in_custom_currency_rate = fields.Monetary(string="Custom Currency Rate", currency_field="l10n_in_company_currency_id")
@@ -29,7 +30,7 @@ def action_open_wizard(self):
2930
"default_l10n_in_custom_duty_import_journal_id": self.env.company.l10n_in_custom_duty_import_journal_id.id,
3031
"default_l10n_in_account_custom_duty_income_id": self.env.company.l10n_in_account_custom_duty_income_id.id,
3132
"default_l10n_in_import_default_tax_account": self.env.company.l10n_in_import_default_tax_account.id,
32-
"default_l10n_in_custom_duty_tax_payable_account_import": self.env.company.l10n_in_custom_duty_tax_payable_account_import.id,
33+
"default_l10n_in_custom_duty_tax_payable_account": self.env.company.l10n_in_custom_duty_tax_payable_account.id,
3334
"default_l10n_in_shipping_bill_number": self.l10n_in_shipping_bill_number,
3435
"default_l10n_in_shipping_bill_date": self.l10n_in_shipping_bill_date,
3536
"default_l10n_in_shipping_port_code_id": self.l10n_in_shipping_port_code_id,

accountant_custom_duty/models/account_move_bill_of_entry_line.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class AccountMoveBillOfEntryLine(models.Model):
66
_description = "Bill of Entry Line"
77

88
move_id = fields.Many2one("account.move", string="Journal Entry")
9-
l10n_in_company_currency_id = fields.Many2one("res.currency", related="move_id.l10n_in_company_currency_id", string="Company Currency", readonly=True, default=lambda self: self.env.ref("base.INR"))
9+
l10n_in_company_currency_id = fields.Many2one("res.currency", related="move_id.l10n_in_company_currency_id", string="Company Currency", readonly=True)
1010
account_id = fields.Many2one("account.account", string="Account")
1111
label = fields.Char(string="Label")
1212
debit = fields.Monetary(string="Debit", currency_field="l10n_in_company_currency_id")

accountant_custom_duty/models/res_company.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class ResCompany(models.Model):
55
_inherit = "res.company"
66

7-
l10n_in_custom_duty = fields.Boolean(string="Enable Custom Duty")
7+
l10n_in_custom_duty = fields.Boolean(string="Enable Custom Duty", default=False)
88

99
l10n_in_custom_duty_import_journal_id = fields.Many2one(comodel_name="account.journal",string="Import Journal",check_company=True)
1010
l10n_in_account_custom_duty_income_id = fields.Many2one(comodel_name="account.account",string="Import Custom Duty Income Account",check_company=True)
@@ -14,4 +14,4 @@ class ResCompany(models.Model):
1414
l10n_in_account_custom_duty_expense_income_id = fields.Many2one(comodel_name="account.account",string="Export Custom Duty Expense/Income Account",check_company=True)
1515
l10n_in_export_default_tax_account = fields.Many2one(comodel_name="account.account",string="Export Journal Suspense Account",check_company=True)
1616

17-
l10n_in_custom_duty_tax_payable_account_import = fields.Many2one(comodel_name="account.account",string="Custom Duty Tax Payable Account",check_company=True)
17+
l10n_in_custom_duty_tax_payable_account = fields.Many2one(comodel_name="account.account",string="Custom Duty Tax Payable Account",check_company=True)

accountant_custom_duty/models/res_config_settings.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ class ResConfigSettings(models.TransientModel):
55
_inherit = "res.config.settings"
66

77
l10n_in_custom_duty = fields.Boolean(related="company_id.l10n_in_custom_duty", readonly=False, help="Enable Custom Duty.")
8-
l10n_in_custom_duty_tax_payable_account_import = fields.Many2one(comodel_name="account.account", related="company_id.l10n_in_custom_duty_tax_payable_account_import", readonly=False, help="Import and Export tax payable account.")
8+
l10n_in_custom_duty_tax_payable_account = fields.Many2one(comodel_name="account.account", related="company_id.l10n_in_custom_duty_tax_payable_account", readonly=False, help="Import and Export tax payable account.")
99

1010
# Import
1111
l10n_in_custom_duty_import_journal_id = fields.Many2one(comodel_name="account.journal", related="company_id.l10n_in_custom_duty_import_journal_id", readonly=False, help="Journal used for import custom duty.")
12-
l10n_in_account_custom_duty_income_id = fields.Many2one(comodel_name="account.account", related="company_id.l10n_in_account_custom_duty_income_id", readonly=False, domain="[('account_type', '=', 'income')]", help="Import custom duty account.")
12+
l10n_in_account_custom_duty_income_id = fields.Many2one(comodel_name="account.account", related="company_id.l10n_in_account_custom_duty_income_id", readonly=False, domain="[('account_type', '=', 'expense')]", help="Import custom duty account.")
1313
l10n_in_import_default_tax_account = fields.Many2one(comodel_name="account.account", related="company_id.l10n_in_import_default_tax_account", readonly=False, domain="[('reconcile', '=', True), ('deprecated', '=', False), ('account_type', 'in', ('asset_current', 'liability_current'))]", help="Import account which is of type Current Asset or Liability.")
1414

1515
# Export
@@ -21,12 +21,13 @@ class ResConfigSettings(models.TransientModel):
2121
def get_values(self):
2222
res = super().get_values()
2323
company = self.env.company
24+
2425
res.update(
2526
l10n_in_custom_duty=company.l10n_in_custom_duty,
2627
l10n_in_custom_duty_import_journal_id=company.l10n_in_custom_duty_import_journal_id.id,
2728
l10n_in_account_custom_duty_income_id=company.l10n_in_account_custom_duty_income_id.id,
2829
l10n_in_import_default_tax_account=company.l10n_in_import_default_tax_account.id,
29-
l10n_in_custom_duty_tax_payable_account_import=company.l10n_in_custom_duty_tax_payable_account_import.id,
30+
l10n_in_custom_duty_tax_payable_account=company.l10n_in_custom_duty_tax_payable_account.id,
3031
l10n_in_custom_duty_export_journal_id=company.l10n_in_custom_duty_export_journal_id.id,
3132
l10n_in_account_custom_duty_expense_income_id=company.l10n_in_account_custom_duty_expense_income_id.id,
3233
l10n_in_export_default_tax_account=company.l10n_in_export_default_tax_account.id,
@@ -43,7 +44,7 @@ def set_values(self):
4344
"l10n_in_custom_duty_import_journal_id": self.l10n_in_custom_duty_import_journal_id.id,
4445
"l10n_in_account_custom_duty_income_id": self.l10n_in_account_custom_duty_income_id.id,
4546
"l10n_in_import_default_tax_account": self.l10n_in_import_default_tax_account.id,
46-
"l10n_in_custom_duty_tax_payable_account_import": self.l10n_in_custom_duty_tax_payable_account_import.id,
47+
"l10n_in_custom_duty_tax_payable_account": self.l10n_in_custom_duty_tax_payable_account.id,
4748
"l10n_in_custom_duty_export_journal_id": self.l10n_in_custom_duty_export_journal_id.id,
4849
"l10n_in_account_custom_duty_expense_income_id": self.l10n_in_account_custom_duty_expense_income_id.id,
4950
"l10n_in_export_default_tax_account": self.l10n_in_export_default_tax_account.id,
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_account_move
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.")

accountant_custom_duty/views/account_move_views_inherit.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<field name="inherit_id" ref="account.view_move_form"/>
88
<field name="arch" type="xml">
99
<xpath expr="//header" position="inside">
10-
<button name="action_open_wizard" string="Bill of Entry" class="oe_highlight" type="object" invisible="is_confirmed or state != 'posted' or l10n_in_gst_treatment not in ['overseas','special_economic_zone','deemed_export'] or move_type != 'in_invoice'"/>
10+
<button name="action_open_wizard" string="Bill of Entry" class="oe_highlight" type="object" invisible="not l10n_in_custom_duty or is_confirmed or state != 'posted' or l10n_in_gst_treatment not in ['overseas','special_economic_zone','deemed_export', 'in_invoice']"/>
1111
</xpath>
1212
<xpath expr="//sheet/div" position="inside">
1313
<button type="object" class="oe_stat_button" name="action_move_journal_line_bill_of_entry" icon="fa-list" invisible="not is_confirmed">

accountant_custom_duty/views/res_config_settings_views.xml

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@
1010
<setting string="Import-Export" help="Enable this feature to apply custom duty on import/export transactions, including Bill of Entry and Shipping Bills" company_dependent="1">
1111
<field name="l10n_in_custom_duty" class="oe_inline"/>
1212
<div class="content-group" invisible="not l10n_in_custom_duty">
13-
<p class="fw-bolder">Import</p>
13+
<p class="fw-bolder">Import:</p>
1414
<div class="row mt8">
1515
<label for="l10n_in_custom_duty_import_journal_id" class="col-lg-5 o_light_label"/>
16-
<field name="l10n_in_custom_duty_import_journal_id" domain="[('type', '=', 'general'), ('active', '=', True)]"/>
16+
<field name="l10n_in_custom_duty_import_journal_id" domain="[('type', '=', 'general'), ('active', '=', True)]" required="l10n_in_custom_duty"/>
1717
</div>
1818
<div class="row mt8">
1919
<label for="l10n_in_account_custom_duty_income_id" class="col-lg-5 o_light_label"/>
20-
<field name="l10n_in_account_custom_duty_income_id"/>
20+
<field name="l10n_in_account_custom_duty_income_id" required="l10n_in_custom_duty"/>
2121
</div>
2222
<div class="row mt8">
2323
<label for="l10n_in_import_default_tax_account" class="col-lg-5 o_light_label"/>
24-
<field name="l10n_in_import_default_tax_account"/>
24+
<field name="l10n_in_import_default_tax_account" required="l10n_in_custom_duty"/>
2525
</div>
2626

27-
<p class="fw-bolder mt-2">Export</p>
27+
<p class="fw-bolder mt-2">Export:</p>
2828
<div class="row mt8">
2929
<label for="l10n_in_custom_duty_export_journal_id" class="col-lg-5 o_light_label"/>
30-
<field name="l10n_in_custom_duty_export_journal_id" domain="[('type', '=', 'general'), ('active', '=', True)]"/>
30+
<field name="l10n_in_custom_duty_export_journal_id" domain="[('type', '=', 'general'), ('active', '=', True)]" required="l10n_in_custom_duty"/>
3131
</div>
3232
<div class="row mt8">
3333
<label for="l10n_in_account_custom_duty_expense_income_id" class="col-lg-5 o_light_label"/>
34-
<field name="l10n_in_account_custom_duty_expense_income_id"/>
34+
<field name="l10n_in_account_custom_duty_expense_income_id" required="l10n_in_custom_duty"/>
3535
</div>
3636
<div class="row mt8">
3737
<label for="l10n_in_export_default_tax_account" class="col-lg-5 o_light_label"/>
38-
<field name="l10n_in_export_default_tax_account"/>
38+
<field name="l10n_in_export_default_tax_account" required="l10n_in_custom_duty"/>
3939
</div>
4040

41-
<p class="fw-bolder mt-2">Default Tax Account</p>
42-
<div class="row mt8">
43-
<label for="l10n_in_custom_duty_tax_payable_account_import" class="col-lg-5 o_light_label"/>
44-
<field name="l10n_in_custom_duty_tax_payable_account_import"/>
41+
<p class="fw-bolder mt-2">Default Tax Payable Account:</p>
42+
<div class="row">
43+
<label for="l10n_in_custom_duty_tax_payable_account" class="col-lg-5 o_light_label"/>
44+
<field name="l10n_in_custom_duty_tax_payable_account" required="l10n_in_custom_duty"/>
4545
</div>
4646
</div>
4747
</setting>

accountant_custom_duty/wizard/account_bill_of_entry_wizard.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import api, Command, fields, models
1+
from odoo import api, fields, models
22

33

44
class CustomWizard(models.TransientModel):
@@ -10,7 +10,7 @@ class CustomWizard(models.TransientModel):
1010
l10n_in_account_custom_duty_income_id = fields.Many2one(comodel_name="account.account", string="Separate account for income discount")
1111

1212
l10n_in_import_default_tax_account = fields.Many2one("account.account", string="Journal Suspense Account", check_company=True)
13-
l10n_in_custom_duty_tax_payable_account_import = fields.Many2one("account.account", string="Custom Duty Tax Payable Account", check_company=True)
13+
l10n_in_custom_duty_tax_payable_account = fields.Many2one("account.account", string="Custom Duty Tax Payable Account", check_company=True)
1414

1515
l10n_in_company_currency_id = fields.Many2one("res.currency", string="Company Currency ID", default=lambda self: self.env.ref("base.INR"))
1616
l10n_in_custom_currency_rate = fields.Monetary(string="Custom Currency Rate", currency_field="l10n_in_company_currency_id", default=1.0)
@@ -80,7 +80,7 @@ def _compute_journal_items(self):
8080
),
8181
(0,0,
8282
{
83-
"account_id": wizard.env.company.l10n_in_custom_duty_tax_payable_account_import.id,
83+
"account_id": wizard.env.company.l10n_in_custom_duty_tax_payable_account.id,
8484
"label": "Custom Duty Tax Payable Account",
8585
"debit": 0.0,
8686
"credit": wizard.l10n_in_total_amount_payable,
@@ -115,7 +115,7 @@ def default_get(self, fields_list):
115115
defaults["l10n_in_custom_duty_import_journal_id"] = (company.l10n_in_custom_duty_import_journal_id.id)
116116
defaults["l10n_in_account_custom_duty_income_id"] = (company.l10n_in_account_custom_duty_income_id.id)
117117
defaults["l10n_in_import_default_tax_account"] = (company.l10n_in_import_default_tax_account.id)
118-
defaults["l10n_in_custom_duty_tax_payable_account_import"] = (company.l10n_in_custom_duty_tax_payable_account_import.id)
118+
defaults["l10n_in_custom_duty_tax_payable_account"] = (company.l10n_in_custom_duty_tax_payable_account.id)
119119

120120
move_id = self._context.get("default_move_id")
121121
if move_id:

accountant_custom_duty/wizard/account_move_line_wizard.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class AccountMoveLineWizard(models.TransientModel):
66
_description = "Account Move Line Wizard"
77

88
wizard_id = fields.Many2one("account.bill.of.entry.wizard", string="Wizard", required=True, ondelete="cascade")
9-
l10n_in_company_currency_id = fields.Many2one("res.currency", related="wizard_id.l10n_in_company_currency_id", string="Company Currency", readonly=True, default=lambda self: self.env.company.currency_id.id)
9+
l10n_in_company_currency_id = fields.Many2one("res.currency", related="wizard_id.l10n_in_company_currency_id", string="Company Currency", readonly=True)
1010
account_id = fields.Many2one("account.account", string="Account")
1111
label = fields.Char(string="Label")
1212
debit = fields.Monetary(string="Debit", currency_field="l10n_in_company_currency_id")

0 commit comments

Comments
 (0)