summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-05-15 21:58:34 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-05-15 21:58:34 +0700
commit3ecfd3cbf9e3257644c388801f18870960ef3ac0 (patch)
treee733b3f79f2fc73bde2d4efd9a0eadc7338064b1
parent46faf116edfba0f3d44fb1adc9ba65f17d01b1a2 (diff)
<miqdad> prevent export error when state is in draft and add filter based on account_id.
-rw-r--r--indoteknik_custom/models/coretax_fatur.py47
1 files changed, 36 insertions, 11 deletions
diff --git a/indoteknik_custom/models/coretax_fatur.py b/indoteknik_custom/models/coretax_fatur.py
index ffc2813f..c0558e5b 100644
--- a/indoteknik_custom/models/coretax_fatur.py
+++ b/indoteknik_custom/models/coretax_fatur.py
@@ -12,11 +12,20 @@ class CoretaxFaktur(models.Model):
export_file = fields.Binary(string="Export File", )
export_filename = fields.Char(string="Export File", )
- def validate_and_format_number(self, input_number):
+ def validate_and_format_number(slef, input_number):
+ # mencegah error ketika mau cetak xml ketika masih di draft
+ if input_number is None:
+ return '0000000000000000'
+
+ # ubah ke str kalau blm
+ if not isinstance(input_number, str):
+ input_number = str(input_number)
+
# Hapus semua karakter non-digit
cleaned_number = re.sub(r'\D', '', input_number)
total_sum = sum(int(char) for char in cleaned_number)
+
if total_sum == 0:
return '0000000000000000'
@@ -69,18 +78,36 @@ class CoretaxFaktur(models.Model):
ET.SubElement(tax_invoice, 'BuyerEmail').text = invoice.partner_id.email or ''
ET.SubElement(tax_invoice, 'BuyerIDTKU').text = buyerIDTKU
- # Find all product lines (exclude discounts and other adjustments)
+ # initiate diskon id
+ # ACCOUNT_DISCOUNT_IDS = [463, 464, 467]
+ # product_lines = invoice.invoice_line_ids.filtered(
+ # lambda l: not l.display_type and l.product_id and
+ # hasattr(l, 'account_id') and l.account_id and
+ # l.account_id.id not in self.ACCOUNT_DISCOUNT_IDS and
+ # l.quantity != -1
+ # )
+ # discount_lines = invoice.invoice_line_ids.filtered(
+ # lambda l: not l.display_type and (
+ # (hasattr(l, 'account_id') and l.account_id and
+ # l.account_id.id in self.ACCOUNT_DISCOUNT_IDS) or
+ # (l.quantity == -1)
+ # )
+ # )
+ # discount_id = self.env['account.account'].search([('name', '=', 'Diskon')])
+
+ # cari product dari inovoice line
product_lines = invoice.invoice_line_ids.filtered(
- lambda l: not l.display_type and l.product_id and 'Diskon' not in l.account_id.name
+ lambda l: not l.display_type and l.product_id and 'Diskon' not in l.account_id.id
)
- # Find all discount lines
+ # cari diskon/potongan
discount_lines = invoice.invoice_line_ids.filtered(
- lambda l: not l.display_type and ('Diskon' in l.account_id.name or l.name and 'Diskon' in l.name)
- )
+ lambda l: not l.display_type and ('Diskon' in l.account_id.id or l.name and 'Diskon' in l.name)
+ ) # ini ke account.id
# Calculate total product amount (before discount)
total_product_amount = sum(line.price_subtotal for line in product_lines)
+
if total_product_amount == 0:
total_product_amount = 1 # Avoid division by zero
@@ -100,11 +127,8 @@ class CoretaxFaktur(models.Model):
quantity = line.quantity
total_discount = round(line_discount, 2)
- # Calculate tax base after discount
- price_after_discount = line.price_subtotal - line_discount
-
# Calculate other tax values
- otherTaxBase = round(price_after_discount * (11 / 12), 2) if price_after_discount else 0
+ otherTaxBase = round(subtotal * (11 / 12), 2) if subtotal else 0
vat_amount = round(otherTaxBase * 0.12, 2)
# Create the line in XML
@@ -116,7 +140,8 @@ class CoretaxFaktur(models.Model):
ET.SubElement(good_service, 'Price').text = str(round(subtotal / quantity, 2)) if subtotal else '0'
ET.SubElement(good_service, 'Qty').text = str(quantity)
ET.SubElement(good_service, 'TotalDiscount').text = str(total_discount)
- ET.SubElement(good_service, 'TaxBase').text = str(round(price_after_discount))
+ ET.SubElement(good_service, 'TaxBase').text = str(
+ round(subtotal)) if subtotal else '0'
ET.SubElement(good_service, 'OtherTaxBase').text = str(otherTaxBase)
ET.SubElement(good_service, 'VATRate').text = '12'
ET.SubElement(good_service, 'VAT').text = str(vat_amount)