Created
June 16, 2025 09:07
-
-
Save TurkerTunali/8004decfc55c7642792cc8b470866005 to your computer and use it in GitHub Desktop.
ERPNext - Logo Tiger Entegrasyonu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########## LOGEDOSOFT BUSINESS SOLUTIONS ############# | |
################## LOGO INTEGRATION ################## | |
def gzip_zip_base64(content): | |
import gzip | |
import base64 | |
import sys | |
import os | |
""" | |
gzip + base64 compression | |
In this way the compressed object relatively short / small when the effect is not obvious, but since then base64 becomes large, but the compression is relatively large when the object will be effective | |
:param content: | |
:return: | |
""" | |
bytes_com = gzip.compress(str(content).encode("utf-8")) | |
base64_data = base64.b64encode(bytes_com) | |
back = str(base64_data.decode()) | |
return back, sys.getsizeof(back) | |
# Gzip file for read and write operations | |
# with gzip.open('./log/zip-test.gz', 'wb') as write: | |
# write.write(str(back).encode("utf-8")) | |
def gzip_unzip_base64(content): | |
import gzip | |
import base64 | |
import sys | |
import os | |
""" | |
base64 + gzip decompression | |
:param content: | |
:return: | |
""" | |
base64_data = base64.b64decode(content) | |
bytes_decom = gzip.decompress(base64_data) | |
str_unzip = bytes_decom.decode() | |
return str_unzip, sys.getsizeof(str_unzip) | |
def gzip_zip(content): | |
import gzip | |
import sys | |
import os | |
""" | |
gzip compresses data | |
: Param content: To compress objects | |
: Return: [0, 1]: 0: to be compressed; 1: After compression | |
""" | |
bytes_com = gzip.compress(str(content).encode("utf-8")) | |
return bytes_com, sys.getsizeof(bytes_com) | |
# print(bytes_com) | |
# with gzip.open('./lognew/zip-base-test.gz', 'wb') as write: | |
# write.write(str(content).encode("utf-8")) | |
def gzip_unzip(content): | |
import gzip | |
import sys | |
import os | |
""" | |
gzip unzip embodiment decompressed data | |
: Param content: the object you want to extract | |
:return: | |
""" | |
bytes_decom = gzip.decompress(content).decode() | |
return bytes_decom, sys.getsizeof(bytes_decom) | |
def get_customer_estatus(strLogoCode, strLogoObjectServiceURL, strLogoFirmNo, strLogoSecurityCode): | |
#Logo cari kartindan efatura, eirsaliye, mukellefiyet durumunu getirir | |
#SELECT CODE, ACCEPTEINV, PROFILEID, ACCEPTEDESP, PROFILEIDDESP FROM LG_021_CLCARD | |
import requests | |
from bs4 import BeautifulSoup | |
import base64 | |
dctHeaders = { | |
'Accept-Encoding': 'gzip,deflate', | |
'Content-Type': 'text/xml;charset=UTF-8', | |
'SOAPAction': '"http://tempuri.org/ISvc/ExecQuery"' | |
} | |
strBodyXML = """ | |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"> | |
<soapenv:Header/> | |
<soapenv:Body> | |
<tem:ExecQuery> | |
<tem:sqlText>{{queryBase64}}</tem:sqlText> | |
<tem:securityCode>{{strLogoSecurityCode}}</tem:securityCode> | |
</tem:ExecQuery> | |
</soapenv:Body> | |
</soapenv:Envelope> | |
""" | |
strQuery = f""" | |
SELECT ACCEPTEINV, PROFILEID, ACCEPTEDESP, PROFILEIDDESP | |
FROM LG_{strLogoFirmNo}_CLCARD | |
WHERE CODE = '{strLogoCode}' | |
""" | |
frappe.log_error(_("Query=\n{0}").format(strQuery), _("Logo Get Customer E-Status.")) | |
strQueryBase64 = base64.b64encode(strQuery.encode("utf-8")) | |
strQueryBase64 = str(strQueryBase64.decode()) | |
strBodyXML = frappe.render_template(strBodyXML, context= | |
{ | |
"queryBase64": strQueryBase64, | |
"strLogoSecurityCode": strLogoSecurityCode | |
}, is_path=False) | |
response = requests.post(strLogoObjectServiceURL, headers=dctHeaders, data=strBodyXML.encode('utf-8'), timeout=10) | |
strResult = "" | |
strMessage = "" | |
dctResult = {} | |
if response.status_code != 200: | |
strResult = f"Sunucu iletişim hatası! " | |
strMessage = f"Detay:status_code={response.status_code}" | |
else: | |
bsMain = BeautifulSoup(response.text, "lxml") | |
status = bsMain.find_all('status')[0].text | |
if status == "4": | |
strResult = "Veritabanı sorgusu çalıştırılamadı! " | |
strMessage = bsMain.find_all('errorstring')[0].text | |
strMessage = f"Detay:{strMessage}" | |
frappe.log_error(_("Error=\n{0}\nResponse=\n{1}").format(strMessage, response.text), _("Logo Get Customer E-Status.")) | |
else: | |
#Sorgu sonucu alındı | |
strQueryResultGZipped = bsMain.find_all('resultxml')[0].text | |
#print("Unzipping result xml") | |
strResultXML = gzip_unzip_base64(strQueryResultGZipped)[0] | |
#strResultXML = gzip_unzip(strQueryResultGZipped.encode('utf-8')) | |
frappe.log_error(_("ResultXML=\n{0}").format(strResultXML), _("Logo Get Customer E-Status.")) | |
bsResult = BeautifulSoup(strResultXML, "lxml") | |
#print("Parsing result xml") | |
dctResult['ACCEPTEINV'] = bsResult.find_all('accepteinv')[0].text | |
dctResult['PROFILEID'] = bsResult.find_all('profileid')[0].text | |
dctResult['ACCEPTEDESP'] = bsResult.find_all('acceptedesp')[0].text | |
dctResult['PROFILEIDDESP'] = bsResult.find_all('profileiddesp')[0].text | |
frappe.log_error(_("ResultDict=\n{0}").format(dctResult), _("Logo Get Customer E-Status.")) | |
return { 'message': strResult + strMessage, 'result': dctResult} | |
def get_supplier_address(docSupplier): | |
#Returns address doctype of the given supplier | |
docResult = () | |
lstAddress = frappe.get_list('Dynamic Link', filters={ | |
'parenttype': 'Address', | |
'link_doctype': 'Supplier', | |
'link_name': docSupplier.name | |
}, fields=['parent']) | |
print(lstAddress) | |
print(len(lstAddress)) | |
if len(lstAddress) == 0: | |
raise ValueError(_("Taşıyıcı firma {0}-{1} için adres tanımlanmamış!").format(docSupplier.name, docSupplier.supplier_name)) | |
docResult = frappe.get_doc("Address", lstAddress[0]['parent']) | |
print(docResult.name) | |
return docResult | |
def get_transporter_info_from_logo(docDeliveryNote): | |
#Checks for the given transporter name in the L_SHPAGENT.TITLE | |
#Creates a new record if not exist | |
#Returns the CODE of the SHIP AGENT (L_SHPAGENT) | |
import pyodbc | |
strResult = "" | |
#TEST SQL SERVER | |
strConnection = "DRIVER={ODBC Driver 17 for SQL Server};" | |
#strConnection += f"SERVER=2.tcp.ngrok.io,12778;DATABASE=GODB;UID=SA;" | |
#strConnection += f"SERVER=192.168.1.200\SQLEXPRESS;DATABASE=GODB;UID=SA;" | |
#strConnection += f"SERVER=185.218.245.149,9834;DATABASE=GODB;UID=erpnext;PWD=erpnext;" | |
#strConnection += f"SERVER=185.51.39.24,9834;DATABASE=GODB;UID=erpnext;PWD=erpnext;" | |
strConnection += f"SERVER=212.57.14.110,9834;DATABASE=GODB;UID=erpnext;PWD=erpnext;" | |
conSQL = pyodbc.connect(strConnection) | |
cursor = conSQL.cursor() | |
sql = "SELECT CODE FROM L_SHPAGENT WHERE TITLE = ?" | |
params = (docDeliveryNote.transporter_name) #("AYZE AMB.SAN.TİC.LTD.ŞTİ.") | |
cursor.execute(sql, (params)) | |
lstResult = cursor.fetchall() | |
if len(lstResult) > 0: | |
strResult = lstResult[0][0] | |
else: | |
#Transporter company doesn't exist in other ERP system :) Let's create it. | |
docSupplier = frappe.get_doc("Supplier", docDeliveryNote.transporter) | |
docSupplierAddress = get_supplier_address(docSupplier) | |
docSupplierCountry = frappe.get_doc("Country", docSupplierAddress.country) | |
#filters = {'link_doctype': "Supplier", 'link_name': "Ahmet"} | |
#x = frappe.contacts.doctype.address.address.address_query("Supplier", searchfield="*", filters=filters) | |
#print(x) | |
strResult = docSupplier.supplier_name[0:12] | |
print(strResult) | |
sql = 'EXEC [GODB].[dbo].[LD_INSERT_SHPAGENT] ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?' | |
""" PARAMETERS ARE | |
@_CODE varchar(13), @_TITLE varchar(51), @_ADDR1 varchar(51), @_ADDR2 varchar(51), | |
@_CITY varchar(41), @_COUNTRY varchar(41), @_COUNTRYCODE varchar(13), @_TOWN varchar(51), | |
@_POSTCODE varchar(21), @_TELNRS1 varchar(16), @_TCNO varchar(21), @_TAXNR varchar(21), | |
@_FIRMTYPE smallint, | |
@_SURNAME varchar(31), @_NAME varchar(31), @_DEFINITION_ varchar(201) | |
""" | |
params = ( | |
docSupplier.name, docSupplier.supplier_name, docSupplierAddress.address_line1, docSupplierAddress.address_line2, | |
docSupplierAddress.city.split("/")[0] if "/" in docSupplierAddress.city else docSupplierAddress.city, docSupplierAddress.country.upper(), docSupplierCountry.code.upper(), docSupplierAddress.city.split("/")[1] if "/" in docSupplierAddress.city else "", | |
docSupplierAddress.pincode, docSupplierAddress.phone, docSupplier.tax_id, docSupplier.tax_id, | |
1 if docSupplier.supplier_type == _("Company") else 0, | |
docSupplier.supplier_name.split(" ")[0], docSupplier.supplier_name.split(" ")[1], | |
docSupplier.supplier_name) | |
print("EXECUTE STARTING") | |
cursor.execute(sql, (params)) | |
print("EXECUTE ENDED") | |
cursor.close() | |
conSQL.commit() | |
conSQL.close() | |
print("ELSE 3") | |
#crsr = cnxn.cursor() | |
#crsr.execute(strQuery)#, params) | |
print("END OF SAVE TRANSPORTER") | |
return strResult | |
def get_emcenter_for_service_card_from_logo(strServiceCardCode, strLogoFirmNo): | |
#Gets EMCENTER.CODE for given srv card code | |
import pyodbc | |
strResult = "" | |
#TEST SQL SERVER | |
strConnection = "DRIVER={ODBC Driver 17 for SQL Server};" | |
#strConnection += f"SERVER=2.tcp.ngrok.io,12778;DATABASE=GODB;UID=SA;" | |
strConnection += f"SERVER=192.168.1.200\SQLEXPRESS;DATABASE=GODB;UID=SA;" | |
conSQL = pyodbc.connect(strConnection) | |
cursor = conSQL.cursor() | |
sql = f""" | |
SELECT EMCENTER.CODE | |
FROM LG_{strLogoFirmNo}_SRVCARD SRVCARD WITH(NOLOCK) | |
INNER JOIN LG_{strLogoFirmNo}_CRDACREF CRDACREF WITH(NOLOCK) ON CRDACREF.CARDREF = SRVCARD.LOGICALREF | |
AND TRCODE = 3 AND TYP = 1 | |
INNER JOIN LG_{strLogoFirmNo}_EMCENTER EMCENTER WITH(NOLOCK) ON CRDACREF.CENTERREF = EMCENTER.LOGICALREF | |
WHERE SRVCARD.CODE = ? | |
""" | |
params = (strServiceCardCode) | |
cursor.execute(sql, (params)) | |
lstResult = cursor.fetchall() | |
if len(lstResult) > 0: | |
strResult = lstResult[0][0] | |
return strResult | |
@frappe.whitelist() | |
def export_to_logo(strDocType, strDocName, blnGroupByItemCode = True): | |
import requests | |
from copy import deepcopy | |
from bs4 import BeautifulSoup | |
from frappe.utils.data import nowtime | |
strLogoObjectServiceURL = frappe.db.get_single_value('JP Logo Entegrasyon Ayarlari', 'logo_object_service_url') | |
strLogoFirmNo = frappe.db.get_single_value('JP Logo Entegrasyon Ayarlari', 'logo_firma_no') | |
strLogoSecurityCode = frappe.db.get_single_value('JP Logo Entegrasyon Ayarlari', 'client_secret_id') | |
dctHeaders = { | |
'Accept-Encoding': 'gzip,deflate', | |
'Content-Type': 'text/xml;charset=UTF-8', | |
'SOAPAction': '"http://tempuri.org/ISvc/AppendDataObject"' | |
} | |
strBodyXML = """ | |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"> | |
<soapenv:Header/> | |
<soapenv:Body> | |
<tem:AppendDataObject> | |
<tem:dataType>{{dataType}}</tem:dataType> | |
<tem:dataXML>{{dataXML}}</tem:dataXML> | |
<tem:paramXML><?xml version="1.0" encoding="utf-16"?><Parameters><ReplicMode>0</ReplicMode><CheckParams>1</CheckParams><CheckRight>1</CheckRight><ApplyCampaign>0</ApplyCampaign><ApplyCondition>0</ApplyCondition><FillAccCodes>0</FillAccCodes><FormSeriLotLines>0</FormSeriLotLines><GetStockLinePrice>0</GetStockLinePrice><ExportAllData>0</ExportAllData></Parameters></tem:paramXML> | |
<tem:FirmNr>{{strLogoFirmNo}}</tem:FirmNr> | |
<tem:securityCode>{{strLogoSecurityCode}}</tem:securityCode> | |
</tem:AppendDataObject> | |
</soapenv:Body> | |
</soapenv:Envelope> | |
""" | |
try: | |
if strDocType == "DeliveryNote": | |
contentHeader = """<?xml version="1.0" encoding="ISO-8859-9"?> | |
<SALES_DISPATCHES> | |
<DISPATCH DBOP="INS"> | |
<TYPE>8</TYPE> | |
<NUMBER>{{doc.ld_belge_no}}</NUMBER> | |
<DATE>{{doc.posting_date_formatted}}</DATE> | |
<TIME>{{doc.posting_time_formatted_logo_int}}</TIME> | |
<DOC_NUMBER>{{doc.ld_belge_no}}</DOC_NUMBER> | |
<ARP_CODE>{{docCustomer.logo_cari_kodu}}</ARP_CODE> | |
<SOURCE_WH>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCE_WH> | |
<SHIPPING_AGENT>{{doc.ShipAgentCode}}</SHIPPING_AGENT> | |
<CURRSEL_DETAILS>0</CURRSEL_DETAILS> | |
<CURRSEL_TOTALS>1</CURRSEL_TOTALS> | |
<DEDUCTIONPART1>2</DEDUCTIONPART1> | |
<DEDUCTIONPART2>3</DEDUCTIONPART2> | |
<NOTES1>{{doc.ld_aciklama_dizi[0] if doc.ld_aciklama_dizi[0] else ''}}</NOTES1> | |
<NOTES2>{{doc.ld_aciklama_dizi[1] if doc.ld_aciklama_dizi[1] else ''}}</NOTES2> | |
<NOTES3>{{doc.ld_aciklama_dizi[2] if doc.ld_aciklama_dizi[2] else ''}}</NOTES3> | |
<NOTES4>{{doc.ld_aciklama_dizi[3] if doc.ld_aciklama_dizi[3] else ''}}</NOTES4> | |
<NOTES5>{{doc.ld_aciklama_dizi[4] if doc.ld_aciklama_dizi[4] else ''}}</NOTES5> | |
<NOTES6>{{doc.ld_aciklama_dizi[5] if doc.ld_aciklama_dizi[5] else ''}}</NOTES6> | |
<TRANSACTIONS> | |
{{doc.contentLines}} | |
</TRANSACTIONS> | |
<SHIP_DATE>{{doc.posting_date_formatted}}</SHIP_DATE> | |
<SHIP_TIME>{{doc.posting_time_formatted_logo_int}}</SHIP_TIME> | |
<DOC_DATE>{{doc.posting_date_formatted}}</DOC_DATE> | |
<DOC_TIME>{{doc.posting_time_formatted_logo_int}}</DOC_TIME> | |
<EDESPATCH>1</EDESPATCH> | |
<EDESPATCH_PROFILEID>{{docCustomer.PROFILEIDDESP}}</EDESPATCH_PROFILEID> | |
{% if docCustomer.ACCEPTEINV == "1" %} | |
<EINVOICE>1</EINVOICE> | |
<EINVOICE_PROFILEID>{{docCustomer.PROFILEID}}</EINVOICE_PROFILEID> | |
{% else %} | |
<EINVOICE>2</EINVOICE> | |
<EARCHIVEDETR_SENDMOD>2</EARCHIVEDETR_SENDMOD> | |
<EARCHIVEDETR_INTPAYMENTTYPE>4</EARCHIVEDETR_INTPAYMENTTYPE> | |
<EARCHIVEDETR_INSTEADOFDESP>1</EARCHIVEDETR_INSTEADOFDESP> | |
{% endif %} | |
<EINVOICE_DRIVERNAME1>{{doc.DRIVER_NAME}}</EINVOICE_DRIVERNAME1> | |
<EINVOICE_DRIVERSURNAME1>{{doc.DRIVER_SURNAME}}</EINVOICE_DRIVERSURNAME1> | |
<EINVOICE_DRIVERTCKNO1>{{doc.DRIVER_IDNO}}</EINVOICE_DRIVERTCKNO1> | |
<EINVOICE_PLATENUM1>{{doc.vehicle_no}}</EINVOICE_PLATENUM1> | |
</DISPATCH> | |
</SALES_DISPATCHES> | |
""" | |
contentLine = """ | |
<TRANSACTION> | |
<TYPE>0</TYPE> | |
<MASTER_CODE>{{docItem.logo_malzeme_kodu}}</MASTER_CODE> | |
<SOURCEINDEX>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCEINDEX> | |
<QUANTITY>{{docCurrentLine.qty}}</QUANTITY> | |
<PRICE>{{docCurrentLine.rate}}</PRICE> | |
<CURR_PRICE>160</CURR_PRICE> | |
<PC_PRICE>{{docCurrentLine.rate}}</PC_PRICE> | |
<RC_XRATE>1</RC_XRATE> | |
<UNIT_CODE>{{docCurrentLine.uom}}</UNIT_CODE> | |
<UNIT_CONV1>{{docCurrentLine.qty}}</UNIT_CONV1> | |
<UNIT_CONV2>{{docCurrentLine.qty}}</UNIT_CONV2> | |
<VAT_RATE>18</VAT_RATE> | |
<DIST_ORD_REFERENCE>0</DIST_ORD_REFERENCE> | |
<CAMPAIGN_INFOS> | |
<CAMPAIGN_INFO> | |
</CAMPAIGN_INFO> | |
</CAMPAIGN_INFOS> | |
<MULTI_ADD_TAX>0</MULTI_ADD_TAX> | |
<EDT_CURR>160</EDT_CURR> | |
<EDT_PRICE>{{docCurrentLine.rate}}</EDT_PRICE> | |
<FOREIGN_TRADE_TYPE>0</FOREIGN_TRADE_TYPE> | |
<DISTRIBUTION_TYPE_WHS>0</DISTRIBUTION_TYPE_WHS> | |
<DISTRIBUTION_TYPE_FNO>0</DISTRIBUTION_TYPE_FNO> | |
</TRANSACTION> | |
""" | |
elif strDocType == "DeliveryNoteReturn": | |
contentHeader = """<?xml version="1.0" encoding="ISO-8859-9"?> | |
<SALES_DISPATCHES> | |
<DISPATCH DBOP="INS"> | |
<TYPE>3</TYPE> | |
<NUMBER>{{doc.ld_belge_no}}</NUMBER> | |
<DATE>{{doc.posting_date_formatted}}</DATE> | |
<TIME>{{doc.posting_time_formatted_logo_int}}</TIME> | |
<DOC_NUMBER>{{doc.ld_belge_no}}</DOC_NUMBER> | |
<ARP_CODE>{{docCustomer.logo_cari_kodu}}</ARP_CODE> | |
<SOURCE_WH>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCE_WH> | |
<CURRSEL_DETAILS>0</CURRSEL_DETAILS> | |
<CURRSEL_TOTALS>1</CURRSEL_TOTALS> | |
<DEDUCTIONPART1>2</DEDUCTIONPART1> | |
<DEDUCTIONPART2>3</DEDUCTIONPART2> | |
<TRANSACTIONS> | |
{{doc.contentLines}} | |
</TRANSACTIONS> | |
</DISPATCH> | |
</SALES_DISPATCHES> | |
""" | |
contentLine = """ | |
<TRANSACTION> | |
<TYPE>0</TYPE> | |
<MASTER_CODE>{{docItem.logo_malzeme_kodu}}</MASTER_CODE> | |
<SOURCEINDEX>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCEINDEX> | |
<QUANTITY>{{docCurrentLine.qty | abs}}</QUANTITY> | |
<PRICE>{{docCurrentLine.rate}}</PRICE> | |
<CURR_PRICE>160</CURR_PRICE> | |
<PC_PRICE>{{docCurrentLine.rate}}</PC_PRICE> | |
<RC_XRATE>1</RC_XRATE> | |
<UNIT_CODE>{{docCurrentLine.uom}}</UNIT_CODE> | |
<UNIT_CONV1>{{docCurrentLine.qty | abs}}</UNIT_CONV1> | |
<UNIT_CONV2>{{docCurrentLine.qty | abs}}</UNIT_CONV2> | |
<VAT_RATE>18</VAT_RATE> | |
<DIST_ORD_REFERENCE>0</DIST_ORD_REFERENCE> | |
<RET_COST_TYPE>1</RET_COST_TYPE> | |
<CAMPAIGN_INFOS> | |
<CAMPAIGN_INFO> | |
</CAMPAIGN_INFO> | |
</CAMPAIGN_INFOS> | |
<MULTI_ADD_TAX>0</MULTI_ADD_TAX> | |
<EDT_CURR>160</EDT_CURR> | |
<EDT_PRICE>{{docCurrentLine.rate}}</EDT_PRICE> | |
<FOREIGN_TRADE_TYPE>0</FOREIGN_TRADE_TYPE> | |
<DISTRIBUTION_TYPE_WHS>0</DISTRIBUTION_TYPE_WHS> | |
<DISTRIBUTION_TYPE_FNO>0</DISTRIBUTION_TYPE_FNO> | |
</TRANSACTION> | |
""" | |
elif strDocType == "PurchaseReceipt": | |
contentHeader = """<?xml version="1.0" encoding="ISO-8859-9"?> | |
<PURCHASE_DISPATCHES> | |
<DISPATCH DBOP="INS"> | |
<TYPE>1</TYPE> | |
<NUMBER>~</NUMBER> | |
<DATE>{{doc.posting_date_formatted}}</DATE> | |
<TIME>{{doc.posting_time_formatted_logo_int}}</TIME> | |
<DOC_NUMBER>{{doc.supplier_delivery_note}}</DOC_NUMBER> | |
<ARP_CODE>{{docCustomer.logo_cari_kodu}}</ARP_CODE> | |
<SOURCE_WH>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCE_WH> | |
<CURRSEL_DETAILS>0</CURRSEL_DETAILS> | |
<CURRSEL_TOTALS>1</CURRSEL_TOTALS> | |
<DEDUCTIONPART1>2</DEDUCTIONPART1> | |
<DEDUCTIONPART2>3</DEDUCTIONPART2> | |
<TRANSACTIONS> | |
{{doc.contentLines}} | |
</TRANSACTIONS> | |
</DISPATCH> | |
</PURCHASE_DISPATCHES> | |
""" | |
contentLine = """ | |
<TRANSACTION> | |
<TYPE>0</TYPE> | |
<MASTER_CODE>{{docItem.logo_malzeme_kodu}}</MASTER_CODE> | |
<SOURCEINDEX>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCEINDEX> | |
<QUANTITY>{{docCurrentLine.qty}}</QUANTITY> | |
<PRICE>{{docCurrentLine.rate}}</PRICE> | |
<CURR_PRICE>160</CURR_PRICE> | |
<PC_PRICE>{{docCurrentLine.rate}}</PC_PRICE> | |
<RC_XRATE>1</RC_XRATE> | |
<UNIT_CODE>{{docCurrentLine.uom}}</UNIT_CODE> | |
<UNIT_CONV1>{{docCurrentLine.qty}}</UNIT_CONV1> | |
<UNIT_CONV2>{{docCurrentLine.qty}}</UNIT_CONV2> | |
<VAT_RATE>18</VAT_RATE> | |
<DIST_ORD_REFERENCE>0</DIST_ORD_REFERENCE> | |
<ORDER_REFERENCE></ORDER_REFERENCE> | |
<PAYMENT_CODE></PAYMENT_CODE> | |
<CAMPAIGN_INFOS> | |
<CAMPAIGN_INFO> | |
</CAMPAIGN_INFO> | |
</CAMPAIGN_INFOS> | |
<MULTI_ADD_TAX>0</MULTI_ADD_TAX> | |
<EDT_CURR>160</EDT_CURR> | |
<EDT_PRICE>{{docCurrentLine.rate}}</EDT_PRICE> | |
<FOREIGN_TRADE_TYPE>0</FOREIGN_TRADE_TYPE> | |
<DISTRIBUTION_TYPE_WHS>0</DISTRIBUTION_TYPE_WHS> | |
<DISTRIBUTION_TYPE_FNO>0</DISTRIBUTION_TYPE_FNO> | |
</TRANSACTION> | |
""" | |
elif strDocType == "PurchaseReceiptReturn": | |
contentHeader = """<?xml version="1.0" encoding="ISO-8859-9"?> | |
<PURCHASE_DISPATCHES> | |
<DISPATCH DBOP="INS"> | |
<TYPE>6</TYPE> | |
<NUMBER>~</NUMBER> | |
<DATE>{{doc.posting_date_formatted}}</DATE> | |
<TIME>{{doc.posting_time_formatted_logo_int}}</TIME> | |
<DOC_NUMBER>{{doc.supplier_delivery_note}}</DOC_NUMBER> | |
<ARP_CODE>{{docCustomer.logo_cari_kodu}}</ARP_CODE> | |
<SOURCE_WH>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCE_WH> | |
<CURRSEL_DETAILS>0</CURRSEL_DETAILS> | |
<CURRSEL_TOTALS>1</CURRSEL_TOTALS> | |
<DEDUCTIONPART1>2</DEDUCTIONPART1> | |
<DEDUCTIONPART2>3</DEDUCTIONPART2> | |
<TRANSACTIONS> | |
{{doc.contentLines}} | |
</TRANSACTIONS> | |
</DISPATCH> | |
</PURCHASE_DISPATCHES> | |
""" | |
contentLine = """ | |
<TRANSACTION> | |
<TYPE>0</TYPE> | |
<MASTER_CODE>{{docItem.logo_malzeme_kodu}}</MASTER_CODE> | |
<SOURCEINDEX>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCEINDEX> | |
<QUANTITY>{{docCurrentLine.qty * (-1)}}</QUANTITY> | |
<PRICE>{{docCurrentLine.rate}}</PRICE> | |
<CURR_PRICE>160</CURR_PRICE> | |
<PC_PRICE>{{docCurrentLine.rate}}</PC_PRICE> | |
<RC_XRATE>1</RC_XRATE> | |
<UNIT_CODE>{{docCurrentLine.uom}}</UNIT_CODE> | |
<UNIT_CONV1>1</UNIT_CONV1> | |
<UNIT_CONV2>1</UNIT_CONV2> | |
<VAT_RATE>18</VAT_RATE> | |
<RET_COST_TYPE>1</RET_COST_TYPE> | |
<DIST_ORD_REFERENCE>0</DIST_ORD_REFERENCE> | |
<CAMPAIGN_INFOS> | |
<CAMPAIGN_INFO> | |
</CAMPAIGN_INFO> | |
</CAMPAIGN_INFOS> | |
<MULTI_ADD_TAX>0</MULTI_ADD_TAX> | |
<EDT_CURR>160</EDT_CURR> | |
<EDT_PRICE>{{docCurrentLine.rate}}</EDT_PRICE> | |
<FOREIGN_TRADE_TYPE>0</FOREIGN_TRADE_TYPE> | |
<DISTRIBUTION_TYPE_WHS>0</DISTRIBUTION_TYPE_WHS> | |
<DISTRIBUTION_TYPE_FNO>0</DISTRIBUTION_TYPE_FNO> | |
</TRANSACTION> | |
""" | |
elif strDocType == "PurchaseOrder": | |
contentHeader = """<?xml version="1.0" encoding="ISO-8859-9"?> | |
<PURCHASE_ORDERS> | |
<ORDER_SLIP DBOP="INS" > | |
<NUMBER>~</NUMBER> | |
<DATE>{{doc.posting_date_formatted}}</DATE> | |
<TIME>{{doc.posting_time_formatted_logo_int}}</TIME> | |
<DOC_NUMBER></DOC_NUMBER> | |
<AUXIL_CODE></AUXIL_CODE> | |
<ARP_CODE>{{docCustomer.logo_cari_kodu}}</ARP_CODE> | |
<ORDER_STATUS>1</ORDER_STATUS> | |
<RC_RATE>1</RC_RATE> | |
<CURRSEL_TOTAL>1</CURRSEL_TOTAL> | |
<DEDUCTIONPART1>2</DEDUCTIONPART1> | |
<DEDUCTIONPART2>3</DEDUCTIONPART2> | |
<TRANSACTIONS> | |
{{doc.contentLines}} | |
</TRANSACTIONS> | |
</ORDER_SLIP> | |
</PURCHASE_ORDERS> | |
""" | |
contentLine = """ | |
<TRANSACTION> | |
<TYPE>4</TYPE> | |
<MASTER_CODE>{{docItem.logo_malzeme_kodu}}</MASTER_CODE> | |
<OHP_CODE1>{{docCurrentLine.ohp_code}}</OHP_CODE1> | |
<QUANTITY>{{docCurrentLine.qty}}</QUANTITY> | |
<PRICE>{{docCurrentLine.rate}}</PRICE> | |
<UNIT_CODE>{{docCurrentLine.uom}}</UNIT_CODE> | |
<UNIT_CONV1>{{docCurrentLine.qty}}</UNIT_CONV1> | |
<UNIT_CONV2>{{docCurrentLine.qty}}</UNIT_CONV2> | |
<VAT_RATE>18</VAT_RATE> | |
<EDT_CURR>160</EDT_CURR> | |
<DUE_DATE>{{docCurrentLine.schedule_date_formatted}}</DUE_DATE> | |
</TRANSACTION> | |
""" | |
blnHasError = False | |
strErrorMessage = "" | |
strMessage = "" | |
dctCustomerEStatus = {} #Get Customer e-Details if DN or PR RETURN | |
if strDocType == "DeliveryNote": | |
dDataType = 17 | |
docCurrent = frappe.get_doc("Delivery Note", frappe.as_unicode(strDocName))#.encode("utf-8") | |
docCustomer = frappe.get_doc("Customer", docCurrent.customer) | |
docDriver1 = frappe.get_doc("Driver", docCurrent.driver) | |
docCurrent.plate1 = docCurrent.ld_vehicle | |
docCurrent.ShipAgentCode = get_transporter_info_from_logo(docCurrent) | |
#Logo irsaliye aciklama alani (ld_aciklama_dizi) alistiralim | |
dNoteIndex = 0 | |
docCurrent.ld_aciklama_dizi = [''] * 6 #Logo 6 satir aciklama aliyor | |
if hasattr(docCurrent, 'ld_aciklama') and docCurrent.ld_aciklama is not None: | |
for strLine in docCurrent.ld_aciklama.splitlines(): | |
if dNoteIndex < 6: | |
docCurrent.ld_aciklama_dizi[dNoteIndex] = strLine | |
else: | |
docCurrent.ld_aciklama_dizi[5] = docCurrent.ld_aciklama_dizi[5] + " " + strLine | |
dNoteIndex = dNoteIndex + 1 | |
if docCustomer.logo_cari_kodu is None or not docCustomer.logo_cari_kodu: | |
blnHasError = True | |
strErrorMessage += _("Cari {0} için Logo kodu tanımlanmamış!").format(docCurrent.customer) | |
else: | |
#Get Customer e-Details if DN or PR RETURN | |
dctCustomerEStatus = get_customer_estatus(docCustomer.logo_cari_kodu, strLogoObjectServiceURL, strLogoFirmNo, strLogoSecurityCode) | |
if dctCustomerEStatus['message'] != "": | |
raise ValueError(f"Cari Mükellef bilgileri alınamadı!Detay:{dctCustomerEStatus['message']}") | |
else: | |
frappe.log_error(_("dctCustomerEStatus=\n{0}").format(dctCustomerEStatus), _("Logo Get Customer E-Status.")) | |
docCustomer.ACCEPTEINV = dctCustomerEStatus['result']['ACCEPTEINV'] #2 if dctCustomerEStatus['result']['ACCEPTEINV'] == 0 else 1#Cari kart icinde CLCARD.ACCEPTEINV = 0 ise irsaliye de STFICHE.EINVOICE alani 2 olmali. CLCARD.ACCEPTEINV = 1 ise STFICHE.EINVOICE = 1 olmali. | |
docCustomer.PROFILEID = dctCustomerEStatus['result']['PROFILEID'] | |
docCustomer.ACCEPTEDESP = dctCustomerEStatus['result']['ACCEPTEDESP'] | |
docCustomer.PROFILEIDDESP = dctCustomerEStatus['result']['PROFILEIDDESP'] | |
frappe.log_error(_("docCustomer.ACCEPTEINV=\n{0}").format(docCustomer.ACCEPTEINV), _("Logo Get Customer E-Status.")) | |
if ' ' in docCurrent.driver_name: | |
docCurrent.DRIVER_NAME = docCurrent.driver_name.split(" ", 1)[0] | |
docCurrent.DRIVER_SURNAME = docCurrent.driver_name.split(" ", 1)[1] | |
else: | |
docCurrent.DRIVER_NAME = docCurrent.driver_name | |
docCurrent.DRIVER_SURNAME = "" | |
docCurrent.vehicle_no = docCurrent.ld_vehicle | |
docCurrent.DRIVER_IDNO = docCurrent.ld_driver_id | |
elif strDocType == "DeliveryNoteReturn": | |
dDataType = 17 | |
docCurrent = frappe.get_doc("Delivery Note", frappe.as_unicode(strDocName))#.encode("utf-8") | |
docCustomer = frappe.get_doc("Customer", docCurrent.customer) | |
if docCustomer.logo_cari_kodu is None or not docCustomer.logo_cari_kodu: | |
blnHasError = True | |
strErrorMessage += _("Cari {0} için Logo kodu tanımlanmamış!").format(docCurrent.customer) | |
elif strDocType == "PurchaseReceipt": | |
dDataType = 16 | |
docCurrent = frappe.get_doc("Purchase Receipt", frappe.as_unicode(strDocName))#.encode("utf-8") | |
docCustomer = frappe.get_doc("Supplier", docCurrent.supplier) | |
if docCustomer.logo_cari_kodu is None or not docCustomer.logo_cari_kodu: | |
blnHasError = True | |
strErrorMessage += _("Cari {0} için Logo kodu tanımlanmamış!").format(docCurrent.supplier) | |
elif strDocType == "PurchaseReceiptReturn": | |
dDataType = 16 | |
docCurrent = frappe.get_doc("Purchase Receipt", frappe.as_unicode(strDocName))#.encode("utf-8") | |
docCustomer = frappe.get_doc("Supplier", docCurrent.supplier) | |
if docCustomer.logo_cari_kodu is None or not docCustomer.logo_cari_kodu: | |
blnHasError = True | |
strErrorMessage += _("Cari {0} için Logo kodu tanımlanmamış!").format(docCurrent.supplier) | |
else: | |
#Get Customer e-Details if DN or PR RETURN | |
dctCustomerEStatus = get_customer_estatus(docCustomer.logo_cari_kodu, strLogoObjectServiceURL, strLogoFirmNo, strLogoSecurityCode) | |
if dctCustomerEStatus['message'] != "": | |
raise ValueError(f"Cari Mükellef bilgileri alınamadı!Detay:{dctCustomerEStatus.message}") | |
else: | |
docCustomer.ACCEPTEINV = dctCustomerEStatus['result']['ACCEPTEINV'] | |
docCustomer.PROFILEID = dctCustomerEStatus['result']['PROFILEID'] | |
docCustomer.ACCEPTEDESP = dctCustomerEStatus['result']['ACCEPTEDESP'] | |
docCustomer.PROFILEIDDESP = dctCustomerEStatus['result']['PROFILEIDDESP'] | |
elif strDocType == "PurchaseOrder": | |
dDataType = 4 | |
docCurrent = frappe.get_doc("Purchase Order", frappe.as_unicode(strDocName)) | |
docCustomer = frappe.get_doc("Supplier", docCurrent.supplier) | |
if docCustomer.logo_cari_kodu is None or not docCustomer.logo_cari_kodu: | |
blnHasError = True | |
strErrorMessage += _("Cari {0} için Logo kodu tanımlanmamış!").format(docCurrent.supplier) | |
else: | |
frappe.throw("Bilinmeyen dokuman tipi!(" + strDocType + ")") | |
#Start date time formatting | |
if strDocType == "PurchaseOrder":#Purchase Order doesn't have time field and posting_date | |
docCurrent.posting_date = docCurrent.transaction_date | |
docCurrent.posting_time_formatted_logo_int = 0 | |
else: | |
docCurrent.posting_time_hour = docCurrent.posting_time.seconds//3600 | |
docCurrent.posting_time_minute = (docCurrent.posting_time.seconds//60)%60 | |
docCurrent.posting_time_formatted_logo_int = docCurrent.posting_time_minute * 65536 | |
docCurrent.posting_time_formatted_logo_int += docCurrent.posting_time_hour * 65536 * 256 | |
docCurrent.posting_date_formatted = formatdate(docCurrent.posting_date, "dd.MM.yyyy") | |
#Doviz birimleri ayarlayalim | |
lstCurrency = frappe.db.get_list("JP Doviz Birimleri Eslestirme", fields=["logo_deger"], filters={"currency": docCurrent.currency, "parent": "JP Logo Entegrasyon Ayarlari", 'parenttype': "JP Logo Entegrasyon Ayarlari", 'parentfield': "jp_doviz_birimleri_eslestirme"}, order_by="idx asc") | |
docCurrent.logo_currency_code = lstCurrency[0].logo_deger | |
#if docCurrent.currency == "EUR": | |
# docCurrent.logo_currency_code = 20 | |
#elif docCurrent.currency == "USD": | |
# docCurrent.logo_currency_code = 1 | |
#elif docCurrent.currency == "TRY": | |
# docCurrent.logo_currency_code = 160 | |
docCurrent.contentLines = "" | |
if blnGroupByItemCode == True: | |
#Logo da satir birlestirme yapmak icin gruplama yapalim.https://app.asana.com/0/1159095102216267/1190274132142466/f | |
#print("Grouping started...") | |
arrGroupedItem = [] | |
for item in docCurrent.items: | |
docTmp = next((x for x in arrGroupedItem if (x.item_code == item.item_code and x.rate == item.rate and x.uom == item.uom)), None) | |
if docTmp is not None: #any((x.item_code == item.item_code and x.rate == item.rate and x.uom == item.uom) for x in arrGroupedItem): | |
#print("Found suitable item.") | |
docTmp.qty += item.qty | |
else: | |
#print("Suitable item not found. Creating entry.") | |
docTmp = deepcopy(item) | |
arrGroupedItem.append(docTmp) | |
#Yazdirirken yaptigimiz gruplama item_code ve uom ile siralama yaptiriyor, burada da yapalim | |
#BU KISIM SIRALAMA KARISMAMASI ICIN KALDIRILDI. EVREN BICAKCI | |
#arrGroupedItem = sorted(arrGroupedItem, key=lambda x: (x.item_code, x.uom), reverse=False) | |
docCurrent.items = arrGroupedItem | |
#print(frappe.as_json(arrGroupedItem)) | |
#print("Grouping finished...") | |
for item in docCurrent.items: | |
docItem = frappe.get_doc("Item", item.item_code) | |
docLineWarehouse = frappe.get_doc("Warehouse", item.warehouse) | |
if strDocType == "PurchaseOrder": | |
item.schedule_date_formatted = formatdate(item.schedule_date, "dd.MM.yyyy") | |
item.ohp_code = get_emcenter_for_service_card_from_logo(docItem.logo_malzeme_kodu, strLogoFirmNo) | |
if docItem.logo_malzeme_kodu is None or not docItem.logo_malzeme_kodu: | |
blnHasError = True | |
strErrorMessage += _("{0} kodlu ürün için Logo kodu tanımlanmamış!").format(item.item_code) | |
if docLineWarehouse.ld_erp_aktarim_kodu is None or not docLineWarehouse.ld_erp_aktarim_kodu: | |
blnHasError = True | |
strErrorMessage += _("{0} ambarı için ERP Aktarım Kodu tanımlanmamış!").format(item.warehouse) | |
doc_logo_line_xml = frappe.render_template(contentLine, context={"docCurrent": docCurrent, "docCurrentLine": item, "docItem":docItem, "docLineWarehouse":docLineWarehouse}, is_path=False) | |
docCurrent.contentLines = docCurrent.contentLines + doc_logo_line_xml | |
doc_logo_xml = frappe.render_template(contentHeader, context={"doc": docCurrent, "docCustomer":docCustomer, "docLineWarehouse":docLineWarehouse}, is_path=False) | |
frappe.log_error(_("Logo XML=\n{0}").format(doc_logo_xml), _("Logo Aktarim XML.")) | |
if blnHasError: | |
frappe.throw(strErrorMessage) | |
else: | |
gzip_str = gzip_zip_base64(doc_logo_xml) | |
strBodyXML = frappe.render_template(strBodyXML, context= | |
{ | |
"dataXML": gzip_str[0], | |
"dataType": dDataType, | |
"strLogoFirmNo": strLogoFirmNo, | |
"strLogoSecurityCode": strLogoSecurityCode | |
}, is_path=False) | |
#frappe.log_error(_("Header={0}\n\nBody={1}").format(dctHeaders, strBodyXML), _("Logo Aktarim Header & Body.")) | |
response = requests.post(strLogoObjectServiceURL, headers=dctHeaders, data=strBodyXML.encode('utf-8')) | |
strResult = "" | |
strMessage = "" | |
if response.status_code != 200: | |
strResult = f"Sunucu iletişim hatası! " | |
strMessage = f"Detay:status_code={response.status_code}" | |
else: | |
bsMain = BeautifulSoup(response.text, "lxml") | |
frappe.log_error(_("Response=\n{0}").format(response.text), _("Logo Aktarim XML.")) | |
status = bsMain.find_all('status')[0].text | |
if status == "4": | |
strResult = "Belge kaydedilemedi! " | |
strMessage = bsMain.find_all('errorstring')[0].text | |
strMessage = f"Detay:{strMessage}" | |
else: | |
#Kaydedildi | |
strMessage = bsMain.find_all('datareference')[0].text | |
except Exception as e: | |
print("exception occured") | |
print(e) | |
strResult = _("Hata oluştu! Detay:{0}").format(e) | |
frappe.log_error(frappe.get_traceback(), _("Muhasebe entegrasyonu (export_to_logo) hata oluşturdu.")) | |
frappe.msgprint(strResult) | |
return {'result':strResult, 'message':strMessage} | |
@frappe.whitelist() | |
def download_logo_integration_xml(strDocType, strDocName, blnGroupByItemCode = True): | |
from copy import deepcopy | |
try: | |
if strDocType == "DeliveryNote": | |
contentHeader = """<?xml version="1.0" encoding="ISO-8859-9"?> | |
<SALES_DISPATCHES> | |
<DISPATCH DBOP="INS"> | |
<TYPE>8</TYPE> | |
<NUMBER>~</NUMBER> | |
<DATE>{{doc.posting_date_formatted}}</DATE> | |
<TIME>{{doc.posting_time_formatted_logo_int}}</TIME> | |
<DOC_NUMBER>{{doc.ld_belge_no}}</DOC_NUMBER> | |
<ARP_CODE>{{docCustomer.logo_cari_kodu}}</ARP_CODE> | |
<SOURCE_WH>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCE_WH> | |
<CURRSEL_DETAILS>0</CURRSEL_DETAILS> | |
<CURRSEL_TOTALS>1</CURRSEL_TOTALS> | |
<DEDUCTIONPART1>2</DEDUCTIONPART1> | |
<DEDUCTIONPART2>3</DEDUCTIONPART2> | |
<TRANSACTIONS> | |
{{doc.contentLines}} | |
</TRANSACTIONS> | |
</DISPATCH> | |
</SALES_DISPATCHES> | |
""" | |
contentLine = """ | |
<TRANSACTION> | |
<TYPE>0</TYPE> | |
<MASTER_CODE>{{docItem.logo_malzeme_kodu}}</MASTER_CODE> | |
<SOURCEINDEX>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCEINDEX> | |
<QUANTITY>{{docCurrentLine.qty}}</QUANTITY> | |
<PRICE>{{docCurrentLine.rate}}</PRICE> | |
<CURR_PRICE>160</CURR_PRICE> | |
<PC_PRICE>{{docCurrentLine.rate}}</PC_PRICE> | |
<RC_XRATE>1</RC_XRATE> | |
<UNIT_CODE>{{docCurrentLine.uom}}</UNIT_CODE> | |
<UNIT_CONV1>{{docCurrentLine.qty}}</UNIT_CONV1> | |
<UNIT_CONV2>{{docCurrentLine.qty}}</UNIT_CONV2> | |
<VAT_RATE>18</VAT_RATE> | |
<DIST_ORD_REFERENCE>0</DIST_ORD_REFERENCE> | |
<CAMPAIGN_INFOS> | |
<CAMPAIGN_INFO> | |
</CAMPAIGN_INFO> | |
</CAMPAIGN_INFOS> | |
<MULTI_ADD_TAX>0</MULTI_ADD_TAX> | |
<EDT_CURR>160</EDT_CURR> | |
<EDT_PRICE>{{docCurrentLine.rate}}</EDT_PRICE> | |
<FOREIGN_TRADE_TYPE>0</FOREIGN_TRADE_TYPE> | |
<DISTRIBUTION_TYPE_WHS>0</DISTRIBUTION_TYPE_WHS> | |
<DISTRIBUTION_TYPE_FNO>0</DISTRIBUTION_TYPE_FNO> | |
</TRANSACTION> | |
""" | |
elif strDocType == "DeliveryNoteReturn": | |
contentHeader = """<?xml version="1.0" encoding="ISO-8859-9"?> | |
<SALES_DISPATCHES> | |
<DISPATCH DBOP="INS"> | |
<TYPE>3</TYPE> | |
<NUMBER>~</NUMBER> | |
<DATE>{{doc.posting_date_formatted}}</DATE> | |
<TIME>{{doc.posting_time_formatted_logo_int}}</TIME> | |
<DOC_NUMBER>{{doc.ld_belge_no}}</DOC_NUMBER> | |
<ARP_CODE>{{docCustomer.logo_cari_kodu}}</ARP_CODE> | |
<SOURCE_WH>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCE_WH> | |
<CURRSEL_DETAILS>0</CURRSEL_DETAILS> | |
<CURRSEL_TOTALS>1</CURRSEL_TOTALS> | |
<DEDUCTIONPART1>2</DEDUCTIONPART1> | |
<DEDUCTIONPART2>3</DEDUCTIONPART2> | |
<TRANSACTIONS> | |
{{doc.contentLines}} | |
</TRANSACTIONS> | |
</DISPATCH> | |
</SALES_DISPATCHES> | |
""" | |
contentLine = """ | |
<TRANSACTION> | |
<TYPE>0</TYPE> | |
<MASTER_CODE>{{docItem.logo_malzeme_kodu}}</MASTER_CODE> | |
<SOURCEINDEX>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCEINDEX> | |
<QUANTITY>{{docCurrentLine.qty | abs}}</QUANTITY> | |
<PRICE>{{docCurrentLine.rate}}</PRICE> | |
<CURR_PRICE>160</CURR_PRICE> | |
<PC_PRICE>{{docCurrentLine.rate}}</PC_PRICE> | |
<RC_XRATE>1</RC_XRATE> | |
<UNIT_CODE>{{docCurrentLine.uom}}</UNIT_CODE> | |
<UNIT_CONV1>{{docCurrentLine.qty | abs}}</UNIT_CONV1> | |
<UNIT_CONV2>{{docCurrentLine.qty | abs}}</UNIT_CONV2> | |
<VAT_RATE>18</VAT_RATE> | |
<DIST_ORD_REFERENCE>0</DIST_ORD_REFERENCE> | |
<CAMPAIGN_INFOS> | |
<CAMPAIGN_INFO> | |
</CAMPAIGN_INFO> | |
</CAMPAIGN_INFOS> | |
<MULTI_ADD_TAX>0</MULTI_ADD_TAX> | |
<EDT_CURR>160</EDT_CURR> | |
<EDT_PRICE>{{docCurrentLine.rate}}</EDT_PRICE> | |
<FOREIGN_TRADE_TYPE>0</FOREIGN_TRADE_TYPE> | |
<DISTRIBUTION_TYPE_WHS>0</DISTRIBUTION_TYPE_WHS> | |
<DISTRIBUTION_TYPE_FNO>0</DISTRIBUTION_TYPE_FNO> | |
</TRANSACTION> | |
""" | |
elif strDocType == "PurchaseReceipt": | |
contentHeader = """<?xml version="1.0" encoding="ISO-8859-9"?> | |
<PURCHASE_DISPATCHES> | |
<DISPATCH DBOP="INS"> | |
<TYPE>1</TYPE> | |
<NUMBER>~</NUMBER> | |
<DATE>{{doc.posting_date_formatted}}</DATE> | |
<TIME>{{doc.posting_time_formatted_logo_int}}</TIME> | |
<DOC_NUMBER>{{doc.supplier_delivery_note}}</DOC_NUMBER> | |
<ARP_CODE>{{docCustomer.logo_cari_kodu}}</ARP_CODE> | |
<SOURCE_WH>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCE_WH> | |
<CURRSEL_DETAILS>0</CURRSEL_DETAILS> | |
<CURRSEL_TOTALS>1</CURRSEL_TOTALS> | |
<DEDUCTIONPART1>2</DEDUCTIONPART1> | |
<DEDUCTIONPART2>3</DEDUCTIONPART2> | |
<TRANSACTIONS> | |
{{doc.contentLines}} | |
</TRANSACTIONS> | |
</DISPATCH> | |
</PURCHASE_DISPATCHES> | |
""" | |
contentLine = """ | |
<TRANSACTION> | |
<TYPE>0</TYPE> | |
<MASTER_CODE>{{docItem.logo_malzeme_kodu}}</MASTER_CODE> | |
<SOURCEINDEX>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCEINDEX> | |
<QUANTITY>{{docCurrentLine.qty}}</QUANTITY> | |
<PRICE>{{docCurrentLine.rate}}</PRICE> | |
<CURR_PRICE>160</CURR_PRICE> | |
<PC_PRICE>{{docCurrentLine.rate}}</PC_PRICE> | |
<RC_XRATE>1</RC_XRATE> | |
<UNIT_CODE>{{docCurrentLine.uom}}</UNIT_CODE> | |
<UNIT_CONV1>{{docCurrentLine.qty}}</UNIT_CONV1> | |
<UNIT_CONV2>{{docCurrentLine.qty}}</UNIT_CONV2> | |
<VAT_RATE>18</VAT_RATE> | |
<DIST_ORD_REFERENCE>0</DIST_ORD_REFERENCE> | |
<ORDER_REFERENCE></ORDER_REFERENCE> | |
<PAYMENT_CODE></PAYMENT_CODE> | |
<CAMPAIGN_INFOS> | |
<CAMPAIGN_INFO> | |
</CAMPAIGN_INFO> | |
</CAMPAIGN_INFOS> | |
<MULTI_ADD_TAX>0</MULTI_ADD_TAX> | |
<EDT_CURR>160</EDT_CURR> | |
<EDT_PRICE>{{docCurrentLine.rate}}</EDT_PRICE> | |
<FOREIGN_TRADE_TYPE>0</FOREIGN_TRADE_TYPE> | |
<DISTRIBUTION_TYPE_WHS>0</DISTRIBUTION_TYPE_WHS> | |
<DISTRIBUTION_TYPE_FNO>0</DISTRIBUTION_TYPE_FNO> | |
</TRANSACTION> | |
""" | |
elif strDocType == "PurchaseReceiptReturn": | |
contentHeader = """<?xml version="1.0" encoding="ISO-8859-9"?> | |
<PURCHASE_DISPATCHES> | |
<DISPATCH DBOP="INS"> | |
<TYPE>6</TYPE> | |
<NUMBER>~</NUMBER> | |
<DATE>{{doc.posting_date_formatted}}</DATE> | |
<TIME>{{doc.posting_time_formatted_logo_int}}</TIME> | |
<DOC_NUMBER>{{doc.supplier_delivery_note}}</DOC_NUMBER> | |
<ARP_CODE>{{docCustomer.logo_cari_kodu}}</ARP_CODE> | |
<SOURCE_WH>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCE_WH> | |
<CURRSEL_DETAILS>0</CURRSEL_DETAILS> | |
<CURRSEL_TOTALS>1</CURRSEL_TOTALS> | |
<DEDUCTIONPART1>2</DEDUCTIONPART1> | |
<DEDUCTIONPART2>3</DEDUCTIONPART2> | |
<TRANSACTIONS> | |
{{doc.contentLines}} | |
</TRANSACTIONS> | |
</DISPATCH> | |
</PURCHASE_DISPATCHES> | |
""" | |
contentLine = """ | |
<TRANSACTION> | |
<TYPE>0</TYPE> | |
<MASTER_CODE>{{docItem.logo_malzeme_kodu}}</MASTER_CODE> | |
<SOURCEINDEX>{{docLineWarehouse.ld_erp_aktarim_kodu}}</SOURCEINDEX> | |
<QUANTITY>{{docCurrentLine.qty * (-1)}}</QUANTITY> | |
<PRICE>{{docCurrentLine.rate}}</PRICE> | |
<CURR_PRICE>160</CURR_PRICE> | |
<PC_PRICE>{{docCurrentLine.rate}}</PC_PRICE> | |
<RC_XRATE>1</RC_XRATE> | |
<UNIT_CODE>{{docCurrentLine.uom}}</UNIT_CODE> | |
<UNIT_CONV1>1</UNIT_CONV1> | |
<UNIT_CONV2>1</UNIT_CONV2> | |
<VAT_RATE>18</VAT_RATE> | |
<RET_COST_TYPE>1</RET_COST_TYPE> | |
<DIST_ORD_REFERENCE>0</DIST_ORD_REFERENCE> | |
<CAMPAIGN_INFOS> | |
<CAMPAIGN_INFO> | |
</CAMPAIGN_INFO> | |
</CAMPAIGN_INFOS> | |
<MULTI_ADD_TAX>0</MULTI_ADD_TAX> | |
<EDT_CURR>160</EDT_CURR> | |
<EDT_PRICE>{{docCurrentLine.rate}}</EDT_PRICE> | |
<FOREIGN_TRADE_TYPE>0</FOREIGN_TRADE_TYPE> | |
<DISTRIBUTION_TYPE_WHS>0</DISTRIBUTION_TYPE_WHS> | |
<DISTRIBUTION_TYPE_FNO>0</DISTRIBUTION_TYPE_FNO> | |
</TRANSACTION> | |
""" | |
blnHasError = False | |
strErrorMessage = "" | |
#print("TEST TEST") | |
#print(strDocName) | |
#print(frappe.as_unicode(strDocName)) | |
#print(frappe.safe_decode(strDocName, encoding='utf-8')) | |
#print(frappe.safe_encode(strDocName, encoding='utf-8')) | |
#print(encode(strDocName)) | |
#strDocName = u' ' + strDocName.encode('utf-8') BUNU DENE | |
if strDocType == "DeliveryNote": | |
docCurrent = frappe.get_doc("Delivery Note", frappe.as_unicode(strDocName))#.encode("utf-8") | |
docCustomer = frappe.get_doc("Customer", docCurrent.customer) | |
if docCustomer.logo_cari_kodu is None or not docCustomer.logo_cari_kodu: | |
blnHasError = True | |
strErrorMessage += _("Cari {0} için Logo kodu tanımlanmamış!").format(docCurrent.customer) | |
elif strDocType == "DeliveryNoteReturn": | |
docCurrent = frappe.get_doc("Delivery Note", frappe.as_unicode(strDocName))#.encode("utf-8") | |
docCustomer = frappe.get_doc("Customer", docCurrent.customer) | |
if docCustomer.logo_cari_kodu is None or not docCustomer.logo_cari_kodu: | |
blnHasError = True | |
strErrorMessage += _("Cari {0} için Logo kodu tanımlanmamış!").format(docCurrent.customer) | |
elif strDocType == "PurchaseReceipt": | |
docCurrent = frappe.get_doc("Purchase Receipt", frappe.as_unicode(strDocName))#.encode("utf-8") | |
docCustomer = frappe.get_doc("Supplier", docCurrent.supplier) | |
if docCustomer.logo_cari_kodu is None or not docCustomer.logo_cari_kodu: | |
blnHasError = True | |
strErrorMessage += _("Cari {0} için Logo kodu tanımlanmamış!").format(docCurrent.supplier) | |
elif strDocType == "PurchaseReceiptReturn": | |
docCurrent = frappe.get_doc("Purchase Receipt", frappe.as_unicode(strDocName))#.encode("utf-8") | |
docCustomer = frappe.get_doc("Supplier", docCurrent.supplier) | |
if docCustomer.logo_cari_kodu is None or not docCustomer.logo_cari_kodu: | |
blnHasError = True | |
strErrorMessage += _("Cari {0} için Logo kodu tanımlanmamış!").format(docCurrent.supplier) | |
else: | |
frappe.throw("Bilinmeyen dokuman tipi!(" + strDocType + ")") | |
docCurrent.posting_date_formatted = formatdate(docCurrent.posting_date, "dd.MM.yyyy") | |
docCurrent.posting_time_hour = docCurrent.posting_time.seconds//3600 | |
docCurrent.posting_time_minute = (docCurrent.posting_time.seconds//60)%60 | |
docCurrent.posting_time_formatted_logo_int = docCurrent.posting_time_minute * 65536 | |
docCurrent.posting_time_formatted_logo_int += docCurrent.posting_time_hour * 65536 * 256 | |
#Doviz birimleri ayarlayalim | |
if docCurrent.currency == "EUR": | |
docCurrent.logo_currency_code = 20 | |
elif docCurrent.currency == "USD": | |
docCurrent.logo_currency_code = 1 | |
elif docCurrent.currency == "TRY": | |
docCurrent.logo_currency_code = 160 | |
docCurrent.contentLines = "" | |
if blnGroupByItemCode == True: | |
#Logo da satir birlestirme yapmak icin gruplama yapalim.https://app.asana.com/0/1159095102216267/1190274132142466/f | |
#print("Grouping started...") | |
arrGroupedItem = [] | |
for item in docCurrent.items: | |
docTmp = next((x for x in arrGroupedItem if (x.item_code == item.item_code and x.rate == item.rate and x.uom == item.uom)), None) | |
if docTmp is not None: #any((x.item_code == item.item_code and x.rate == item.rate and x.uom == item.uom) for x in arrGroupedItem): | |
#print("Found suitable item.") | |
docTmp.qty += item.qty | |
else: | |
#print("Suitable item not found. Creating entry.") | |
docTmp = deepcopy(item) | |
arrGroupedItem.append(docTmp) | |
#Yazdirirken yaptigimiz gruplama item_code ve uom ile siralama yaptiriyor, burada da yapalim | |
arrGroupedItem = sorted(arrGroupedItem, key=lambda x: (x.item_code, x.uom), reverse=False) | |
docCurrent.items = arrGroupedItem | |
#print(frappe.as_json(arrGroupedItem)) | |
#print("Grouping finished...") | |
for item in docCurrent.items: | |
docItem = frappe.get_doc("Item", item.item_code) | |
docLineWarehouse = frappe.get_doc("Warehouse", item.warehouse) | |
if docItem.logo_malzeme_kodu is None or not docItem.logo_malzeme_kodu: | |
blnHasError = True | |
strErrorMessage += _("{0} kodlu ürün için Logo kodu tanımlanmamış!").format(item.item_code) | |
if docLineWarehouse.ld_erp_aktarim_kodu is None or not docLineWarehouse.ld_erp_aktarim_kodu: | |
blnHasError = True | |
strErrorMessage += _("{0} ambarı için ERP Aktarım Kodu tanımlanmamış!").format(item.warehouse) | |
doc_logo_line_xml = frappe.render_template(contentLine, context={"docCurrent": docCurrent, "docCurrentLine": item, "docItem":docItem, "docLineWarehouse":docLineWarehouse}, is_path=False) | |
docCurrent.contentLines = docCurrent.contentLines + doc_logo_line_xml | |
doc_logo_xml = frappe.render_template(contentHeader, context={"doc": docCurrent, "docCustomer":docCustomer, "docLineWarehouse":docLineWarehouse}, is_path=False) | |
if blnHasError: | |
frappe.throw(strErrorMessage) | |
else: | |
frappe.local.response.filename = strDocName + ".xml" | |
frappe.local.response.filecontent = doc_logo_xml | |
frappe.local.response.type = "download" | |
except Exception as e: | |
frappe.throw("Beklenmeyen hata oluştu.Detay:" + str(e)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment