库存移动新增需求计划关联
This commit is contained in:
@@ -1,116 +0,0 @@
|
||||
/** @odoo-module */
|
||||
import {patch} from '@web/core/utils/patch';
|
||||
import {ListRenderer} from "@web/views/list/list_renderer";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
|
||||
|
||||
patch(ListRenderer.prototype, 'jikimo_sf_demand_plan.ListRenderer', {
|
||||
setup() {
|
||||
// 获取各种服务
|
||||
this.dialog = useService("dialog");
|
||||
this.notification = useService("notification");
|
||||
this.orm = useService("orm");
|
||||
|
||||
owl.onMounted(() => {
|
||||
this.listenSelect();
|
||||
});
|
||||
return this._super(...arguments);
|
||||
},
|
||||
|
||||
listenSelect() {
|
||||
// console.log('listenSelect 被调用');
|
||||
const dom = $(this.__owl__.bdom.el);
|
||||
const _this = this;
|
||||
if(dom.hasClass('custom_made_type_listener_select2')) {
|
||||
this.listenSelect2();
|
||||
return
|
||||
}
|
||||
if(!dom.hasClass('custom_made_type_listener_select')) {
|
||||
return;
|
||||
}
|
||||
// 检查是否包含custom_made_type字段
|
||||
const hasCustomMadeTypeField = dom.find('[name="custom_made_type"]').length > 0;
|
||||
|
||||
if (hasCustomMadeTypeField) {
|
||||
// console.log('找到custom_made_type字段,设置监听器');
|
||||
|
||||
dom.on('change', '[name="custom_made_type"] select', function (event) {
|
||||
// console.log('检测到custom_made_type变化');
|
||||
|
||||
const record = _this.props.list.records;
|
||||
const limitData = record.find(item =>
|
||||
item.data.status == '30' &&
|
||||
item.data.new_supply_method == 'custom_made'
|
||||
);
|
||||
|
||||
if (!limitData) {
|
||||
// console.log('未找到符合条件的记录');
|
||||
return;
|
||||
}
|
||||
|
||||
let limitVal = limitData.data.custom_made_type;
|
||||
if (!limitVal) {
|
||||
// console.log('limitVal为空');
|
||||
return;
|
||||
}
|
||||
|
||||
const v = $(this).val();
|
||||
limitVal = '"' + limitVal + '"';
|
||||
// console.log('当前值:', v, '限制值:', limitVal);
|
||||
|
||||
if (v != limitVal) {
|
||||
// console.log('值不匹配,显示确认对话框');
|
||||
|
||||
// 方法1:使用Odoo的确认对话框服务(推荐)
|
||||
_this.showConfirmationDialog2(event.target, limitVal);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('未找到custom_made_type字段');
|
||||
}
|
||||
},
|
||||
listenSelect2() {
|
||||
// console.log('listenSelect2 被调用',this);
|
||||
const dom = $(this.__owl__.bdom.el);
|
||||
const _this = this;
|
||||
dom.on('change', '[name="custom_made_type"] select', function (event) {
|
||||
// console.log('检测到custom_made_type变化', event);
|
||||
const record = _this.props.list.records;
|
||||
const index = $(this).parents('tr').index();
|
||||
const data = record[index].data;
|
||||
const data_id = data.id;
|
||||
const product_id = data.product_id[0]
|
||||
const v = $(this).val();
|
||||
const limitVal = $(this).find('option:selected').siblings(':not([value=false])').attr('value');
|
||||
// 请求接口
|
||||
_this.orm.call('sf.production.demand.plan', 'check_other_custom_made_demands', [data_id, product_id, v]).then(res => {
|
||||
if(res) {
|
||||
_this.showConfirmationDialog2(event.target, limitVal);
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 方法2:使用ConfirmationDialog组件
|
||||
*/
|
||||
async showConfirmationDialog2(target, correctValue) {
|
||||
const confirmed = await this.dialog.add(ConfirmationDialog, {
|
||||
title: "确认",
|
||||
body: "请选择正确的类型",
|
||||
confirm: () => {
|
||||
console.log('用户确认');
|
||||
$(target).val(correctValue);
|
||||
},
|
||||
cancel: () => {
|
||||
console.log('用户取消');
|
||||
$(target).val(correctValue);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user