odoo-edi-connector

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Odoo EDI Connector

Odoo EDI连接器

Overview

概述

Electronic Data Interchange (EDI) is the standard for automated B2B document exchange — purchase orders, invoices, ASNs (Advance Shipping Notices). This skill guides you through mapping EDI transactions (ANSI X12 or EDIFACT) to Odoo business objects, setting up trading partner configurations, and automating inbound/outbound document flows.
电子数据交换(EDI)是企业间自动化文档交换的标准 —— 涵盖采购订单、发票、ASN(预先发货通知)。本指南将引导您完成EDI交易(ANSI X12或EDIFACT)与Odoo业务对象的映射、贸易伙伴配置的设置,以及入站/出站文档流的自动化。

When to Use This Skill

何时使用本指南

  • A retail partner requires EDI 850 (Purchase Orders) to do business with you.
  • You need to send EDI 856 (ASN) when goods are shipped.
  • Automating EDI 810 (Invoice) generation from Odoo confirmed deliveries.
  • Mapping EDI fields to Odoo fields for a new trading partner.
  • 零售合作伙伴要求您使用EDI 850(采购订单)开展业务
  • 您需要在发货时发送EDI 856(ASN)
  • 从Odoo已确认的交货单自动生成EDI 810(发票)
  • 为新的贸易伙伴映射EDI字段与Odoo字段

How It Works

工作流程

  1. Activate: Mention
    @odoo-edi-connector
    and specify the EDI transaction set and trading partner.
  2. Map: Receive a complete field mapping table between EDI segments and Odoo fields.
  3. Automate: Get Python code to parse incoming EDI files and create Odoo records.
  1. 激活:提及
    @odoo-edi-connector
    并指定EDI交易集和贸易伙伴
  2. 映射:获取EDI段与Odoo字段之间的完整字段映射表
  3. 自动化:获取用于解析入站EDI文件并创建Odoo记录的Python代码

EDI ↔ Odoo Object Mapping

EDI ↔ Odoo对象映射

EDI TransactionOdoo Object
850 Purchase Order
sale.order
(inbound customer PO)
855 PO AcknowledgmentConfirmation email / SO confirmation
856 ASN (Advance Ship Notice)
stock.picking
(delivery order)
810 Invoice
account.move
(customer invoice)
846 Inventory Inquiry
product.product
stock levels
997 Functional AcknowledgmentAutomated receipt confirmation
EDI交易Odoo对象
850 采购订单
sale.order
(入站客户采购订单)
855 采购订单确认确认邮件/销售订单确认
856 ASN(预先发货通知)
stock.picking
(交货单)
810 发票
account.move
(客户发票)
846 库存查询
product.product
库存水平
997 功能确认自动接收确认

Examples

示例

Example 1: Parse EDI 850 and Create Odoo Sale Order (Python)

示例1:解析EDI 850并创建Odoo销售订单(Python)

python
from pyx12 import x12file  # pip install pyx12

import xmlrpc.client

odoo_url = "https://myodoo.example.com"
db, uid, pwd = "my_db", 2, "api_key"
models = xmlrpc.client.ServerProxy(f"{odoo_url}/xmlrpc/2/object")

def process_850(edi_file_path):
    """Parse X12 850 Purchase Order and create Odoo Sale Order"""
    with x12file.X12File(edi_file_path) as f:
        for transaction in f.get_transaction_sets():
            # Extract header info (BEG segment)
            po_number = transaction['BEG'][3]    # Purchase Order Number
            po_date   = transaction['BEG'][5]    # Purchase Order Date

            # Extract partner (N1 segment — Buyer)
            partner_name = transaction['N1'][2]

            # Find partner in Odoo
            partner = models.execute_kw(db, uid, pwd, 'res.partner', 'search',
                [[['name', 'ilike', partner_name]]])
            partner_id = partner[0] if partner else False

            # Extract line items (PO1 segments)
            order_lines = []
            for po1 in transaction.get_segments('PO1'):
                sku     = po1[7]    # Product ID
                qty     = float(po1[2])
                price   = float(po1[4])

                product = models.execute_kw(db, uid, pwd, 'product.product', 'search',
                    [[['default_code', '=', sku]]])
                if product:
                    order_lines.append((0, 0, {
                        'product_id': product[0],
                        'product_uom_qty': qty,
                        'price_unit': price,
                    }))

            # Create Sale Order
            if partner_id and order_lines:
                models.execute_kw(db, uid, pwd, 'sale.order', 'create', [{
                    'partner_id': partner_id,
                    'client_order_ref': po_number,
                    'order_line': order_lines,
                }])
