Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] l10n_id_efaktur: NPWP and NIK #163707

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 23 additions & 7 deletions addons/l10n_id_efaktur/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import base64
import re
from odoo import api, fields, models, _
from odoo.exceptions import UserError, ValidationError
from odoo.exceptions import UserError, ValidationError, RedirectWarning
from odoo.tools import float_round, float_repr

FK_HEAD_LIST = ['FK', 'KD_JENIS_TRANSAKSI', 'FG_PENGGANTI', 'NOMOR_FAKTUR', 'MASA_PAJAK', 'TAHUN_PAJAK', 'TANGGAL_FAKTUR', 'NPWP', 'NAMA', 'ALAMAT_LENGKAP', 'JUMLAH_DPP', 'JUMLAH_PPN', 'JUMLAH_PPNBM', 'ID_KETERANGAN_TAMBAHAN', 'FG_UANG_MUKA', 'UANG_MUKA_DPP', 'UANG_MUKA_PPN', 'UANG_MUKA_PPNBM', 'REFERENSI', 'KODE_DOKUMEN_PENDUKUNG']
Expand Down Expand Up @@ -153,18 +153,34 @@ def _generate_efaktur_invoice(self, delimiter):

if move.l10n_id_replace_invoice_id:
number_ref = str(move.l10n_id_replace_invoice_id.name) + " replaced by " + str(move.name) + " " + nik
else:
elif nik:
number_ref = str(move.name) + " " + nik
else:
number_ref = str(move.name)

street = ', '.join([x for x in (move.partner_id.street, move.partner_id.street2) if x])

