search
HomeBackend DevelopmentPython TutorialHow to automatically enter ERP system data in Python

    Overall project situation

    Software: Pycharm

    Environment: Python 3.7. 9 (Considering that customers may have different operating systems, for compatibility reasons)

    Technical library: requests, pandas, Pyqt5, etc. (see dependency files for details)

    Requirements analysis

    Through analysis and communication with customer demand documents, there are roughly the following requirements:

    • Submit data to 3 interfaces in batches based on "single number ownership"

    • Need a GUI operation interface

    • Support different salesmen to log in

    In general It is said to be a POST data submission and GUI development.

    Project implementation

    1.Post submission

    This section mainly uses crawler technology. The steps that remain unchanged for thousands of years are to analyze the web page first.

    1.1 Login

    How to automatically enter ERP system data in Python

    Through packet capture, it is found that the password is plain text, which reduces the difficulty by half. Then use the correct password to analyze the return after successful login. .

        def login(self, username: str, password: str):
            """
            登录
            """
            url = "http://cloud.tiamaes.com:11349/erp/portal.bootstrap/SSOLoginAction/login.do"
            data = {
                "_tp_data": '{"parameters":{"userName":' + username + ',"pwd":' + password + '},"rowsets":{},"headers":{},"requestComponent":"0"}'
            }
            data = parse.urlencode(data).replace("+", "")
            resp = requests.post(url, headers=self.headers, data=data, verify=False)
            self.IDENTIFIER = resp.json()["headers"]["IDENTIFIER"]
            return self.IDENTIFIER

    How to automatically enter ERP system data in Python

    It is found that after successful login, an "IDENTIFIER" parameter will be returned. The value is an encrypted string. This is obvious. Just by looking at the literal meaning, you know that this must be useful, so Write it down first.

    1.2 Interface Analysis

    Since I am using a test account, the data submitted by this account will be deleted. In order not to inject too much invalid data into others, there will be no actual entry here. , explained with business code.

    • Get vehicle information

    Through analysis, it was found that although the customer has given some vehicle information, there is still a lot of missing information that requires oneself Replenish. Through packet capture, we found that after entering the vehicle number, an Ajax request will be initiated, and the other information in the form is the data returned by the Ajax request.

    How to automatically enter ERP system data in Python

     def get_car_details(self, car_no: str, IDENTIFIER: str):
            """
            获取车辆信息
            """
            # print(self.IDENTIFIER)
            url = "http://cloud.tiamaes.com:11349/money/basis.inter/JwBusAction/getCacheJwBusByNo.do"
            data = {
                '_tp_data': '{"parameters": {"busNo": ' + str(car_no) + ', "dsName": "83"}, "rowsets": {}, "headers": {"IDENTIFIER": ' + IDENTIFIER + '}, "requestComponent": "0"}'
            }
            data = parse.urlencode(data).replace("+", "")
            resp = requests.post(url, headers=self.headers, data=data, verify=False)
            rows = resp.json()["rowsets"]["com.tp.basis.entity.entity.bus.BaJwBus"]["rows"][0]
            return rows
    • Get personnel information

    I didn’t find the personnel information in the form through packet capture, and later found it Relevant data was found on a page.

    How to automatically enter ERP system data in Python

    This is a little more troublesome. You need to use regular expressions to match the data.

        def get_personal_info(self, IDENTIFIER: str):
            """
            获取个人信息
            """
            url = "http://cloud.tiamaes.com:11349/money/money.action/CharteredAction/showDetail.do"
            data = {
                '_tp_data': '{"parameters":{"dsName":"83","method":"add","recId":"-1"},"rowsets":{},"headers":{"IDENTIFIER":' + IDENTIFIER + '},"requestComponent":"1"}'
            }
            data = parse.urlencode(data).replace("+", "")
            resp = requests.post(url, headers=self.headers, data=data, verify=False)
            json_data = eval(re.findall(r&#39;<code>.*?"rows":\[(.*?)\]&#39;, resp.text)[0])
            return json_data
    • Initiate a request and submit the data

    Get the identifier, vehicle information, and personnel information returned by the login, and the rest is to communicate with the customer Combine the given data and initiate a request. It should be noted that the request parameters need to be converted to URL encoding. The request parameters are also the most troublesome part of this crawler. Here we show you the parameters that need to be sent in a request.

    How to automatically enter ERP system data in Python

    #There are many parameters and the format requirements are relatively strict. In the entire development process, debugging here also takes the longest time. After debugging, the code should be simplified. I am too lazy to change the merge that needs to be merged after debugging, so this section is relatively redundant.

        def submit_data(self, i: dict, IDENTIFIER: str):
            """
            众意数据提交
            """
            personal_info = self.get_personal_info(IDENTIFIER)  # 获取个人信息
            personal_info_data = str(personal_info).replace("&#39;", &#39;"&#39;)  # 将personal_info转换为字符串
            url = "http://cloud.tiamaes.com:11349/money/money.action/CharteredAction/saveForm.do"
            print(f&#39;开始处理--{i["单号归属"]}--数据&#39;)
            memo = f&#39;工单号{i["工单号"]}、餐费{i["餐费"]}、住宿{i["住宿"]}、过路过桥费{i["过路过桥费"]}、油费{i["油费"]}、备注{i["备注"]}&#39;  # 拼接备注信息
            car_infos = self.get_car_details(str(i["车号"]), IDENTIFIER)  # 获取车辆信息
            pay_type = {
                "现金": "3",
                "转账": "2",
                "欠款": "1"
            }
            single_and_double = {
                "单程": "1",
                "双程": "2"
            }
            colType = pay_type[i["结账方式"]]  # 获取结账方式编码
            oddEven = single_and_double[i["单双程"]]  # 获取单双程编码
            now_date = datetime.datetime.now().date().strftime("%Y-%m-%d")  # 获取当前日期
            .......(此处省略)
            data["_tp_data"] = data["_tp_data"].replace(&#39;"dsName":"83"&#39;, &#39;"dsName":"82"&#39;)
            data = parse.urlencode(data).replace("+", "")  # 将字典转换成url编码
            resp = requests.post(url, headers=self.headers, data=data, verify=False).json()
            order_id = resp["rowsets"]["com.tp.money.entity.basic.Chartered"]["rows"][0]["recNo"]  # 获取订单编号
            i["包车单号"] = order_id
            return data

    2. GUI development

    gui development is relatively simple. If you don’t want to beautify it, Pyqt’s native plug-in will do. I borrowed the experience of the previous project here and used only Some knowledge has made a borderless interface and appropriate beautification.

    • Login

    How to automatically enter ERP system data in Python

    from PyQt5.QtCore import Qt
    from PyQt5.QtGui import QColor
    from PyQt5.QtWidgets import (QFrame, QMessageBox, QGraphicsDropShadowEffect)
    from Ui import login_ui
    from Ui.submit_ui_main import MySubmitForm
    from submit import TransitSubmit
     
     
    class MyLogin(login_ui.Ui_LoginForm, QFrame):
        def __init__(self, submit: TransitSubmit):
            super().__init__()
            # self.IDENTIFIER = None
            # self.my_main_window = None
            self.setupUi(self)
            self.submit = submit
            # 设置无边框模式
            self.setWindowFlag(Qt.FramelessWindowHint)  # 将界面设置为无框
            self.setAttribute(Qt.WA_TranslucentBackground)  # 将界面属性设置为半透明
            self.shadow = QGraphicsDropShadowEffect()  # 设定一个阴影,半径为10,颜色为#444444,定位为0,0
            self.shadow.setBlurRadius(10)
            self.shadow.setColor(QColor("#444444"))
            self.shadow.setOffset(0, 0)
            self.frame.setGraphicsEffect(self.shadow)  # 为frame设定阴影效果
            # ------------------------------------------------
            self.show()
            self.pushButton_3.clicked.connect(self.close)  # 关闭按钮
            self.pushButton_login.clicked.connect(self.do_login)  # 登录按钮
     
        # 以下是控制窗口移动的代码
        def mousePressEvent(self, event):  # 鼠标左键按下时获取鼠标坐标,按下右键取消
            if event.button() == Qt.LeftButton:
                self.m_flag = True
                self.m_Position = event.globalPos() - self.pos()
                event.accept()
            elif event.button() == Qt.RightButton:
                self.m_flag = False
     
        def mouseMoveEvent(self, QMouseEvent):  # 鼠标在按下左键的情况下移动时,根据坐标移动界面
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)
                QMouseEvent.accept()
     
        def mouseReleaseEvent(self, QMouseEvent):  # 鼠标按键释放时,取消移动
            self.m_flag = False
     
        # 登录事件
        def do_login(self):
            username = self.lineEdit_username.text()
            password = self.lineEdit_password.text()
            if not username or not password:
                QMessageBox.warning(self, &#39;警告&#39;, &#39;用户名或密码不能为空&#39;, QMessageBox.Yes)
                return
            else:
                IDENTIFIER = self.submit.login(username, password)
                if not IDENTIFIER:
                    QMessageBox.warning(self, &#39;警告&#39;, &#39;用户名或密码错误&#39;, QMessageBox.Yes)
                    return
                self.hide()  # 隐藏登录界面
                my_submit_form = MySubmitForm(self.submit, IDENTIFIER)
                my_submit_form.exec_()  # 显示主界面
    • Business Operation

    How to automatically enter ERP system data in Python

    class MySubmitForm(submitform_ui.Ui_Dialog_Submit, QDialog):
        def __init__(self, submit: TransitSubmit, IDENTIFIER: str):
            super().__init__()
            ......
            self.setupUi(self)
            ......
            self.progressBar.hide()  # 关闭进度条显示
            self.setWindowFlags(Qt.FramelessWindowHint)  # 无边框
            self.setAttribute(Qt.WA_TranslucentBackground)  # 设置窗口透明
            self.pushButton_mini.clicked.connect(self.showMinimized)  # 实现最小化
            self.pushButton_close.clicked.connect(self.close)  # 实现关闭功能
            ......
            self.show()
     
        # 实现鼠标拖拽功能
        def mousePressEvent(self, event):
            self.pressX = event.x()  # 记录鼠标按下的时候的坐标
            self.pressY = event.y()
     
        def mouseMoveEvent(self, event):
            x = event.x()
            y = event.y()  # 获取移动后的坐标
            moveX = x - self.pressX
            moveY = y - self.pressY  # 计算移动了多少
            positionX = self.frameGeometry().x() + moveX
            positionY = self.frameGeometry().y() + moveY  # 计算移动后主窗口在桌面的位置
            self.move(positionX, positionY)  # 移动主窗口
        ......

    Let me say more here. At first, I used QFrame the same as login, but it does not have an exec() method. It cannot pop up after successful login. It may also be that my knowledge is limited and I cannot do it. By analyzing the source code, I found that QDialog has this method to achieve pop-up. Later, I changed it and used QDialog to create a borderless interface.

    I won’t say much about the rest of the packaging. There are many tutorials on the Internet. What I use here is D packaging, upx compression, and changed icons. The entire packaged project is more than 50 MB.

    The above is the detailed content of How to automatically enter ERP system data in Python. For more information, please follow other related articles on the PHP Chinese website!

    Statement
    This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
    Python vs. C  : Understanding the Key DifferencesPython vs. C : Understanding the Key DifferencesApr 21, 2025 am 12:18 AM

    Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

    Python vs. C  : Which Language to Choose for Your Project?Python vs. C : Which Language to Choose for Your Project?Apr 21, 2025 am 12:17 AM

    Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

    Reaching Your Python Goals: The Power of 2 Hours DailyReaching Your Python Goals: The Power of 2 Hours DailyApr 20, 2025 am 12:21 AM

    By investing 2 hours of Python learning every day, you can effectively improve your programming skills. 1. Learn new knowledge: read documents or watch tutorials. 2. Practice: Write code and complete exercises. 3. Review: Consolidate the content you have learned. 4. Project practice: Apply what you have learned in actual projects. Such a structured learning plan can help you systematically master Python and achieve career goals.

    Maximizing 2 Hours: Effective Python Learning StrategiesMaximizing 2 Hours: Effective Python Learning StrategiesApr 20, 2025 am 12:20 AM

    Methods to learn Python efficiently within two hours include: 1. Review the basic knowledge and ensure that you are familiar with Python installation and basic syntax; 2. Understand the core concepts of Python, such as variables, lists, functions, etc.; 3. Master basic and advanced usage by using examples; 4. Learn common errors and debugging techniques; 5. Apply performance optimization and best practices, such as using list comprehensions and following the PEP8 style guide.

    Choosing Between Python and C  : The Right Language for YouChoosing Between Python and C : The Right Language for YouApr 20, 2025 am 12:20 AM

    Python is suitable for beginners and data science, and C is suitable for system programming and game development. 1. Python is simple and easy to use, suitable for data science and web development. 2.C provides high performance and control, suitable for game development and system programming. The choice should be based on project needs and personal interests.

    Python vs. C  : A Comparative Analysis of Programming LanguagesPython vs. C : A Comparative Analysis of Programming LanguagesApr 20, 2025 am 12:14 AM

    Python is more suitable for data science and rapid development, while C is more suitable for high performance and system programming. 1. Python syntax is concise and easy to learn, suitable for data processing and scientific computing. 2.C has complex syntax but excellent performance and is often used in game development and system programming.

    2 Hours a Day: The Potential of Python Learning2 Hours a Day: The Potential of Python LearningApr 20, 2025 am 12:14 AM

    It is feasible to invest two hours a day to learn Python. 1. Learn new knowledge: Learn new concepts in one hour, such as lists and dictionaries. 2. Practice and exercises: Use one hour to perform programming exercises, such as writing small programs. Through reasonable planning and perseverance, you can master the core concepts of Python in a short time.

    Python vs. C  : Learning Curves and Ease of UsePython vs. C : Learning Curves and Ease of UseApr 19, 2025 am 12:20 AM

    Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    VSCode Windows 64-bit Download

    VSCode Windows 64-bit Download

    A free and powerful IDE editor launched by Microsoft

    MinGW - Minimalist GNU for Windows

    MinGW - Minimalist GNU for Windows

    This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

    mPDF

    mPDF

    mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    SublimeText3 English version

    SublimeText3 English version

    Recommended: Win version, supports code prompts!