下拉选项检测

This commit is contained in:
hyyy
2025-07-16 17:37:29 +08:00
parent 4d959eab59
commit 20415d0d3f
5 changed files with 119 additions and 3 deletions

View File

@@ -32,6 +32,7 @@
'sf_demand_plan/static/src/scss/style.css',
'sf_demand_plan/static/src/js/print_demand.js',
'sf_demand_plan/static/src/js/custom_button.js',
'sf_demand_plan/static/src/js/custom_made_type_listener.js',
]
},
'license': 'LGPL-3',

View File

@@ -25,7 +25,6 @@ export class CustomDemandPlanListRenderer extends ListRenderer {
const selectedRecords = this.props.list.selection;
const isStatus30 = selectedRecords.some(record => record.data.status != "30");
const button = $(this.__owl__.parent.bdom.parentEl).find('button[name="button_batch_release_plan"]');
console.log('isStatus30', isStatus30, button);
if (isStatus30) {
// 禁用按钮
button.attr('disabled', true);

View File

@@ -0,0 +1,116 @@
/** @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);
}
});
},
});

View File

@@ -4,7 +4,7 @@
<field name="model">sf.production.demand.plan</field>
<field name="arch" type="xml">
<tree string="需求计划" default_order="sequence desc,id desc" editable="bottom"
class="demand_plan_tree freeze-columns-before-part_number" create="false" delete="false"
class="demand_plan_tree freeze-columns-before-part_number custom_made_type_listener_select2" create="false" delete="false"
js_class="custom_demand_plan_list">
<header>
<button string="打印" name="button_action_print" type="object"

View File

@@ -78,7 +78,7 @@
</tree>
</field>
<field name="line_ids" attrs="{'invisible': [('state', 'not in', ('40','50'))]}">
<tree editable="bottom">
<tree editable="bottom" class="custom_made_type_listener_select">
<field name="status"/>
<field name="readonly_custom_made_type" invisible="1"/>
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>