diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-01-10 10:39:39 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-01-10 10:39:39 +0700 |
| commit | 88e5def4792743d2b3245e390f95df5a3f4be321 (patch) | |
| tree | a1d430b84f4d186d23a23f7436c4a633e612156a | |
| parent | f1215bf41196a5758acfc05942fd305b166bd0bf (diff) | |
| parent | bef3ba4c18d585bc0980942d91b5fcb4d44427e1 (diff) | |
Merge branch 'feature/coretax_export_fakture' into odoo-production
# Conflicts:
# indoteknik_custom/models/__init__.py
# indoteknik_custom/security/ir.model.access.csv
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 3 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/coretax_fatur.py | 94 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/coretax_faktur.xml | 49 |
5 files changed, 147 insertions, 1 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 89f62524..255fbd3d 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -8,7 +8,7 @@ 'author': 'Rafi Zadanly', 'website': '', 'images': ['assets/favicon.ico'], - 'depends': ['base', 'coupon', 'delivery', 'sale', 'sale_management', 'vit_kelurahan'], + 'depends': ['base', 'coupon', 'delivery', 'sale', 'sale_management', 'vit_kelurahan', 'vit_efaktur' ], 'data': [ 'security/ir.model.access.csv', 'views/group_partner.xml', @@ -155,6 +155,7 @@ 'report/report_invoice.xml', 'report/report_picking.xml', 'report/report_sale_order.xml', + 'views/coretax_faktur.xml', ], 'demo': [], 'css': [], diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index e44d4233..bb223a31 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -135,3 +135,4 @@ from . import approval_retur_picking from . import va_multi_approve from . import va_multi_reject from . import stock_immediate_transfer +from . import coretax_fatur diff --git a/indoteknik_custom/models/coretax_fatur.py b/indoteknik_custom/models/coretax_fatur.py new file mode 100644 index 00000000..32082774 --- /dev/null +++ b/indoteknik_custom/models/coretax_fatur.py @@ -0,0 +1,94 @@ +from odoo import models, fields +import xml.etree.ElementTree as ET +from xml.dom import minidom +import base64 + +class CoretaxFaktur(models.Model): + _name = 'coretax.faktur' + _description = 'Export Faktur ke XML' + + export_file = fields.Binary(string="Export File", ) + export_filename = fields.Char(string="Export File", ) + + def generate_xml(self): + # Buat root XML + root = ET.Element('TaxInvoiceBulk', { + 'xmlns:xsi': "http://www.w3.org/2001/XMLSchema-instance", + 'xsi:noNamespaceSchemaLocation': "TaxInvoice.xsd" + }) + ET.SubElement(root, 'TIN').text = '74.226.022.7-086.000' + + # Tambahkan elemen ListOfTaxInvoice + list_of_tax_invoice = ET.SubElement(root, 'ListOfTaxInvoice') + + # Dapatkan data faktur + inv_obj = self.env['account.move'] + invoices = inv_obj.search([('is_efaktur_exported','=',True), + ('state','=','posted'), + ('efaktur_id','!=', False), + ('move_type','=','out_invoice')], limit = 5) + for invoice in invoices: + tax_invoice = ET.SubElement(list_of_tax_invoice, 'TaxInvoice') + + # Tambahkan elemen faktur + ET.SubElement(tax_invoice, 'TaxInvoiceDate').text = invoice.invoice_date.strftime('%Y-%m-%d') if invoice.invoice_date else '' + ET.SubElement(tax_invoice, 'TaxInvoiceOpt').text = 'Normal' + ET.SubElement(tax_invoice, 'TrxCode').text = '01' + ET.SubElement(tax_invoice, 'AddInfo') + ET.SubElement(tax_invoice, 'CustomDoc') + ET.SubElement(tax_invoice, 'RefDesc').text = invoice.name + ET.SubElement(tax_invoice, 'FacilityStamp') + ET.SubElement(tax_invoice, 'SellerIDTKU').text = '0742260227086000000000' + ET.SubElement(tax_invoice, 'BuyerTin').text = invoice.partner_id.npwp or '' + ET.SubElement(tax_invoice, 'BuyerDocument').text = 'TIN' + ET.SubElement(tax_invoice, 'BuyerCountry').text = 'IND' + ET.SubElement(tax_invoice, 'BuyerEmail').text = invoice.partner_id.email or '' + ET.SubElement(tax_invoice, 'BuyerIDTKU').text = '' + + # Tambahkan elemen ListOfGoodService + list_of_good_service = ET.SubElement(tax_invoice, 'ListOfGoodService') + for line in invoice.invoice_line_ids: + good_service = ET.SubElement(list_of_good_service, 'GoodService') + ET.SubElement(good_service, 'Opt').text = 'B' if line.product_id.type == 'service' else 'A' + ET.SubElement(good_service, 'Code').text = line.product_id.default_code + ET.SubElement(good_service, 'Name').text = line.name + ET.SubElement(good_service, 'Unit').text = 'UM.0018' + ET.SubElement(good_service, 'Price').text = str(line.price_unit) + ET.SubElement(good_service, 'Qty').text = str(line.quantity) + ET.SubElement(good_service, 'TotalDiscount').text = str(line.discount) + ET.SubElement(good_service, 'TaxBase').text = str(line.price_subtotal) + ET.SubElement(good_service, 'OtherTaxBase').text = str(line.price_subtotal) + ET.SubElement(good_service, 'VATRate').text = '0,11' + ET.SubElement(good_service, 'VAT').text = str(line.price_total * 0.11) + ET.SubElement(good_service, 'STLGRate').text = '' + ET.SubElement(good_service, 'STLG').text = '' + + # Pretty print XML + xml_str = ET.tostring(root, encoding='utf-8') + xml_pretty = minidom.parseString(xml_str).toprettyxml(indent=" ") + return xml_pretty + + def export_to_download(self): + # Generate XML content + xml_content = self.generate_xml() + + # Encode content to Base64 + xml_encoded = base64.b64encode(xml_content.encode('utf-8')) + + # Buat attachment untuk XML + attachment = self.env['ir.attachment'].create({ + 'name': 'Faktur_XML.xml', + 'type': 'binary', + 'datas': xml_encoded, + 'mimetype': 'application/xml', + 'store_fname': 'faktur_xml.xml', + }) + + # Kembalikan URL untuk download dengan header 'Content-Disposition' + response = { + 'type': 'ir.actions.act_url', + 'url': '/web/content/{}?download=true'.format(attachment.id), + 'target': 'self', + } + + return response diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 37a16c4d..6093636c 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -149,3 +149,4 @@ access_v_move_outstanding,access.v.move.outstanding,model_v_move_outstanding,,1, access_va_multi_approve,access.va.multi.approve,model_va_multi_approve,,1,1,1,1 access_va_multi_reject,access.va.multi.reject,model_va_multi_reject,,1,1,1,1 access_stock_immediate_transfer,access.stock.immediate.transfer,model_stock_immediate_transfer,,1,1,1,1 +access_coretax_faktur,access.coretax.faktur,model_coretax_faktur,,1,1,1,1 diff --git a/indoteknik_custom/views/coretax_faktur.xml b/indoteknik_custom/views/coretax_faktur.xml new file mode 100644 index 00000000..45eea23f --- /dev/null +++ b/indoteknik_custom/views/coretax_faktur.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data> + <record id="act_coretax_faktur" model="ir.actions.act_window"> + <field name="name">Export Faktur Pajak Keluaran XML Version</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">coretax.faktur</field> + <field name="view_mode">form</field> + <field name="target">new</field> + </record> + + <record id="view_coretax_faktur" model="ir.ui.view"> + <field name="name">view coretax faktur</field> + <field name="model">coretax.faktur</field> + <field name="type">form</field> + <field name="arch" type="xml"> + <form string="Export Pajak Keluaran"> + <p> + Klik tombol Export di bawah untuk mulai export Faktur Pajak Keluaran. + Data yang diexport adalah Customer Invoice yang berstatus Open dan belum diexport ke E-Faktur. + </p> + + <p> + Setelah proses export Faktur Pajak Keluaran selesai dilakukan, + download file ini: + </p> + <group> + <field name="export_file" filename="export_filename" readonly="1"/> + </group> + + <p> + Lalu import ke program E-Faktur DJP melalui menu <b>Referensi - Pajak Keluaran - Import</b> + </p> + + <footer> + <button string="Export" name="export_to_download" type="object" class="btn-primary"/> + <button string="Cancel" class="btn-default" special="cancel"/> + </footer> + </form> + </field> + </record> + + <menuitem id="coretax_faktur_export" + parent="vit_efaktur.menu_vit_efaktur_keluaran" + sequence="80" + name="Export FP. Keluaran XML" + action="act_coretax_faktur" /> + </data> +</odoo>
\ No newline at end of file |