python
from pyx12 import x12file  # pip install pyx12

import xmlrpc.client

odoo_url = "https://myodoo.example.com"
db, uid, pwd = "my_db", 2, "api_key"
models = xmlrpc.client.ServerProxy(f"{odoo_url}/xmlrpc/2/object")

def process_850(edi_file_path):
    """Parse X12 850 Purchase Order and create Odoo Sale Order"""
    with x12file.X12File(edi_file_path) as f:
        for transaction in f.get_transaction_sets():
            # Extract header info (BEG segment)
            po_number = transaction['BEG'][3]    # Purchase Order Number
            po_date   = transaction['BEG'][5]    # Purchase Order Date

            # Extract partner (N1 segment — Buyer)
            partner_name = transaction['N1'][2]

            # Find partner in Odoo
            partner = models.execute_kw(db, uid, pwd, 'res.partner', 'search',
                [[['name', 'ilike', partner_name]]])
            partner_id = partner[0] if partner else False

            # Extract line items (PO1 segments)
            order_lines = []
            for po1 in transaction.get_segments('PO1'):
                sku     = po1[7]    # Product ID
                qty     = float(po1[2])
                price   = float(po1[4])

                product = models.execute_kw(db, uid, pwd, 'product.product', 'search',
                    [[['default_code', '=', sku]]])
                if product:
                    order_lines.append((0, 0, {
                        'product_id': product[0],
                        'product_uom_qty': qty,
                        'price_unit': price,
                    }))

            # Create Sale Order
            if partner_id and order_lines:
                models.execute_kw(db, uid, pwd, 'sale.order', 'create', [{
                    'partner_id': partner_id,
                    'client_order_ref': po_number,
                    'order_line': order_lines,
                }])

Example 2: Send EDI 997 Acknowledgment

示例2:发送EDI 997功能确认

python
def generate_997(isa_control, gs_control, transaction_control):
    """Generate a functional acknowledgment for received EDI"""
    return f"""ISA*00*          *00*          *ZZ*YOURISAID      *ZZ*PARTNERISAID   *{today}*1200*^*00501*{isa_control}*0*P*>~
GS*FA*YOURGID*PARTNERGID*{today}*1200*{gs_control}*X*005010X231A1~
ST*997*0001~
AK1*PO*{gs_control}~
AK9*A*1*1*1~
SE*4*0001~
GE*1*{gs_control}~
IEA*1*{isa_control}~"""
python
def generate_997(isa_control, gs_control, transaction_control):
    """Generate a functional acknowledgment for received EDI"""
    return f"""ISA*00*          *00*          *ZZ*YOURISAID      *ZZ*PARTNERISAID   *{today}*1200*^*00501*{isa_control}*0*P*>~
GS*FA*YOURGID*PARTNERGID*{today}*1200*{gs_control}*X*005010X231A1~
ST*997*0001~
AK1*PO*{gs_control}~
AK9*A*1*1*1~
SE*4*0001~
GE*1*{gs_control}~
IEA*1*{isa_control}~"""

Best Practices

最佳实践

  • Do: Store every raw EDI transaction in an audit log table before processing.
  • Do: Always send a 997 Functional Acknowledgment within 24 hours of receiving a transaction.
  • Do: Negotiate a test cycle with trading partners before going live — use test ISA qualifier
    T
    .
  • Don't: Process EDI files synchronously in web requests — queue them for async processing.
  • Don't: Hardcode trading partner qualifiers — store them in a configuration table per partner.
  • 建议:在处理前将所有原始EDI交易存储在审计日志表中
  • 建议:在收到交易后24小时内发送997功能确认
  • 建议:上线前与贸易伙伴协商测试周期——使用测试ISA限定符
    T
  • 不建议:在Web请求中同步处理EDI文件——将它们加入队列进行异步处理
  • 不建议:硬编码贸易伙伴限定符——将它们存储在每个伙伴的配置表中