diff --git a/sf_demand_plan/__manifest__.py b/sf_demand_plan/__manifest__.py index 6e20e1e6..605ba5b0 100644 --- a/sf_demand_plan/__manifest__.py +++ b/sf_demand_plan/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'sf', 'website': 'https://www.sf.jikimo.com', - 'depends': ['sf_plan', 'jikimo_printing'], + 'depends': ['sf_plan', 'jikimo_printing', 'purchase_request', 'purchase_request_tier_validation'], 'data': [ 'security/ir.model.access.csv', 'data/stock_route_group.xml', @@ -32,7 +32,6 @@ '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', diff --git a/sf_demand_plan/models/__init__.py b/sf_demand_plan/models/__init__.py index 9913da30..46c426fd 100644 --- a/sf_demand_plan/models/__init__.py +++ b/sf_demand_plan/models/__init__.py @@ -9,3 +9,4 @@ from . import mrp_production from . import stock_rule from . import purchase_request from . import purchase_order +from . import stock_move diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 4c11d6cf..f85adc65 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -922,6 +922,11 @@ class SfProductionDemandPlan(models.Model): ], limit=1)) def button_plan_detail(self): + self.ensure_one() + purchase_request_ids = self.env['purchase.request'].sudo().search( + [('line_ids.demand_plan_line_id', 'in', self.ids)]) + purchase_order_ids = self.env['purchase.order'].sudo().search( + [('order_line.demand_plan_line_id', 'in', self.ids)]) return { 'name': _('详情'), 'type': 'ir.actions.act_window', @@ -930,6 +935,18 @@ class SfProductionDemandPlan(models.Model): 'target': 'new', 'views': [(False, 'form')], 'context': { - 'default_demand_plan_line_ids': self.ids, 'default_mrp_production_ids': self.mrp_production_ids.ids, + 'default_purchase_request_ids': purchase_request_ids.ids, + 'default_standard_purchase_order_ids': purchase_order_ids.filtered( + lambda o: o.purchase_type == 'standard' + ).ids, + 'default_consignment_purchase_order_ids': purchase_order_ids.filtered( + lambda o: o.purchase_type == 'consignment' + ).ids, + 'default_outsourcing_purchase_order_ids': purchase_order_ids.filtered( + lambda o: o.purchase_type == 'outsourcing' + ).ids, + 'default_outside_purchase_order_ids': purchase_order_ids.filtered( + lambda o: o.purchase_type == 'outside' + ).ids, }} diff --git a/sf_demand_plan/models/stock_move.py b/sf_demand_plan/models/stock_move.py new file mode 100644 index 00000000..6ffe5b42 --- /dev/null +++ b/sf_demand_plan/models/stock_move.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class StockMove(models.Model): + _inherit = 'stock.move' + + demand_plan_line_ids = fields.Many2many(comodel_name="sf.production.demand.plan", + string="需求计划明细", compute='_compute_demand_plan_line_ids', store=True) + + @api.depends('origin', 'move_orig_ids') + def _compute_demand_plan_line_ids(self): + sorted_records = self.sorted(key=lambda r: -r.id) + for line in sorted_records: + origin = [origin.replace(' ', '') for origin in line.origin.split(',')] + if line.created_purchase_request_line_id: + line.demand_plan_line_ids = line.created_purchase_request_line_id.demand_plan_line_id.ids + elif line.origin and 'MO' in line.origin: + mp_ids = self.env['mrp.production'].sudo().search([('name', '=', origin[0])]) + line.demand_plan_line_ids = mp_ids.demand_plan_line_id.ids if mp_ids else [] + elif line.origin and 'P' in line.origin: + purchase_order_ids = self.env['purchase.order'].sudo().search([('name', '=', origin[0])]) + if purchase_order_ids.order_line: + line.demand_plan_line_ids = purchase_order_ids.order_line.demand_plan_line_id.ids + elif line.move_orig_ids: + demand_plan_lines = self.env['sf.production.demand.plan'] + for move_orig in line.move_orig_ids: + demand_plan_lines |= move_orig.demand_plan_line_ids + line.demand_plan_line_ids = demand_plan_lines.ids + else: + line.demand_plan_line_ids = [] + + if not line.demand_plan_line_ids and self.env.context.get('demand_plan_line_id'): + plan_ids = self.env.context['demand_plan_line_id'] + line.demand_plan_line_ids = [plan_ids] diff --git a/sf_demand_plan/static/src/js/custom_made_type_listener.js b/sf_demand_plan/static/src/js/custom_made_type_listener.js deleted file mode 100644 index 4f2d3b9e..00000000 --- a/sf_demand_plan/static/src/js/custom_made_type_listener.js +++ /dev/null @@ -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); - } - }); - }, - - - - -}); - diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml index 68fb14e1..a5b3bddd 100644 --- a/sf_demand_plan/views/demand_plan.xml +++ b/sf_demand_plan/views/demand_plan.xml @@ -4,7 +4,7 @@ sf.production.demand.plan