Skip to content

Commit 3d83648

Browse files
Added tests
added PR #565 integration #578
1 parent d200c06 commit 3d83648

6 files changed

Lines changed: 144 additions & 8 deletions

File tree

l10n_it_withholding_tax/i18n/it.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ msgstr "Errore! I tassi sono obbligatori"
174174
#: code:addons/l10n_it_withholding_tax/models/withholding_tax.py:139
175175
#, python-format
176176
msgid ""
177-
"Error! You cannot have 2 pricelist versions that overlap!"
177+
"Error! You cannot have 2 rates that overlap!"
178178
msgstr "Errore! I periodi si sovrappongono"
179179

180180
#. module: l10n_it_withholding_tax

l10n_it_withholding_tax/i18n/l10n_it_withholding_tax.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ msgstr ""
164164
#. module: l10n_it_withholding_tax
165165
#: code:addons/l10n_it_withholding_tax/models/withholding_tax.py:139
166166
#, python-format
167-
msgid "Error! You cannot have 2 pricelist versions that overlap!"
167+
msgid "Error! You cannot have 2 rates that overlap!"
168168
msgstr ""
169169

170170
#. module: l10n_it_withholding_tax

l10n_it_withholding_tax/models/account.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,14 @@ def _prepare_price_unit(self, line):
469469
(1 - (line.discount or 0.0) / 100.0)
470470
return price_unit
471471

472-
@api.depends('base', 'tax')
472+
@api.depends('base', 'tax', 'invoice_id.amount_untaxed')
473473
def _compute_coeff(self):
474474
for inv_wt in self:
475475
if inv_wt.invoice_id.amount_untaxed:
476-
inv_wt.base_coeff = round(
477-
inv_wt.base / inv_wt.invoice_id.amount_untaxed, 5)
476+
inv_wt.base_coeff = \
477+
inv_wt.base / inv_wt.invoice_id.amount_untaxed
478478
if inv_wt.base:
479-
inv_wt.tax_coeff = round(inv_wt.tax / inv_wt.base, 5)
479+
inv_wt.tax_coeff = inv_wt.tax / inv_wt.base
480480

481481
invoice_id = fields.Many2one('account.invoice', string='Invoice',
482482
ondelete="cascade")

