File size: 1,685 Bytes
634769d
 
 
cfb1100
 
8f651b0
634769d
8f651b0
cfb1100
8f651b0
 
 
634769d
8f651b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
634769d
 
8f651b0
 
 
 
 
634769d
 
 
 
8f651b0
 
634769d
8f651b0
 
 
 
 
 
 
634769d
8f651b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import openai
import requests

# 🔥 Replace with your real OpenAI API key
client = openai.OpenAI(api_key="sk-abc123xyz456YOURREALAPIKEY")

def interpret_prompt(prompt):
    response = client.chat.completions.create(
        model="gpt-4",  # or use "gpt-3.5-turbo" if needed
        messages=[
            {"role": "user", "content": prompt}
        ]
    )
    return response.choices[0].message.content

def map_to_journal_entry(interpretation):
    """
    This is a placeholder function.
    In real implementation, parse 'interpretation' to map correct accounts and amounts.
    For demo, returning dummy entry.
    """
    return {
        "date": "2025-05-02",
        "journal_id": 1,  # Example journal
        "lines": [
            {"account_id": 101, "debit": 0, "credit": 245, "partner": "Tylor Smith"},  # AR
            {"account_id": 201, "debit": 245, "credit": 0, "partner": "Tylor Smith"}   # Bank/Cash
        ]
    }

def post_to_erp(accounting_entry):
    url = "https://your-odoo-instance.com/api/account.move"  # Replace with your Odoo API endpoint
    headers = {
        "Authorization": "Bearer YOUR_ODOO_API_TOKEN",
        "Content-Type": "application/json"
    }
    response = requests.post(url, json=accounting_entry, headers=headers)
    return response.json()

prompt = "Received $245 from Tylor Smith today"

# Step 1: Interpret prompt
interpretation = interpret_prompt(prompt)
print("AI Interpretation:", interpretation)

# Step 2: Map to journal entry
accounting_entry = map_to_journal_entry(interpretation)
print("Mapped Entry:", accounting_entry)

# Step 3: Post to ERP
result = post_to_erp(accounting_entry)
print("ERP API Response:", result)