Update app.py
Browse files
app.py
CHANGED
|
@@ -1,73 +1,23 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
result = model(formatted_prompt, max_length=256)[0]['generated_text']
|
| 25 |
-
print("\nRaw Model Output:\n", result)
|
| 26 |
-
|
| 27 |
-
# --- 4. PARSE JSON ---
|
| 28 |
-
try:
|
| 29 |
-
output_data = json.loads(result)
|
| 30 |
-
except json.JSONDecodeError:
|
| 31 |
-
print("\nERROR: Failed to parse output as JSON. Please adjust model or prompt.")
|
| 32 |
-
exit(1)
|
| 33 |
-
|
| 34 |
-
# Debug print
|
| 35 |
-
print("\nParsed Data:\n", output_data)
|
| 36 |
-
|
| 37 |
-
vendor_name = output_data['vendor_name']
|
| 38 |
-
amount = float(output_data['amount'])
|
| 39 |
-
invoice_date = output_data['date']
|
| 40 |
-
description = output_data['description']
|
| 41 |
-
|
| 42 |
-
# --- 5. CONNECT TO ODOO ---
|
| 43 |
-
print("\nConnecting to Odoo...")
|
| 44 |
-
common = xmlrpc.client.ServerProxy(f"{ODOO_URL}/xmlrpc/2/common")
|
| 45 |
-
uid = common.authenticate(ODOO_DB, ODOO_USERNAME, ODOO_PASSWORD, {})
|
| 46 |
-
models = xmlrpc.client.ServerProxy(f"{ODOO_URL}/xmlrpc/2/object")
|
| 47 |
-
|
| 48 |
-
# --- 6. FIND OR CREATE VENDOR ---
|
| 49 |
-
partner_id = models.execute_kw(ODOO_DB, uid, ODOO_PASSWORD, 'res.partner', 'search', [[['name', '=', vendor_name]]])
|
| 50 |
-
if not partner_id:
|
| 51 |
-
partner_id = models.execute_kw(ODOO_DB, uid, ODOO_PASSWORD, 'res.partner', 'create', [{
|
| 52 |
-
'name': vendor_name,
|
| 53 |
-
'supplier_rank': 1
|
| 54 |
-
}])
|
| 55 |
-
print(f"Vendor '{vendor_name}' created with ID {partner_id}")
|
| 56 |
-
else:
|
| 57 |
-
partner_id = partner_id[0]
|
| 58 |
-
print(f"Vendor '{vendor_name}' found with ID {partner_id}")
|
| 59 |
-
|
| 60 |
-
# --- 7. CREATE VENDOR BILL ---
|
| 61 |
-
invoice_id = models.execute_kw(ODOO_DB, uid, ODOO_PASSWORD, 'account.move', 'create', [{
|
| 62 |
-
'move_type': 'in_invoice',
|
| 63 |
-
'partner_id': partner_id,
|
| 64 |
-
'invoice_date': invoice_date,
|
| 65 |
-
'invoice_line_ids': [(0, 0, {
|
| 66 |
-
'name': description,
|
| 67 |
-
'quantity': 1,
|
| 68 |
-
'price_unit': amount,
|
| 69 |
-
'account_id': ACCOUNT_ID,
|
| 70 |
-
})],
|
| 71 |
-
}])
|
| 72 |
-
|
| 73 |
-
print(f"\nVendor Bill Created Successfully in Odoo! Invoice ID: {invoice_id}")
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
def interpret_prompt(prompt):
|
| 5 |
+
# Call GPT model
|
| 6 |
+
response = openai.ChatCompletion.create(
|
| 7 |
+
model="gpt-4",
|
| 8 |
+
messages=[{"role": "user", "content": prompt}]
|
| 9 |
+
)
|
| 10 |
+
return response.choices[0].message['content']
|
| 11 |
+
|
| 12 |
+
def post_to_erp(accounting_entry):
|
| 13 |
+
# Example Odoo API call
|
| 14 |
+
url = "https://your-odoo-instance/api/account.move"
|
| 15 |
+
headers = {"Authorization": "Bearer YOUR_TOKEN"}
|
| 16 |
+
response = requests.post(url, json=accounting_entry, headers=headers)
|
| 17 |
+
return response.json()
|
| 18 |
+
|
| 19 |
+
prompt = "Received $245 from Tylor Smith today"
|
| 20 |
+
interpretation = interpret_prompt(prompt)
|
| 21 |
+
accounting_entry = map_to_journal_entry(interpretation) # You define this mapping
|
| 22 |
+
result = post_to_erp(accounting_entry)
|
| 23 |
+
print(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|