l10n_it_withholding_tax/models/withholding_tax.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ def _check_date(self):
134134
self.id))
135135
if self.env.cr.fetchall():
136136
raise ValidationError(
137-
_('Error! You cannot have 2 pricelist versions that \
138-
overlap!'))
137+
_('Error! You cannot have 2 rates that overlap!'))
139138

140139
withholding_tax_id = fields.Many2one('withholding.tax',
141140
string='Withholding Tax',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_withholding_tax
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
2+
from odoo.tests.common import TransactionCase
3+
import time
4+
5+
6+
class TestWithholdingTax(TransactionCase):
7+
8+
def setUp(self):
9+
super(TestWithholdingTax, self).setUp()
10+
11+
# Accounts
12+
type_payable = self.env.ref('account.data_account_type_payable')
13+
type_receivable = self.env.ref('account.data_account_type_receivable')
14+
self.wt_account_payable = self.env['account.account'].create({
15+
'name': 'Debiti per ritenute da versare',
16+
'code': 'WT_001',
17+
'user_type_id': type_payable.id,
18+
'reconcile': True,
19+
})
20+
self.wt_account_receivable = self.env['account.account'].create({
21+
'name': 'Crediti per ritenute subite',
22+
'code': 'WT_002',
23+
'user_type_id': type_receivable.id,
24+
'reconcile': True,
25+
})
26+
27+
# Journals
28+
self.journal_misc = self.env['account.journal'].search(
29+
[('type', '=', 'general')])[0]
30+
self.journal_bank = self.env['account.journal'].create(
31+
{'name': 'Bank', 'type': 'bank', 'code': 'BNK67'})
32+
33+
# Payments
34+
vals_payment = {
35+
'name': "",
36+
'line_ids': [(0, 0, {'value': 'balance', 'days': 15})]
37+
}
38+
self.payment_term_15 = self.env['account.payment.term'].create(
39+
vals_payment)
40+
41+
# Withholding tax
42+
wt_vals = {
43+
'name': 'Code 1040',
44+
'code': '1040',
45+
'certification': True,
46+
'account_receivable_id': self.wt_account_receivable.id,
47+
'account_payable_id': self.wt_account_payable.id,
48+
'journal_id': self.journal_misc.id,
49+
'payment_term': self.payment_term_15.id,
50+
'rate_ids': [(0, 0, {
51+
'tax': 20,
52+
'base': 1,
53+
})]
54+
}
55+
self.wt1040 = self.env['withholding.tax'].create(wt_vals)
56+
57+
# Supplier Invoice with WT
58+
invoice_vals = [
59+
(0, 0, {
60+
'quantity': 1.0,
61+
'account_id': self.env['account.account'].search(
62+
[('user_type_id', '=', self.env.ref(
63+
'account.data_account_type_expenses').id)],
64+
limit=1).id,
65+
'name': 'Advice',
66+
'price_unit': 1000.00,
67+
'invoice_line_tax_wt_ids': [(6, 0, [self.wt1040.id])]
68+
})]
69+
self.invoice = self.env['account.invoice'].create({
70+
'name': "Test Supplier Invoice WT",
71+
'journal_id': self.env['account.journal'].search(
72+
[('type', '=', 'purchase')])[0].id,
73+
'partner_id': self.env.ref('base.res_partner_12').id,
74+
'account_id': self.env['account.account'].search(
75+
[('user_type_id', '=', self.env.ref(
76+
'account.data_account_type_receivable').id)],
77+
limit=1, order='id').id,
78+
'invoice_line_ids': invoice_vals,
79+
})
80+
self.invoice._onchange_invoice_line_wt_ids()
81+
self.invoice.action_invoice_open()
82+
83+
def test_creation_withholding_tax(self):
84+
domain = [('name', '=', 'Code 1040')]
85+
wts = self.env['withholding.tax'].search(domain)
86+
self.assertEqual(len(wts), 1, msg="Withholding tax was not created")
87+
88+
def test_invoice_values(self):
89+
self.assertEqual(
90+
self.invoice.withholding_tax_amount, 200, msg='Invoice WT amount')
91+
self.assertEqual(
92+
self.invoice.amount_net_pay, 800, msg='Invoice WT amount net pay')
93+
94+
def test_creation_statement(self):
95+
domain = [('invoice_id', '=', self.invoice.id),
96+
('withholding_tax_id', '=', self.wt1040.id)]
97+
wt_statement = self.env['withholding.tax.statement'].search(domain)
98+
self.assertEqual(
99+
len(wt_statement), 1, msg='WT statement was not created')
100+
self.assertEqual(
101+
wt_statement.base, 1000, msg='WT statement Base amount')
102+
self.assertEqual(
103+
wt_statement.amount, 0, msg='WT statement amount applied')
104+
self.assertEqual(
105+
wt_statement.amount_paid, 0, msg='WT statement Base paid')
106+
107+
def test_invoice_payment(self):
108+
ctx = {
109+
'active_model': 'account.invoice',
110+
'active_ids': [self.invoice.id],
111+
}
112+
register_payments = self.env['account.register.payments']\
113+
.with_context(ctx).create({
114+
'payment_date': time.strftime('%Y') + '-07-15',
115+
'amount': 800,
116+
'journal_id': self.journal_bank.id,
117+
'payment_method_id': self.env.ref(
118+
"account.account_payment_method_manual_out").id,
119+
})
120+
register_payments.create_payments()
121+
122+
# WT payment generation
123+
self.assertEqual(
124+
len(self.invoice.payment_move_line_ids), 2,
125+
msg='Missing WT payment')
126+
127+
# WT amount in account move
128+
wt_line = self.invoice.payment_move_line_ids.filtered(
129+
lambda r: r.account_id.id == self.wt_account_payable.id)
130+
self.assertEqual(wt_line.debit, 200, msg='WT amount payment')
131+
132+
# WT aomunt applied in statement
133+
domain = [('invoice_id', '=', self.invoice.id),
134+
('withholding_tax_id', '=', self.wt1040.id)]
135+
wt_statement = self.env['withholding.tax.statement'].search(domain)
136+
self.assertEqual(wt_statement.amount, 200)

0 commit comments

Comments
 (0)