下拉选项检测
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
'sf_demand_plan/static/src/scss/style.css',
|
'sf_demand_plan/static/src/scss/style.css',
|
||||||
'sf_demand_plan/static/src/js/print_demand.js',
|
'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_button.js',
|
||||||
|
'sf_demand_plan/static/src/js/custom_made_type_listener.js',
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'license': 'LGPL-3',
|
'license': 'LGPL-3',
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ export class CustomDemandPlanListRenderer extends ListRenderer {
|
|||||||
const selectedRecords = this.props.list.selection;
|
const selectedRecords = this.props.list.selection;
|
||||||
const isStatus30 = selectedRecords.some(record => record.data.status != "30");
|
const isStatus30 = selectedRecords.some(record => record.data.status != "30");
|
||||||
const button = $(this.__owl__.parent.bdom.parentEl).find('button[name="button_batch_release_plan"]');
|
const button = $(this.__owl__.parent.bdom.parentEl).find('button[name="button_batch_release_plan"]');
|
||||||
console.log('isStatus30', isStatus30, button);
|
|
||||||
if (isStatus30) {
|
if (isStatus30) {
|
||||||
// 禁用按钮
|
// 禁用按钮
|
||||||
button.attr('disabled', true);
|
button.attr('disabled', true);
|
||||||
|
|||||||
116
sf_demand_plan/static/src/js/custom_made_type_listener.js
Normal file
116
sf_demand_plan/static/src/js/custom_made_type_listener.js
Normal 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
<field name="model">sf.production.demand.plan</field>
|
<field name="model">sf.production.demand.plan</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="需求计划" default_order="sequence desc,id desc" editable="bottom"
|
<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">
|
js_class="custom_demand_plan_list">
|
||||||
<header>
|
<header>
|
||||||
<button string="打印" name="button_action_print" type="object"
|
<button string="打印" name="button_action_print" type="object"
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
<field name="line_ids" attrs="{'invisible': [('state', 'not in', ('40','50'))]}">
|
<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="status"/>
|
||||||
<field name="readonly_custom_made_type" invisible="1"/>
|
<field name="readonly_custom_made_type" invisible="1"/>
|
||||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user