diff --git a/addons/l10n_id_efaktur/models/account_move.py b/addons/l10n_id_efaktur/models/account_move.py index 6f0e645b7bd..0e812017a18 100644 --- a/addons/l10n_id_efaktur/models/account_move.py +++ b/addons/l10n_id_efaktur/models/account_move.py @@ -5,7 +5,7 @@ import base64 import re from odoo import api, fields, models, _ from odoo.exceptions import UserError, ValidationError -from odoo.tools import float_round +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'] @@ -137,6 +137,8 @@ class AccountMove(models.Model): def _generate_efaktur_invoice(self, delimiter): """Generate E-Faktur for customer invoice.""" # Invoice of Customer + dp = self.company_id.currency_id.decimal_places + output_head = '%s%s%s' % ( _csv_row(FK_HEAD_LIST, delimiter), _csv_row(LT_HEAD_LIST, delimiter), @@ -173,15 +175,15 @@ class AccountMove(models.Model): eTax['NAMA'] = move.partner_id.name if eTax['NPWP'] == '000000000000000' else move.partner_id.l10n_id_tax_name or move.partner_id.name eTax['ALAMAT_LENGKAP'] = move.partner_id.contact_address.replace('\n', '') if eTax['NPWP'] == '000000000000000' else move.partner_id.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)) + 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 '' eTax['REFERENSI'] = number_ref eTax['KODE_DOKUMEN_PENDUKUNG'] = '0' lines = move.line_ids.filtered(lambda x: x.move_id._is_downpayment() and x.price_unit < 0 and x.display_type == 'product') eTax['FG_UANG_MUKA'] = 0 - eTax['UANG_MUKA_DPP'] = int(abs(sum(lines.mapped(lambda l: float_round(l.price_subtotal, 0))))) - eTax['UANG_MUKA_PPN'] = int(abs(sum(lines.mapped(lambda l: float_round(l.price_total - l.price_subtotal, 0))))) + eTax['UANG_MUKA_DPP'] = abs(float_round(sum(lines.mapped(lambda l: float_round(l.price_subtotal, 2))), 0)) + eTax['UANG_MUKA_PPN'] = abs(float_round(sum(lines.mapped(lambda l: float_round(l.price_total - l.price_subtotal, 2))), 0)) fk_values_list = ['FK'] + [eTax[f] for f in FK_HEAD_LIST[1:]] @@ -209,10 +211,10 @@ class AccountMove(models.Model): line_dict = { 'KODE_OBJEK': line.product_id.default_code or '', 'NAMA': line.product_id.name or '', - 'HARGA_SATUAN': int(float_round(invoice_line_unit_price, 0)), + 'HARGA_SATUAN': float_repr(float_round(invoice_line_unit_price, dp), dp), 'JUMLAH_BARANG': line.quantity, - 'HARGA_TOTAL': int(float_round(invoice_line_total_price, 0)), - 'DPP': int(float_round(line.price_subtotal, 0)), + 'HARGA_TOTAL': float_repr(float_round(invoice_line_total_price, dp), dp), + 'DPP': float_round(line.price_subtotal, dp), 'product_id': line.product_id.id, } @@ -221,16 +223,16 @@ class AccountMove(models.Model): free_tax_line += (line.price_subtotal * (tax.amount / 100.0)) * -1.0 line_dict.update({ - 'DISKON': int(float_round(invoice_line_total_price - line.price_subtotal, 0)), - 'PPN': int(float_round(free_tax_line, 0)), + 'DISKON': float_round(invoice_line_total_price - line.price_subtotal, dp), + 'PPN': float_round(free_tax_line, dp), }) free.append(line_dict) elif line.price_subtotal != 0.0: invoice_line_discount_m2m = invoice_line_total_price - line.price_subtotal line_dict.update({ - 'DISKON': int(float_round(invoice_line_discount_m2m, 0)), - 'PPN': int(float_round(tax_line, 0)), + 'DISKON': float_round(invoice_line_discount_m2m, dp), + 'PPN': float_round(tax_line, dp), }) sales.append(line_dict) @@ -262,6 +264,13 @@ class AccountMove(models.Model): bruto_total += sale['DISKON'] total_discount += float_round(sale['DISKON'], 2) + # Change the values to string format after being used + sale.update({ + 'DPP': float_repr(sale['DPP'], dp), + 'PPN': float_repr(sale['PPN'], dp), + 'DISKON': float_repr(sale['DISKON'], dp), + }) + output_head += _csv_row(fk_values_list, delimiter) for sale in sales: of_values_list = ['OF'] + [str(sale[f]) for f in OF_HEAD_LIST[1:-2]] + ['0', '0'] diff --git a/addons/l10n_id_efaktur/tests/test_l10n_id_efaktur.py b/addons/l10n_id_efaktur/tests/test_l10n_id_efaktur.py index 85dff914859..93b3922c21f 100644 --- a/addons/l10n_id_efaktur/tests/test_l10n_id_efaktur.py +++ b/addons/l10n_id_efaktur/tests/test_l10n_id_efaktur.py @@ -64,8 +64,8 @@ class TestIndonesianEfaktur(common.TransactionCase): _csv_row(OF_HEAD_LIST, ','), ) # remaining lines - line_4 = '"FK","01","0","0000000000001","5","2019","1/5/2019","12345","l10ntest","","100","10","0","","0","0","0","0","INV/2019/00001 12345","0"\n' - line_5 = '"OF","","","100","1.0","100","0","100","10","0","0"\n' + line_4 = '"FK","01","0","0000000000001","5","2019","1/5/2019","12345","l10ntest","","100","10","0","","0","0.0","0.0","0","INV/2019/00001 12345","0"\n' + line_5 = '"OF","","","100.00","1.0","100.00","0.00","100.00","10.00","0","0"\n' efaktur_csv_expected = output_head + line_4 + line_5 @@ -87,8 +87,8 @@ class TestIndonesianEfaktur(common.TransactionCase): _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","0","0","0","INV/2019/00002 12345","0"\n' - line_5 = '"OF","","","100","400.0","40040","0","40040","4004","0","0"\n' + line_4 = '"FK","01","0","0000000000002","5","2019","1/5/2019","12345","l10ntest","","40040","4004","0","","0","0.0","0.0","0","INV/2019/00002 12345","0"\n' + line_5 = '"OF","","","100.10","400.0","40040.00","0.00","40040.00","4004.00","0","0"\n' efaktur_csv_expected = output_head + line_4 + line_5 self.assertEqual(efaktur_csv_expected, efaktur_csv_output)