summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-05-15 23:42:20 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-05-15 23:42:20 +0700
commita6a26665953d36578c62b6f4d5608b716d9fac88 (patch)
treea4524cbb8c83fd0e4e9d9d5510bb70fca024d21b
parent3ecfd3cbf9e3257644c388801f18870960ef3ac0 (diff)
<miqdad> fix not iterable account_id
-rw-r--r--indoteknik_custom/models/coretax_fatur.py40
1 files changed, 10 insertions, 30 deletions
diff --git a/indoteknik_custom/models/coretax_fatur.py b/indoteknik_custom/models/coretax_fatur.py
index c0558e5b..f2a1f793 100644
--- a/indoteknik_custom/models/coretax_fatur.py
+++ b/indoteknik_custom/models/coretax_fatur.py
@@ -13,14 +13,6 @@ class CoretaxFaktur(models.Model):
export_filename = fields.Char(string="Export File", )
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)
@@ -78,36 +70,24 @@ class CoretaxFaktur(models.Model):
ET.SubElement(tax_invoice, 'BuyerEmail').text = invoice.partner_id.email or ''
ET.SubElement(tax_invoice, 'BuyerIDTKU').text = buyerIDTKU
- # 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
+ # cari product
product_lines = invoice.invoice_line_ids.filtered(
- lambda l: not l.display_type and l.product_id and 'Diskon' not in l.account_id.id
+ lambda l: not l.display_type and l.product_id and
+ hasattr(l, 'account_id') and l.account_id and
+ 'Diskon' not in (l.account_id.name or '')
)
# cari diskon/potongan
discount_lines = invoice.invoice_line_ids.filtered(
- 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
+ lambda l: not l.display_type and (
+ (hasattr(l, 'account_id') and l.account_id and 'Diskon' in (l.account_id.name or '')) or
+ (l.name and isinstance(l.name, str) and 'Diskon' in l.name) or
+ (l.quantity == -1)
+ )
+ )
# 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