货位看板详情回退修复,删除幽灵卡片。

This commit is contained in:
huziyang@jikimo.com
2025-06-12 15:38:56 +08:00
parent 23dd88b7ba
commit 6321e7ef23

View File

@@ -5,7 +5,7 @@ import { KanbanRenderer } from "@web/views/kanban/kanban_renderer";
import { kanbanView } from "@web/views/kanban/kanban_view"; import { kanbanView } from "@web/views/kanban/kanban_view";
import { registry } from "@web/core/registry"; import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks"; import { useService } from "@web/core/utils/hooks";
import { useState, onWillStart,onWillUnmount,onMounted } from "@odoo/owl"; import { useState, onWillStart, onWillUnmount, onMounted } from "@odoo/owl";
// 自定义看板渲染器 // 自定义看板渲染器
@@ -23,30 +23,45 @@ class CustomKanbanController extends KanbanController {
this._onUpdate = (payload) => { this._onUpdate = (payload) => {
this._handleSearchUpdate(payload); this._handleSearchUpdate(payload);
}; };
this.env.services.user.updateContext({ this.env.services.user.updateContext({
isBaseStyle: true isBaseStyle: true
}); });
let self = this; let self = this;
// 获取货架分层数据 // 获取货架分层数据
onWillStart(async () => { onWillStart(async () => {
this.searchModel.on('update',self,self._onUpdate); this.searchModel.on('update', self, self._onUpdate);
await this.loadShelfLayersData(); await this.loadShelfLayersData();
}); });
// 组件销毁时移除监听 // 组件销毁时移除监听
onWillUnmount(() => { onWillUnmount(() => {
this.searchModel.off('update',self,self._onUpdate); this.searchModel.off('update', self, self._onUpdate);
}); });
// 监听视图切换事件以监控面包屑
onMounted(() => {
this.handleRouteChange()
});
}
handleRouteChange() {
this.render(true);
let domain = this.searchModel.domain;
if (domain.length > 0) {
let shelfDomain = domain.find(item => item[0] === 'shelf_id');
this.onShelfChange(shelfDomain[2]);
} else {
this.setKanbanStyle('sf_kanban_location_style');
}
} }
_handleSearchUpdate() { _handleSearchUpdate() {
try { try {
let domain = this.searchModel.domain; let domain = this.searchModel.domain;
if(domain.length > 0){ if (domain.length > 0) {
let shelfDomain = domain.find(item => item[0] === 'shelf_id'); let shelfDomain = domain.find(item => item[0] === 'shelf_id');
if(shelfDomain){ if (shelfDomain) {
let shelfId = shelfDomain[2]; let shelfId = shelfDomain[2];
// 如果货架ID存在则设置相应的样式 // 如果货架ID存在则设置相应的样式
if (shelfId) { if (shelfId) {
@@ -60,7 +75,7 @@ class CustomKanbanController extends KanbanController {
this.setKanbanStyle('sf_kanban_location_style'); this.setKanbanStyle('sf_kanban_location_style');
} catch (error) { } catch (error) {
} }
} }
// 加载所有货架的层数数据 // 加载所有货架的层数数据
@@ -68,13 +83,13 @@ class CustomKanbanController extends KanbanController {
this.shelfLayersMap = {}; this.shelfLayersMap = {};
const shelfIds = await this.orm.search('sf.shelf', []); const shelfIds = await this.orm.search('sf.shelf', []);
const shelves = await this.orm.read('sf.shelf', shelfIds, ['id', 'layer_capacity']); const shelves = await this.orm.read('sf.shelf', shelfIds, ['id', 'layer_capacity']);
shelves.forEach(shelf => { shelves.forEach(shelf => {
this.shelfLayersMap[shelf.id] = shelf.layer_capacity; this.shelfLayersMap[shelf.id] = shelf.layer_capacity;
}); });
} }
setKanbanStyle(style){ setKanbanStyle(style) {
this.env.services.user.updateContext({ this.env.services.user.updateContext({
isBaseStyle: style === 'sf_kanban_location_style' isBaseStyle: style === 'sf_kanban_location_style'
}); });
@@ -88,10 +103,14 @@ class CustomKanbanController extends KanbanController {
isHave = true; isHave = true;
} }
}); });
// 添加新类 // 添加新类
if(isHave)kanbanViewEl.classList.add(style); if (isHave) kanbanViewEl.classList.add(style);
} }
const ghostCards = document.querySelectorAll('.o_kanban_ghost');
ghostCards.forEach(card => {
card.remove();
});
} }
updatePagerLimit(limit) { updatePagerLimit(limit) {
@@ -111,7 +130,7 @@ class CustomKanbanController extends KanbanController {
const [shelf] = await this.orm.read('sf.shelf', [shelfId], ['layer_capacity']); const [shelf] = await this.orm.read('sf.shelf', [shelfId], ['layer_capacity']);
this.shelfLayersMap[shelfId] = shelf.layer_capacity; this.shelfLayersMap[shelfId] = shelf.layer_capacity;
} }
// 获取该货架的层数 // 获取该货架的层数
const layerCapacity = this.shelfLayersMap[shelfId]; const layerCapacity = this.shelfLayersMap[shelfId];
// 根据层数设置不同的样式 // 根据层数设置不同的样式
@@ -120,10 +139,10 @@ class CustomKanbanController extends KanbanController {
isBaseStyle = false; isBaseStyle = false;
} }
} }
if(isBaseStyle){ if (isBaseStyle) {
this.updatePagerLimit(this.defaultPagerLimit); this.updatePagerLimit(this.defaultPagerLimit);
} }
else{ else {
this.updatePagerLimit(500); this.updatePagerLimit(500);
} }
this.setKanbanStyle(style); this.setKanbanStyle(style);
@@ -135,12 +154,12 @@ class CustomKanbanController extends KanbanController {
getSystemDefaultLimit() { getSystemDefaultLimit() {
// 方法1从用户服务获取默认值 // 方法1从用户服务获取默认值
const userService = this.env.services.user; const userService = this.env.services.user;
// 获取用户配置的默认分页大小 // 获取用户配置的默认分页大小
if (userService && userService.user_context && userService.user_context.limit) { if (userService && userService.user_context && userService.user_context.limit) {
return userService.user_context.limit; return userService.user_context.limit;
} }
// 方法3使用Odoo核心默认值通常为80 // 方法3使用Odoo核心默认值通常为80
return 80; return 80;
} }