++
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import xmlrpc.client
|
||||
from datetime import datetime
|
||||
|
||||
# Odoo 连接配置
|
||||
ODOO_URL = "http://192.168.31.41:32000"
|
||||
DB_NAME = "quantify"
|
||||
USERNAME = "rpc"
|
||||
PASSWORD = "aaaAAA111"
|
||||
|
||||
# 连接
|
||||
common = xmlrpc.client.ServerProxy(f"{ODOO_URL}/xmlrpc/2/common")
|
||||
uid = common.authenticate(DB_NAME, USERNAME, PASSWORD, {})
|
||||
models = xmlrpc.client.ServerProxy(f"{ODOO_URL}/xmlrpc/2/object")
|
||||
|
||||
# 获取今天的日期字符串
|
||||
today = datetime.now()
|
||||
today_str = today.strftime('%Y-%m-%d')
|
||||
print(f"脚本执行时间(本地): {today_str}")
|
||||
|
||||
# 查询今天创建的所有记录
|
||||
print("\n" + "="*60)
|
||||
print("查询今天创建的所有记录:")
|
||||
print("="*60)
|
||||
|
||||
domain = [('create_date', '=', today_str)]
|
||||
record_ids = models.execute_kw(DB_NAME, uid, PASSWORD, 'alpha.idea', 'search', [domain])
|
||||
records = models.execute_kw(DB_NAME, uid, PASSWORD, 'alpha.idea', 'read',
|
||||
[record_ids, ['id', 'name', 'status', 'create_date']])
|
||||
|
||||
print(f"找到 {len(records)} 条记录:")
|
||||
for record in records:
|
||||
print(f" ID: {record['id']}, Name: {record['name']}, Status: {record['status']}, Create Date: {record['create_date']}")
|
||||
|
||||
# 查询所有状态分布
|
||||
print("\n" + "="*60)
|
||||
print("今天所有记录的状态分布:")
|
||||
print("="*60)
|
||||
|
||||
status_count = {}
|
||||
for record in records:
|
||||
status = record.get('status')
|
||||
status_count[status] = status_count.get(status, 0) + 1
|
||||
|
||||
for status, count in status_count.items():
|
||||
print(f" {status}: {count} 条")
|
||||
|
||||
# 测试日期比较的不同方式
|
||||
print("\n" + "="*60)
|
||||
print("测试日期比较方式:")
|
||||
print("="*60)
|
||||
|
||||
# 方式1: 直接使用字符串比较
|
||||
test_domain_1 = [('create_date', '=', today_str)]
|
||||
test_ids_1 = models.execute_kw(DB_NAME, uid, PASSWORD, 'alpha.idea', 'search', [test_domain_1])
|
||||
print(f"方式1 (create_date = '{today_str}'): 找到 {len(test_ids_1)} 条")
|
||||
|
||||
# 方式2: 使用日期范围
|
||||
test_domain_2 = [('create_date', '>=', today_str), ('create_date', '<', f"{today_str} 23:59:59")]
|
||||
test_ids_2 = models.execute_kw(DB_NAME, uid, PASSWORD, 'alpha.idea', 'search', [test_domain_2])
|
||||
print(f"方式2 (create_date >= '{today_str}' AND < '{today_str} 23:59:59'): 找到 {len(test_ids_2)} 条")
|
||||
|
||||
# 方式3: 使用日期函数(如果支持)
|
||||
test_domain_3 = [('create_date', '>=', today_str)]
|
||||
test_ids_3 = models.execute_kw(DB_NAME, uid, PASSWORD, 'alpha.idea', 'search', [test_domain_3])
|
||||
print(f"方式3 (create_date >= '{today_str}'): 找到 {len(test_ids_3)} 条")
|
||||
|
||||
# 查看最近创建的5条记录,看看日期格式
|
||||
print("\n" + "="*60)
|
||||
print("最近创建的5条记录:")
|
||||
print("="*60)
|
||||
|
||||
recent_ids = models.execute_kw(DB_NAME, uid, PASSWORD, 'alpha.idea', 'search',
|
||||
[[]], {'limit': 5, 'order': 'create_date desc'})
|
||||
recent_records = models.execute_kw(DB_NAME, uid, PASSWORD, 'alpha.idea', 'read',
|
||||
[recent_ids, ['id', 'name', 'status', 'create_date']])
|
||||
|
||||
for record in recent_records:
|
||||
print(f" ID: {record['id']}, Status: {record['status']}, Create Date: {record['create_date']}")
|
||||
Reference in New Issue
Block a user