Skip to content

Commit

Permalink
[FIX] test script and description
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Jan 30, 2024
1 parent db2488e commit f25cc23
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 103 deletions.
2 changes: 1 addition & 1 deletion l10n_th_bank_payment_export_scb/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Thai Localization - Bank Payment Export SCB
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:943a58eeed4dbee4a948ea32296b3531adf01de802475d8de1ccb24d9b6cd395
!! source digest: sha256:909aa8de96a8c17169bd882ae101813eb7f83391fcf3dc94c57272ae1c53977f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
Expand Down
6 changes: 5 additions & 1 deletion l10n_th_bank_payment_export_scb/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"license": "AGPL-3",
"category": "Localization / Accounting",
"summary": "Bank Payment Export File SCB",
"depends": ["account_check_payee", "l10n_th_bank_payment_export"],
"depends": [
"account_check_payee",
"l10n_th_bank_payment_export",
"partner_address_street3",
],
"data": [
"data/report_action.xml",
"views/bank_payment_export_view.xml",
Expand Down
223 changes: 125 additions & 98 deletions l10n_th_bank_payment_export_scb/models/bank_payment_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,11 +856,13 @@ def _get_wht_header(self, wht_cert):
sum(wht_cert.wht_line.mapped("amount"))
)
text = "{wht_type}{wht_running_no}{wht_attach_no}{wht_line}{total_wht}".format(
wht_type=wht_type,
wht_running_no="".ljust(14), # NOTE: Bank will generate
wht_attach_no="0".zfill(6), # NOTE: Bank will generate
wht_line=str(len(wht_cert.wht_line)).zfill(2),
total_wht=total_wht,
wht_type=wht_type, # 70-71
# NOTE: Bank will generate
wht_running_no="".ljust(14), # 72-85
# NOTE: Bank will generate
wht_attach_no="0".zfill(6), # 86-91
wht_line=str(len(wht_cert.wht_line)).zfill(2), # 92-93
total_wht=total_wht, # 94-109
)
return text

Expand All @@ -872,9 +874,10 @@ def _get_wht_header2(self, wht_cert):
"paid_one_time": "1",
}
text = "{pay_type}{wht_remark}{wht_deduct_date}".format(
pay_type=mapping_tax_payer.get(wht_cert.tax_payer),
wht_remark="".ljust(40), # NOTE: System is not type 4
wht_deduct_date=wht_cert.date.strftime("%Y%m%d"),
pay_type=mapping_tax_payer.get(wht_cert.tax_payer), # 132-132
# NOTE: System is not type 4
wht_remark="".ljust(40), # 133-172
wht_deduct_date=wht_cert.date.strftime("%Y%m%d"), # 173-180
)
return text

Expand All @@ -885,8 +888,8 @@ def _get_invoice_header(self, invoices):
sum(invoices.mapped("amount_total"))
)
text = "{invoice_count}{invoice_total_amount}".format(
invoice_count=str(len(invoices)).zfill(6),
invoice_total_amount=invoice_total_amount,
invoice_count=str(len(invoices)).zfill(6), # 110-115
invoice_total_amount=invoice_total_amount, # 116-131
)
return text