invoice_npwp = '000000000000000'
if commercial_partner.vat and len(commercial_partner.vat) >= 12:
invoice_npwp = ''
if commercial_partner.vat and len(commercial_partner.vat) >= 15:
nni-odoo marked this conversation as resolved.
Show resolved Hide resolved
invoice_npwp = commercial_partner.vat
elif (not commercial_partner.vat or len(commercial_partner.vat) < 12) and commercial_partner.l10n_id_nik:
elif commercial_partner.l10n_id_nik:
invoice_npwp = commercial_partner.l10n_id_nik
if not invoice_npwp:
action_error = {
'view_mode': 'form',
'res_model': 'res.partner',
'type': 'ir.actions.act_window',
'res_id': commercial_partner.id,
'views': [[self.env.ref('base.view_partner_form').id, 'form']],
}
msg = _("Please make sure that you've input the appropriate NPWP or NIK for the following customer")
raise RedirectWarning(msg, action_error, _("Edit Customer Information"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :) during the forward port (in 17.2, or just master to make it easier) you can simplify this

Suggested change
raise RedirectWarning(msg, action_error, _("Edit Customer Information"))
raise RedirectWarning(
msg,
commercial_partner._get_records_action(),
_("Edit Customer Information")
)

_get_records_action can take as args whatever you would like to add to the action.
By default, it will dynamically set the view_mode based on the amount of records in self.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, will keep note of this!

invoice_npwp = invoice_npwp.replace('.', '').replace('-', '')

etax_name = commercial_partner.l10n_id_tax_name or move.partner_id.name
nni-odoo marked this conversation as resolved.
Show resolved Hide resolved
if invoice_npwp[:15] == '000000000000000' and commercial_partner.l10n_id_nik:
etax_name = "%s#NIK#NAMA#%s" % (commercial_partner.l10n_id_nik, etax_name)

# Here all fields or columns based on eTax Invoice Third Party
eTax['KD_JENIS_TRANSAKSI'] = move.l10n_id_tax_number[0:2] or 0
eTax['FG_PENGGANTI'] = move.l10n_id_tax_number[2:3] or 0
Expand All @@ -173,8 +189,8 @@ def _generate_efaktur_invoice(self, delimiter):
eTax['TAHUN_PAJAK'] = move.invoice_date.year
eTax['TANGGAL_FAKTUR'] = '{0}/{1}/{2}'.format(move.invoice_date.day, move.invoice_date.month, move.invoice_date.year)
eTax['NPWP'] = invoice_npwp
eTax['NAMA'] = move.partner_id.name if eTax['NPWP'] == '000000000000000' else commercial_partner.l10n_id_tax_name or move.partner_id.name
eTax['ALAMAT_LENGKAP'] = move.partner_id.contact_address.replace('\n', '') if eTax['NPWP'] == '000000000000000' else commercial_partner.l10n_id_tax_address or street
eTax['NAMA'] = etax_name
eTax['ALAMAT_LENGKAP'] = move.partner_id.contact_address.replace('\n', '').strip() if eTax['NPWP'] == '000000000000000' else commercial_partner.l10n_id_tax_address or street
eTax['JUMLAH_DPP'] = int(float_round(move.amount_untaxed, 0)) # currency rounded to the unit
eTax['JUMLAH_PPN'] = int(float_round(move.amount_tax, 0, rounding_method="DOWN")) # tax amount ALWAYS rounded down
eTax['ID_KETERANGAN_TAMBAHAN'] = '1' if move.l10n_id_kode_transaksi == '07' else ''
Expand Down
81 changes: 78 additions & 3 deletions addons/l10n_id_efaktur/tests/test_l10n_id_efaktur.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from odoo.tests import tagged, common
from odoo.addons.l10n_id_efaktur.models.account_move import FK_HEAD_LIST, LT_HEAD_LIST, OF_HEAD_LIST, _csv_row
from odoo.exceptions import RedirectWarning

@tagged('post_install', '-at_install', 'post_install_l10n')
class TestIndonesianEfaktur(common.TransactionCase):
Expand All @@ -17,7 +18,8 @@ def setUp(self):
self.env.company.street = "test"
self.env.company.phone = "12345"

self.partner_id = self.env['res.partner'].create({"name": "l10ntest", "l10n_id_pkp": True, "l10n_id_kode_transaksi": "01", "l10n_id_nik": "12345"})
self.partner_id = self.env['res.partner'].create({"name": "l10ntest", "l10n_id_pkp": True, "l10n_id_kode_transaksi": "01", "l10n_id_nik": "12345", "vat": "000000000000000"})
self.partner_id_vat = self.env['res.partner'].create({"name": "l10ntest3", "l10n_id_pkp": True, "l10n_id_kode_transaksi": "01", "l10n_id_nik": "67890", "vat": "010000000000000"})
nni-odoo marked this conversation as resolved.
Show resolved Hide resolved
self.tax_id = self.env['account.tax'].create({"name": "test tax", "type_tax_use": "sale", "amount": 10.0, "price_include": True})

self.efaktur = self.env['l10n_id_efaktur.efaktur.range'].create({'min': '0000000000001', 'max': '0000000000010'})
Expand Down Expand Up @@ -59,7 +61,7 @@ def test_efaktur_csv_output_1(self):
_csv_row(OF_HEAD_LIST, ','),
)
# remaining lines
line_4 = '"FK","01","0","0000000000001","5","2019","1/5/2019","12345","l10ntest","","100","10","0","","0","110","0","0","INV/2019/00001 12345","0"\n'
line_4 = '"FK","01","0","0000000000001","5","2019","1/5/2019","000000000000000","12345#NIK#NAMA#l10ntest","","100","10","0","","0","110","0","0","INV/2019/00001","0"\n'
line_5 = '"OF","","","100","1.0","100","0","100","10","0","0"\n'

efaktur_csv_expected = output_head + line_4 + line_5
Expand All @@ -82,7 +84,80 @@ def test_efaktur_csv_output_decimal_place(self):
_csv_row(LT_HEAD_LIST, ','),
_csv_row(OF_HEAD_LIST, ','),
)
line_4 = '"FK","01","0","0000000000002","5","2019","1/5/2019","12345","l10ntest","","40040","4004","0","","0","44044","0","0","INV/2019/00002 12345","0"\n'
line_4 = '"FK","01","0","0000000000002","5","2019","1/5/2019","000000000000000","12345#NIK#NAMA#l10ntest","","40040","4004","0","","0","44044","0","0","INV/2019/00002","0"\n'
line_5 = '"OF","","","100","400.0","40040","0","40040","4004","0","0"\n'

