odoo_loyalty_app/lib/services/odoo_service.dart
2026-03-21 15:26:51 +07:00

34 lines
1.0 KiB
Dart

import 'package:odoo_rpc/odoo_rpc.dart';
class OdooService {
static final OdooService _instance = OdooService._internal();
factory OdooService() => _instance;
OdooService._internal();
OdooClient? client;
void connect(String url) {
client = OdooClient(url);
}
Future<OdooSession> login(String db, String username, String password) async {
if (client == null) throw Exception("Connect to Odoo first");
return await client!.authenticate(db, username, password);
}
Future<List<dynamic>> getLoyaltyCards(int partnerId) async {
if (client == null) throw Exception("Connect to Odoo first");
// In Odoo 19, you might need to adjust the exact fields and model name
// depending on the installed modules (e.g. 'loyalty.card').
return await client!.callKw({
'model': 'loyalty.card',
'method': 'search_read',
'args': [
[['partner_id', '=', partnerId]],
],
'kwargs': {'fields': ['points', 'program_id', 'code']}
}) as List<dynamic>;
}
}