Expand Down Expand Up @@ -964,13 +967,14 @@ def _get_text_header_scb(self):
file_date = today.strftime("%Y%m%d")
file_time = today.strftime("%H%M%S")
text = (
"001{scb_company}{customer_ref}{file_date}{file_time}BCM"
"001{scb_company}{customer_ref}{file_date}{file_time}{channel_id}"
"{batch_reference}\r\n".format(
scb_company=scb_company_id.ljust(12),
customer_ref=self._get_reference().ljust(32),
file_date=file_date,
file_time=file_time,
batch_reference=self._get_reference().ljust(32),
scb_company=scb_company_id.ljust(12), # 4-15
customer_ref=self._get_reference().ljust(32), # 16-47
file_date=file_date, # 48-55
file_time=file_time, # 56-61
channel_id="BCM", # 62-64
batch_reference=self._get_reference().ljust(32), # 65-96
)
)
return text
Expand All @@ -983,26 +987,28 @@ def _get_text_company_detail_scb(self, payment_lines, total_batch_amount, idx=1)
].payment_journal_id.bank_account_id.acc_number
sanitize_account_bank_payment = sanitize_account_number(account_bank_payment)
if not sanitize_account_bank_payment:
sanitize_account_bank_payment = "-------------------------"
sanitize_account_bank_payment = "-----------" # default 11 digits
account_type = "0{}".format(sanitize_account_bank_payment[3])
branch_code = "0{}".format(sanitize_account_bank_payment[0:3])
text = (
"002{product_code}{value_date}{debit_account_no}{account_type_debit_account}"
"{debit_branch_code}THB{debit_amount}{internal_ref}{no_credit}{debit_fee_account}"
"{filler}{mcl_type}{account_type_fee}{debit_fee_branch_code}\r\n".format(
product_code=self.scb_product_code,
value_date=self.effective_date.strftime("%Y%m%d"),
debit_account_no=sanitize_account_bank_payment.ljust(25),
account_type_debit_account=account_type,
debit_branch_code=branch_code,
debit_amount=total_batch_amount,
internal_ref=str(idx).zfill(8),
no_credit=str(self._get_line_count(payment_lines)).zfill(6),
debit_fee_account=sanitize_account_bank_payment.ljust(15),
filler="".ljust(9),
mcl_type=self._get_mcl_type(),
account_type_fee=account_type.zfill(2),
debit_fee_branch_code=branch_code.zfill(4),
"{debit_branch_code}{currency_name}{debit_amount}{internal_ref}{no_credit}"
"{debit_fee_account}{filler}{mcl_type}{account_type_fee}"
"{debit_fee_branch_code}\r\n".format(
product_code=self.scb_product_code, # 4-6
value_date=self.effective_date.strftime("%Y%m%d"), # 7-14
debit_account_no=sanitize_account_bank_payment.ljust(25), # 15-39
account_type_debit_account=account_type, # 40-41
debit_branch_code=branch_code, # 42-45
currency_name="THB", # 46-48
debit_amount=total_batch_amount, # 49-64
internal_ref=str(idx).zfill(8), # 65-72
no_credit=str(self._get_line_count(payment_lines)).zfill(6), # 73-78
debit_fee_account=sanitize_account_bank_payment.ljust(15), # 79-93
filler="".ljust(9), # 94-102
mcl_type=self._get_mcl_type(), # 103-103
account_type_fee=account_type.zfill(2), # 104-105
debit_fee_branch_code=branch_code.zfill(4), # 106-109
)
)
return text, idx
Expand All @@ -1022,43 +1028,51 @@ def _get_text_credit_detail_scb(
receiver_bank_code = "014"
receiver_bank_name = "SCB"
receiver_branch_code = "0111"
# Direct Cheque don't use account number
if self.scb_product_code != "DCP":
receiver_acc_number = ""
text = (
"003{idx}{credit_account}{credit_amount}THB{internal_ref}{wht_present}"
"003{idx}{credit_account}{credit_amount}{currency_name}{internal_ref}{wht_present}"
"{invoice_detail_present}{credit_advice_required}{delivery_mode}"
"{pickup_location}{wht_header}{invoice_number}{wht_header2}"
"{receiver_bank_code}{receiver_bank_name}{receiver_branch_code}"
"{receiver_branch_name}{wht_signatory}{notification}{customer_ref}"
"{cheque_ref}{payment_type_code}{service_type}{remark}"
"{scb_remark}{charge}\r\n".format(
idx=str(idx).zfill(6),
credit_account=receiver_acc_number.ljust(25),
credit_amount=line_batch_amount,
internal_ref=str(internal_ref).zfill(8),
wht_present="Y" if self.scb_is_wht_present and wht_cert else "N",
invoice_detail_present="Y"
idx=str(idx).zfill(6), # 4-9
credit_account=receiver_acc_number.ljust(25), # 10-34
credit_amount=line_batch_amount, # 35-50
currency_name="THB", # 51-53
internal_ref=str(internal_ref).zfill(8), # 54-61
wht_present="Y"
if self.scb_is_wht_present and wht_cert
else "N", # 62-62
invoice_detail_present="Y" # 63-63
if self.scb_is_invoice_present and invoices
else "N",
credit_advice_required="Y" if self.scb_is_credit_advice else "N",
delivery_mode=self.scb_delivery_mode,
pickup_location=self._get_pickup_location(),
wht_header=self._get_wht_header(wht_cert), # WHT Form Type - Total WHT
invoice_number=self._get_invoice_header(invoices),
wht_header2=self._get_wht_header2(wht_cert), # Pay Type - Deduct Date
receiver_bank_code=receiver_bank_code,
receiver_bank_name=self._get_scb_bank_name(receiver_bank_name),
receiver_branch_code=receiver_branch_code,
receiver_branch_name=(receiver_branch_code or "").ljust(35),
wht_signatory=self.scb_wht_signatory,
notification=pe_line.scb_beneficiary_noti,
customer_ref=pe_line.payment_id.name.ljust(20),
cheque_ref=self.scb_cheque_ref or "".ljust(1),
payment_type_code=self.scb_payment_type_code or "".ljust(3),
service_type=self._get_service_type() or "".ljust(2),
remark=(self.scb_remark or "").ljust(50),
scb_remark="".ljust(18),
charge="B " if pe_line.scb_beneficiary_charge else " ",
credit_advice_required="Y"
if self.scb_is_credit_advice
else "N", # 64-64
delivery_mode=self.scb_delivery_mode or " ", # 65-65
pickup_location=self._get_pickup_location(), # 66-69
wht_header=self._get_wht_header(wht_cert), # 70-109
invoice_number=self._get_invoice_header(invoices), # 110-131
wht_header2=self._get_wht_header2(wht_cert), # 132-180
receiver_bank_code=receiver_bank_code, # 181-183
receiver_bank_name=self._get_scb_bank_name(
receiver_bank_name
), # 184-218
receiver_branch_code=receiver_branch_code, # 219-222
receiver_branch_name=(receiver_branch_code or "").ljust(35), # 223-257
wht_signatory=self.scb_wht_signatory, # 258-258
notification=pe_line.scb_beneficiary_noti, # 259-259
customer_ref=pe_line.payment_id.name.ljust(20), # 260-279
cheque_ref=self.scb_cheque_ref or "".ljust(1), # 280-280
payment_type_code=self.scb_payment_type_code or "".ljust(3), # 281-283
service_type=self._get_service_type() or "".ljust(2), # 284-285
remark=(self.scb_remark or "").ljust(50), # 286-335
scb_remark="".ljust(18), # 336-353
charge="B " if pe_line.scb_beneficiary_charge else " ", # 354-355
)
)
return text
Expand All @@ -1073,17 +1087,20 @@ def _get_text_payee_detail_scb(self, idx, pe_line, line_batch_amount, internal_r
"004{internal_ref}{idx}{payee_idcard}{payee_name}"
"{payee_address}{payee_tax_id}{payee_name_eng}{payee_fax}{payee_sms}"
"{payee_email}{space}\r\n".format(
internal_ref=str(internal_ref).zfill(8),
idx=str(idx).zfill(6),
payee_idcard=str(pe_line.payment_partner_id.vat or "").ljust(15),
payee_name=receiver_name.ljust(100),
payee_address=address,
payee_tax_id="".ljust(10),
payee_name_eng=self._get_payee_name_eng(pe_line).ljust(70),
payee_fax=pe_line._get_payee_fax().zfill(10),
payee_sms=pe_line._get_payee_sms().zfill(10),
payee_email=(pe_line._get_payee_email() or "").ljust(64),
space="".ljust(310), # TODO Payee2
internal_ref=str(internal_ref).zfill(8), # 4-11
idx=str(idx).zfill(6), # 12-17
payee_idcard=str(pe_line.payment_partner_id.vat or "").ljust(
15
), # 18-32
payee_name=receiver_name.ljust(100), # 33-132
payee_address=address, # 133-342
payee_tax_id="".ljust(10), # 343-352
payee_name_eng=self._get_payee_name_eng(pe_line).ljust(70), # 353-422
payee_fax=pe_line._get_payee_fax().zfill(10), # 423-432
payee_sms=pe_line._get_payee_sms().zfill(10), # 433-442
payee_email=(pe_line._get_payee_email() or "").ljust(64), # 443-506
# TODO Payee2 do not implement yet.
space="".ljust(310), # 507-816
)
)
return text
Expand All @@ -1096,14 +1113,16 @@ def _get_text_wht_detail_scb(self, idx, sequence_wht, wht_line, internal_ref):
"005{internal_ref}{idx}{wht_sequence}{wht_amount}"
"{wht_income_type}{wht_income_description}{wht_deduct_rate}"
"{wht_base_amount}\r\n".format(
internal_ref=str(internal_ref).zfill(8),
idx=str(idx).zfill(6),
wht_sequence=str(sequence_wht).zfill(2),
wht_amount=wht_amount,
wht_income_type=wht_income_type.ljust(5),
wht_income_description=wht_line.wht_cert_income_desc.ljust(80),
wht_deduct_rate=str(abs(int(wht_line.wht_percent))).zfill(2),
wht_base_amount=wht_base_amount,
internal_ref=str(internal_ref).zfill(8), # 4-11
idx=str(idx).zfill(6), # 12-17
wht_sequence=str(sequence_wht).zfill(2), # 18-19
wht_amount=wht_amount, # 20-35
wht_income_type=wht_income_type.ljust(5), # 36-40
wht_income_description=wht_line.wht_cert_income_desc.ljust(
80
), # 41-120
wht_deduct_rate=str(abs(int(wht_line.wht_percent))).zfill(2), # 121-122
wht_base_amount=wht_base_amount, # 123-138
)
)
return text
Expand All @@ -1113,38 +1132,46 @@ def _get_text_invoice_detail_scb(
):
inv_amount_untaxed = self._get_scb_amount_no_decimal(inv.amount_untaxed)
inv_amount_tax = self._get_scb_amount_no_decimal(inv.amount_tax)
purchase = inv.invoice_line_ids.mapped("purchase_line_id.order_id")
# Get withholding tax from invoice lines
wht_lines = inv.invoice_line_ids.filtered("wht_tax_id")
amount_wht = wht_lines._get_wht_amount(
self.env.company.currency_id, pe_line.payment_date
)[1]
# Check install module purchase
purchase = False
if hasattr(inv.invoice_line_ids, "purchase_line_id"):
purchase = inv.invoice_line_ids.mapped("purchase_line_id.order_id")
# Check install module l10n_th_account_tax (not required)
wht_lines = False
amount_wht = 0.0
if hasattr(inv.invoice_line_ids, "wht_tax_id"):
wht_lines = inv.invoice_line_ids.filtered("wht_tax_id")
amount_wht = wht_lines._get_wht_amount(
self.env.company.currency_id, pe_line.payment_date
)[1]
amount_wht = self._get_scb_amount_no_decimal(amount_wht)
text = (
"006{internal_ref}{idx}{inv_sequence}{inv_number}{inv_amount}"
"{inv_date}{inv_description}{po_number}{vat_amount}{payee_chage_amount}"
"{wht_amount}{language}\r\n".format(
internal_ref=str(internal_ref).zfill(8),
idx=str(idx).zfill(6),
inv_sequence=str(sequence_inv).zfill(6),
inv_number=inv.name.ljust(15) if inv.name != "/" else ".".ljust(15),
inv_amount=inv_amount_untaxed,
inv_date=inv.invoice_date.strftime("%Y%m%d"),
inv_description="".ljust(70),
po_number=(purchase.name or "").ljust(15),
vat_amount=inv_amount_tax,
payee_chage_amount="0".zfill(16),
wht_amount=amount_wht,
language=self.scb_invoice_language,
internal_ref=str(internal_ref).zfill(8), # 4-11
idx=str(idx).zfill(6), # 12-17
inv_sequence=str(sequence_inv).zfill(6), # 18-23
inv_number=inv.name.ljust(15)
if inv.name != "/"
else ".".ljust(15), # 24-38
inv_amount=inv_amount_untaxed, # 39-54
inv_date=inv.invoice_date.strftime("%Y%m%d"), # 55-62
inv_description="".ljust(70), # 63-132
po_number=(purchase and purchase.name or "").ljust(15), # 133-147
vat_amount=inv_amount_tax, # 148-163
payee_chage_amount="0".zfill(16), # 164-179
wht_amount=amount_wht, # 180-195
language=self.scb_invoice_language, # 196-196
)
)
return text

def _get_text_footer_scb(self, payment_lines, total_batch_amount, internal_ref):
text = "999{total_debit}{total_credit}{total_amount}\r\n".format(
total_debit=str(internal_ref).zfill(6),
total_credit=str(len(payment_lines)).zfill(6),
total_amount=total_batch_amount,
total_debit=str(internal_ref).zfill(6), # 4-9
total_credit=str(len(payment_lines)).zfill(6), # 10-15
total_amount=total_batch_amount, # 16-31
)
return text

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _get_receiver_information(self):
# BNT return following original
if self.payment_export_id.scb_product_code == "BNT":
receiver_acc_number = sanitize_account_number(
self.payment_partner_bank_id.acc_number
self.payment_partner_bank_id.acc_number or "-----"
)
receiver_name = (
receiver_name and receiver_name[:100].ljust(100) or "".ljust(100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Thai Localization - Bank Payment Export SCB</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:943a58eeed4dbee4a948ea32296b3531adf01de802475d8de1ccb24d9b6cd395
!! source digest: sha256:909aa8de96a8c17169bd882ae101813eb7f83391fcf3dc94c57272ae1c53977f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-thailand/tree/15.0/l10n_th_bank_payment_export_scb"><img alt="OCA/l10n-thailand" src="https://img.shields.io/badge/github-OCA%2Fl10n--thailand-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-thailand-15-0/l10n-thailand-15-0-l10n_th_bank_payment_export_scb"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-thailand&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of Bank Export Payment to support a SCB.</p>
Expand Down
Loading

0 comments on commit f25cc23

Please sign in to comment.