efaktur_csv_expected = output_head + line_4 + line_5
self.assertEqual(efaktur_csv_expected, efaktur_csv_output)

def test_efaktur_use_vat(self):
""" Test to ensure that the e-faktur uses the VAT on NPWP column of efaktur when
VAT is non-zeros """
out_invoice = self.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': self.partner_id_vat.id,
'invoice_date': '2019-05-01',
'date': '2019-05-01',
'invoice_line_ids': [
(0, 0, {'name': 'line1', 'price_unit': 110.11, 'quantity': 400, 'tax_ids': self.tax_id.ids})
],
'l10n_id_kode_transaksi': '01'
})
out_invoice.action_post()
efaktur_csv_output = out_invoice._generate_efaktur_invoice(',')
output_head = '%s%s%s' % (
_csv_row(FK_HEAD_LIST, ','),
_csv_row(LT_HEAD_LIST, ','),
_csv_row(OF_HEAD_LIST, ','),
)
line_4 = '"FK","01","0","0000000000003","5","2019","1/5/2019","010000000000000","l10ntest3","","40040","4004","0","","0","44044","0","0","INV/2019/00003","0"\n'
line_5 = '"OF","","","100","400.0","40040","0","40040","4004","0","0"\n'

efaktur_csv_expected = output_head + line_4 + line_5
self.assertEqual(efaktur_csv_expected, efaktur_csv_output)

def test_efaktur_no_vat_nik(self):
""" Test to ensure that when no VAT and NIK is supplied, a RedirectWarning should be raised """
partner_no_vat_nik = self.env['res.partner'].create({"name": "l10ntest4", "l10n_id_pkp": True, "l10n_id_kode_transaksi": "01"})
out_invoice = self.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': partner_no_vat_nik.id,
'invoice_date': '2019-05-01',
'date': '2019-05-01',
'invoice_line_ids': [
(0, 0, {'name': 'line1', 'price_unit': 110.11, 'quantity': 400, 'tax_ids': self.tax_id.ids})
],
'l10n_id_kode_transaksi': '01'
})
out_invoice.action_post()
with self.assertRaises(RedirectWarning):
out_invoice._generate_efaktur_invoice(',')

def test_efaktur_nik_with_no_vat(self):
""" Test to ensure if there is contact has no VAT but has NIK

NPWP would contain NIK, NAMA contains customer's name, REFERENSI would contain invoice name with customer's NIK"""

partner_nik_no_vat = self.env['res.partner'].create({"name": "l10ntest4", "l10n_id_pkp": True, "l10n_id_kode_transaksi": "01", "l10n_id_nik": "1532167"})
out_invoice = self.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': partner_nik_no_vat.id,
'invoice_date': '2019-05-01',
'date': '2019-05-01',
'invoice_line_ids': [
(0, 0, {'name': 'line1', 'price_unit': 110.11, 'quantity': 400, 'tax_ids': self.tax_id.ids})
],
'l10n_id_kode_transaksi': '01'
})
out_invoice.action_post()

efaktur_csv_output = out_invoice._generate_efaktur_invoice(',')
output_head = '%s%s%s' % (
_csv_row(FK_HEAD_LIST, ','),
_csv_row(LT_HEAD_LIST, ','),
_csv_row(OF_HEAD_LIST, ','),
)
line_4 = '"FK","01","0","0000000000003","5","2019","1/5/2019","1532167","l10ntest4","","40040","4004","0","","0","44044","0","0","INV/2019/00003 1532167","0"\n'
line_5 = '"OF","","","100","400.0","40040","0","40040","4004","0","0"\n'

efaktur_csv_expected = output_head + line_4 + line_5
Expand Down