summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-06-24 11:23:36 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-06-24 11:23:45 +0700
commit6a913c0025c64903536fa6c9aeda526b609d27e6 (patch)
treea79437756e52c8a3cdf4ff74d6a14aba11026eaa
parentb6ec1d3c1b12a637d7c4ec9c6818167e77d3d3cc (diff)
change request coretax down payment
-rw-r--r--indoteknik_custom/models/account_move.py3
-rw-r--r--indoteknik_custom/models/coretax_fatur.py83
-rwxr-xr-xindoteknik_custom/models/sale_order.py1
-rw-r--r--indoteknik_custom/views/account_move.xml1
4 files changed, 62 insertions, 26 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index 66020a69..ece47236 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -70,6 +70,7 @@ class AccountMove(models.Model):
reklas_misc_id = fields.Many2one('account.move', string='Journal Entries Reklas')
# Di model account.move
bill_id = fields.Many2one('account.move', string='Vendor Bill', domain=[('move_type', '=', 'in_invoice')], help='Bill asal dari proses reklas ini')
+ down_payment = fields.Boolean('Down Payments?')
# def name_get(self):
@@ -441,7 +442,7 @@ class AccountMove(models.Model):
# Panggil model coretax.faktur untuk menghasilkan XML
coretax_faktur = self.env['coretax.faktur'].create({})
- response = coretax_faktur.export_to_download(invoices=valid_invoices)
+ response = coretax_faktur.export_to_download(invoices=valid_invoices, down_payments=valid_invoices.down_payment)
current_time = datetime.utcnow()
# Tandai faktur sebagai sudah diekspor
diff --git a/indoteknik_custom/models/coretax_fatur.py b/indoteknik_custom/models/coretax_fatur.py
index 92ff1a72..54eb0f8e 100644
--- a/indoteknik_custom/models/coretax_fatur.py
+++ b/indoteknik_custom/models/coretax_fatur.py
@@ -32,7 +32,7 @@ class CoretaxFaktur(models.Model):
return cleaned_number
- def generate_xml(self, invoices=None):
+ def generate_xml(self, invoices=None, down_payments=False):
# Buat root XML
root = ET.Element('TaxInvoiceBulk', {
'xmlns:xsi': "http://www.w3.org/2001/XMLSchema-instance",
@@ -72,42 +72,76 @@ class CoretaxFaktur(models.Model):
ET.SubElement(tax_invoice, 'BuyerEmail').text = invoice.partner_id.email or ''
ET.SubElement(tax_invoice, 'BuyerIDTKU').text = buyerIDTKU
- # Filter product
- product_lines = invoice.invoice_line_ids.filtered(
- lambda l: not l.display_type and hasattr(l, 'account_id') and
- l.account_id and l.product_id and
- l.account_id.id != self.DISCOUNT_ACCOUNT_ID and
- l.quantity != -1
- )
+ # Handle product lines based on down_payments flag
+ if down_payments and invoice.invoice_origin:
+ # Get from sale.order.line for down payment
+ sale_order = invoice.sale_id
+ if sale_order:
+ product_lines = sale_order.order_line.filtered(
+ lambda l: l.product_id and not l.is_downpayment and not l.display_type and not l.product_id.id == 229625
+ )
+ # Convert sale order lines to invoice-like format
+ converted_lines = []
+ for line in product_lines:
+ converted_lines.append({
+ 'name': line.name,
+ 'product_id': line.product_id,
+ 'price_subtotal': line.price_subtotal,
+ 'quantity': line.product_uom_qty,
+ 'price_unit': line.price_unit,
+ 'account_id': line.order_id.analytic_account_id or False,
+ })
+ product_lines = converted_lines
+ else:
+ product_lines = []
+ else:
+ # Normal case - get from invoice lines
+ product_lines = invoice.invoice_line_ids.filtered(
+ lambda l: not l.display_type and hasattr(l, 'account_id') and
+ l.account_id and l.product_id and
+ l.account_id.id != self.DISCOUNT_ACCOUNT_ID and
+ l.quantity != -1
+ )
- # Filter discount
+ # Filter discount (always from invoice)
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 == self.DISCOUNT_ACCOUNT_ID) or
- (l.quantity == -1)
+ (hasattr(l, 'account_id') and l.account_id and
+ l.account_id.id == self.DISCOUNT_ACCOUNT_ID) or
+ (l.quantity == -1)
)
)
- # Calculate total product amount (before discount)
- total_product_amount = sum(line.price_subtotal for line in product_lines)
+ # Calculate totals
+ total_product_amount = sum(line.get('price_subtotal', 0) if isinstance(line, dict)
+ else line.price_subtotal for line in product_lines)
if total_product_amount == 0:
total_product_amount = 1 # Avoid division by zero
- # Calculate total discount amount
total_discount_amount = abs(sum(line.price_subtotal for line in discount_lines))
# Tambahkan elemen ListOfGoodService
list_of_good_service = ET.SubElement(tax_invoice, 'ListOfGoodService')
for line in product_lines:
+ # Handle both dict (converted sale lines) and normal invoice lines
+ if isinstance(line, dict):
+ line_price_subtotal = line['price_subtotal']
+ line_quantity = line['quantity']
+ line_name = line['name']
+ line_price_unit = line['price_unit']
+ else:
+ line_price_subtotal = line.price_subtotal
+ line_quantity = line.quantity
+ line_name = line.name
+ line_price_unit = line.price_unit
+
# Calculate prorated discount
- line_proportion = line.price_subtotal / total_product_amount
+ line_proportion = line_price_subtotal / total_product_amount
line_discount = total_discount_amount * line_proportion
- # unit_price = line.price_unit
- subtotal = line.price_subtotal
- quantity = line.quantity
+ subtotal = line_price_subtotal
+ quantity = line_quantity
total_discount = round(line_discount, 2)
# Calculate other tax values
@@ -118,13 +152,12 @@ class CoretaxFaktur(models.Model):
good_service = ET.SubElement(list_of_good_service, 'GoodService')
ET.SubElement(good_service, 'Opt').text = 'A'
ET.SubElement(good_service, 'Code').text = '000000'
- ET.SubElement(good_service, 'Name').text = line.name
+ ET.SubElement(good_service, 'Name').text = line_name
ET.SubElement(good_service, 'Unit').text = 'UM.0018'
- ET.SubElement(good_service, 'Price').text = str(round(subtotal / quantity, 2)) if subtotal else '0'
+ ET.SubElement(good_service, 'Price').text = str(round(line_price_unit, 2)) if line_price_unit 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(subtotal)) if subtotal else '0'
+ 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)
@@ -136,9 +169,9 @@ class CoretaxFaktur(models.Model):
xml_pretty = minidom.parseString(xml_str).toprettyxml(indent=" ")
return xml_pretty
- def export_to_download(self, invoices):
+ def export_to_download(self, invoices, down_payments):
# Generate XML content
- xml_content = self.generate_xml(invoices)
+ xml_content = self.generate_xml(invoices, down_payments)
# Encode content to Base64
xml_encoded = base64.b64encode(xml_content.encode('utf-8'))
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index c1cdf2ed..85228901 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -1592,6 +1592,7 @@ class SaleOrder(models.Model):
'campaign_id': self.campaign_id.id,
'medium_id': self.medium_id.id,
'source_id': self.source_id.id,
+ 'down_payment': 229625 in [line.product_id.id for line in self.order_line],
'user_id': self.user_id.id,
'sale_id': self.id,
'invoice_user_id': self.user_id.id,
diff --git a/indoteknik_custom/views/account_move.xml b/indoteknik_custom/views/account_move.xml
index 0fc62293..e8061862 100644
--- a/indoteknik_custom/views/account_move.xml
+++ b/indoteknik_custom/views/account_move.xml
@@ -60,6 +60,7 @@
<field name="due_extension"/>
<field name="counter"/>
<field name="nomor_kwitansi"/>
+ <field name="down_payment"/>
</field>
<field name="to_check" position="after">
<field name="already_paid"/>