fix(addon): replace useService('rpc') with direct rpc import for Odoo 18
rpc service was removed in Odoo 17+. Import rpc function directly from
@web/core/network/rpc instead of using useService('rpc').
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/** @odoo-module **/
|
/** @odoo-module **/
|
||||||
import { Component, useState, useRef, onMounted, onWillUnmount } from '@odoo/owl';
|
import { Component, useState, useRef, onMounted, onWillUnmount } from '@odoo/owl';
|
||||||
import { useService } from '@web/core/utils/hooks';
|
import { useService } from '@web/core/utils/hooks';
|
||||||
import { registry } from '@web/core/registry';
|
import { rpc } from '@web/core/network/rpc';
|
||||||
|
|
||||||
let _msgCounter = 0;
|
let _msgCounter = 0;
|
||||||
function nextId() { return ++_msgCounter; }
|
function nextId() { return ++_msgCounter; }
|
||||||
@@ -15,7 +15,6 @@ export class AiPanel extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
this.rpc = useService('rpc');
|
|
||||||
this.notification = useService('notification');
|
this.notification = useService('notification');
|
||||||
this.messagesRef = useRef('messagesContainer');
|
this.messagesRef = useRef('messagesContainer');
|
||||||
this.inputRef = useRef('inputEl');
|
this.inputRef = useRef('inputEl');
|
||||||
@@ -65,7 +64,7 @@ export class AiPanel extends Component {
|
|||||||
this._scrollToBottom();
|
this._scrollToBottom();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await this.rpc('/ai/chat', {
|
const result = await rpc('/ai/chat', {
|
||||||
message: text,
|
message: text,
|
||||||
context: {},
|
context: {},
|
||||||
session_id: this.state.sessionId,
|
session_id: this.state.sessionId,
|
||||||
@@ -94,7 +93,7 @@ export class AiPanel extends Component {
|
|||||||
|
|
||||||
async approve(directiveId, approved) {
|
async approve(directiveId, approved) {
|
||||||
try {
|
try {
|
||||||
await this.rpc('/ai/approval/respond', {
|
await rpc('/ai/approval/respond', {
|
||||||
directive_id: directiveId,
|
directive_id: directiveId,
|
||||||
approved,
|
approved,
|
||||||
});
|
});
|
||||||
@@ -112,7 +111,7 @@ export class AiPanel extends Component {
|
|||||||
_startApprovalPoll() {
|
_startApprovalPoll() {
|
||||||
const poll = async () => {
|
const poll = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await this.rpc('/ai/approval/pending', {});
|
const result = await rpc('/ai/approval/pending', {});
|
||||||
this.state.pendingApprovals = result.items || [];
|
this.state.pendingApprovals = result.items || [];
|
||||||
} catch {
|
} catch {
|
||||||
// Silently ignore poll errors
|
// Silently ignore poll errors
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/** @odoo-module **/
|
/** @odoo-module **/
|
||||||
import { Component, useState, onMounted, onWillUnmount } from '@odoo/owl';
|
import { Component, useState, onMounted, onWillUnmount } from '@odoo/owl';
|
||||||
import { registry } from '@web/core/registry';
|
import { registry } from '@web/core/registry';
|
||||||
import { useService } from '@web/core/utils/hooks';
|
import { rpc } from '@web/core/network/rpc';
|
||||||
import { AiPanel } from './ai_panel';
|
import { AiPanel } from './ai_panel';
|
||||||
|
|
||||||
export class SystrayButton extends Component {
|
export class SystrayButton extends Component {
|
||||||
@@ -9,7 +9,6 @@ export class SystrayButton extends Component {
|
|||||||
static components = { AiPanel };
|
static components = { AiPanel };
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
this.rpc = useService('rpc');
|
|
||||||
this.state = useState({
|
this.state = useState({
|
||||||
panelOpen: false,
|
panelOpen: false,
|
||||||
serviceStatus: 'unknown',
|
serviceStatus: 'unknown',
|
||||||
@@ -59,7 +58,7 @@ export class SystrayButton extends Component {
|
|||||||
this.state.serviceStatus = 'offline';
|
this.state.serviceStatus = 'offline';
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const pending = await this.rpc('/ai/approval/pending', {});
|
const pending = await rpc('/ai/approval/pending', {});
|
||||||
this.state.pendingCount = (pending.items || []).length;
|
this.state.pendingCount = (pending.items || []).length;
|
||||||
} catch {
|
} catch {
|
||||||
this.state.pendingCount = 0;
|
this.state.pendingCount = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user