Compare commits

..

4 Commits

Author SHA1 Message Date
guanhuan
cdb3cc7c03 需求计划详情调拨单显示 2025-07-18 15:33:51 +08:00
guanhuan
19417dd569 库存移动新增需求计划关联 2025-07-17 17:41:04 +08:00
hyyy
20415d0d3f 下拉选项检测 2025-07-16 17:37:29 +08:00
guanhuan
4d959eab59 新增产线类型方法校验 2025-07-16 15:46:03 +08:00
13 changed files with 390 additions and 186 deletions

View File

@@ -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',
@@ -20,6 +20,7 @@
'views/sale_order_views.xml',
'wizard/sf_demand_plan_print_wizard_view.xml',
'wizard/sf_release_plan_wizard_views.xml',
'wizard/sf_demand_plan_detail_wizard_view.xml',
'views/menu_view.xml',
],
'demo': [

View File

@@ -9,3 +9,5 @@ from . import mrp_production
from . import stock_rule
from . import purchase_request
from . import purchase_order
from . import stock_move
from . import stock_picking

View File

@@ -7,39 +7,17 @@ from odoo.tools import float_compare
from datetime import datetime, timedelta
from odoo.exceptions import UserError
import re
#本地环境问题 不加报错
class ProductCategory(models.Model):
_inherit = 'product.category'
negative_inventory_allowed = fields.Boolean(string="允许负库存", default=False)
class StockPicking(models.Model):
_inherit = 'stock.picking'
whether_show_quality_check = fields.Boolean(string="是否显示质检")
class ProductTemplate(models.Model):
_inherit = 'product.template'
blank_type = fields.Selection([
('圆料', '圆料'),
('方料', '方料'),
], string='坯料分类')
blank_precision = fields.Selection([
('精坯', '精坯'),
('粗坯', '粗坯'),
], string='坯料类型')
class SfProductionDemandPlan(models.Model):
_name = 'sf.production.demand.plan'
_description = 'sf_production_demand_plan'
def get_location_id(self):
stock_location = self.env['stock.location'].sudo().search([('name', '=', '客户')], limit=1)
return stock_location.id
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
return customer_location_id
priority = fields.Selection(related='demand_plan_id.priority', string='优先级')
priority = fields.Selection(related='demand_plan_id.priority', string='优先级', store=True)
status = fields.Selection([
('10', '草稿'),
('20', '待确认'),
@@ -56,7 +34,7 @@ class SfProductionDemandPlan(models.Model):
company_id = fields.Many2one(
related='sale_order_id.company_id',
store=True, index=True, precompute=True)
customer_name = fields.Char('客户', related='sale_order_id.customer_name')
customer_name = fields.Char('客户', related='sale_order_id.customer_name', store=True)
order_remark = fields.Text(related='sale_order_id.remark',
string="订单备注", store=True)
glb_url = fields.Char(related='sale_order_line_id.glb_url', string='glb文件地址')
@@ -105,7 +83,7 @@ class SfProductionDemandPlan(models.Model):
related='product_id.blank_precision')
unit_number = fields.Float('单件用量', digits=(16, 3), related='product_id.unit_number')
embryo_long = fields.Char('坯料尺寸(mm)', related='demand_plan_id.embryo_long')
materials_id = fields.Char('材料', related='demand_plan_id.materials_id')
materials_id = fields.Char('材料', related='demand_plan_id.materials_id', store=True)
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
model_process_parameters_ids = fields.Many2many(related='demand_plan_id.model_process_parameters_ids',
string='表面工艺', )
@@ -149,6 +127,12 @@ class SfProductionDemandPlan(models.Model):
string='字段自制类型只读'
)
is_processing = fields.Boolean(
string='正在处理中',
default=False,
help='用于防止重复点击按钮'
)
# hide_action_open_mrp_production = fields.Boolean(
# string='显示待工艺确认按钮',
# compute='_compute_hid_button',
@@ -637,11 +621,6 @@ class SfProductionDemandPlan(models.Model):
# 按产品分组并计算总数
product_data = {}
for plan in filtered_plan:
check_overdelivery_allowed = False
if not plan.demand_plan_id.overdelivery_allowed:
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
if plan.location_id.id == customer_location_id:
check_overdelivery_allowed = True
if plan.product_id not in product_data:
# 初始化产品数据,从产品上获取需求量
product_data[plan.product_id] = {
@@ -651,22 +630,17 @@ class SfProductionDemandPlan(models.Model):
# 累加计划数量
product_data[plan.product_id]['plan_uom_qty'] += plan.plan_uom_qty
product_data[plan.product_id]['overdelivery_allowed'] = check_overdelivery_allowed
# 检查需求超过计划数量的产品
warning_messages = []
error_messages = []
for product, data in product_data.items():
if data['overdelivery_allowed'] and float_compare(data['plan_uom_qty'], data['product_uom_qty'],precision_rounding=product.uom_id.rounding) == 1:
error_messages.append(f"您正在下达的产品 {product.display_name},已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
elif float_compare(data['plan_uom_qty'], data['product_uom_qty'],
if float_compare(data['plan_uom_qty'], data['product_uom_qty'],
precision_rounding=product.uom_id.rounding) == 1:
warning_messages.append(
_("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") %
(product.display_name, data['plan_uom_qty'], data['product_uom_qty'])
)
if error_messages:
error_message = "\n".join(error_messages)
raise ValidationError(error_message)
if warning_messages and check_overdelivery_allowed:
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
elif warning_messages:
warning_message = "\n".join(warning_messages)
return {
@@ -684,6 +658,9 @@ class SfProductionDemandPlan(models.Model):
def button_release_plan(self):
self.ensure_one()
if self.is_processing:
return
self.is_processing = True
check_overdelivery_allowed = False
if not self.demand_plan_id.overdelivery_allowed:
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
@@ -710,49 +687,38 @@ class SfProductionDemandPlan(models.Model):
self.action_confirm()
def action_confirm(self):
"""
确认需求计划行,创建 BOM、触发库存规则并更新状态。
"""
# 将当前需求计划行 ID 写入上下文,便于后续方法使用
self = self.with_context(demand_plan_line_id=self.id)
# 创建物料清单BOM根据供货方式进行不同的处理
self = self.with_context(
demand_plan_line_id=self.id
)
self.mrp_bom_create()
# 启动库存规则(创建采购、生产等)
self._action_launch_stock_rule()
# 根据供货方式设置状态字段
if self.supply_method in ('automation', 'manual'):
self.write({'status': '50'}) # 自动/手工 供货:待排产
self.write({'status': '50'})
self.update_sale_order_state()
else:
self.write({'status': '60'}) # 外购/外协/客户自供:无需排产
self.write({'status': '60'})
self.update_sale_order_state()
def _get_embryo_template_by_supply_method(self):
"""
根据供货方式返回对应的胚料模板 product.template 记录。
"""
supply_map = {
'automation': self.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo(),
'outsourcing': self.env.ref('sf_dlm.product_embryo_sf_outsource').sudo(),
'purchase': self.env.ref('sf_dlm.product_embryo_sf_purchase').sudo(),
'manual': self.env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo(),
'material_customer_provided': self.env.ref('jikimo_sale_multiple_supply_methods.product_template_embryo_customer_provided').sudo(),
}
template = supply_map.get(self.supply_method)
if not template:
raise UserError(f"未配置供货方式 {self.supply_method} 对应的胚料模板")
return template
def mrp_bom_create(self):
"""
创建 BOM包含胚料与成品 BOM用于后续生产或采购流程。
"""
# 如果同一计划中已有对应的 BOM 可复用,则直接使用
bom_type = ''
# 根据供货方式修改成品模板
if self.supply_method == 'automation':
bom_type = 'normal'
product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo().product_tmpl_id
elif self.supply_method == 'outsourcing':
bom_type = 'subcontract'
product_template_id = self.env.ref(
'jikimo_sale_multiple_supply_methods.product_template_outsourcing').sudo()
elif self.supply_method == 'purchase':
product_template_id = self.env.ref(
'jikimo_sale_multiple_supply_methods.product_template_purchase').sudo()
elif self.supply_method == 'manual':
bom_type = 'normal'
product_template_id = self.env.ref(
'jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo()
# 复制成品模板上的属性
self.product_id.product_tmpl_id.copy_template(product_template_id)
if self.supply_method in ('automation', 'manual'):
line_ids = self.demand_plan_id.line_ids.filtered(
lambda p: p.supply_method in ('automation', 'manual') and p.status in ('50', '60'))
@@ -765,32 +731,13 @@ class SfProductionDemandPlan(models.Model):
if line_ids:
self.bom_id = line_ids[0].bom_id.id
return
# 根据供货方式选择模板和 BOM 类型
bom_type = ''
if self.supply_method == 'automation':
bom_type = 'normal'
product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo().product_tmpl_id
elif self.supply_method == 'outsourcing':
bom_type = 'subcontract'
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_outsourcing').sudo()
elif self.supply_method == 'purchase':
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_purchase').sudo()
elif self.supply_method == 'manual':
bom_type = 'normal'
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo()
# 使用模板复制内容到当前产品
self.product_id.product_tmpl_id.copy_template(product_template_id)
# 构造 BOM 编码(包含时间戳)
future_time = datetime.now() + timedelta(hours=8)
# 生成BOM单据编码
code = f"{self.product_id.default_code}-{bom_type}-{future_time.strftime('%Y%m%d%H%M%S')}"
order_id = self.sale_order_id
product = self.product_id
# 构造胚料产品的参数
# 拼接方法需要的item结构成品的模型数据信息就是坯料的数据信息
item = {
'texture_code': product.materials_id.materials_no,
'texture_type_code': product.materials_type_id.materials_no,
@@ -803,84 +750,110 @@ class SfProductionDemandPlan(models.Model):
'embryo_redundancy_id': self.sale_order_line_id.embryo_redundancy_id,
'model_id': self.model_id
}
# 从产品名中提取编号(如 S12345-3
product_name = ''
match = re.search(r'(S\d{5}-\d+)', product.name)
product_seria = 0
# 如果匹配成功,提取结果
if match:
product_name = match.group(0)
# 获取成品名结尾-n的n
product_seria = int(product_name.split('-')[-1])
# 如果供货方式不是采购,则需要先创建胚料产品
# 成品供货方式为采购则不生成bom
if self.supply_method != 'purchase':
# 判断是否为客户自供
# 当成品上带有客供料选项时,生成坯料时选择“客供料”路线
if self.sale_order_line_id.embryo_redundancy_id:
embryo_template = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_embryo_customer_provided').sudo()
embryo_key = 'material_customer_provided'
else:
embryo_template = self._get_embryo_template_by_supply_method()
embryo_key = self.supply_method
# 获取批次追踪方式 依据模版
tracking_method = embryo_template.tracking
# 创建胚料产品(无 BOM 产品)
embryo_product = self.env['product.template'].sudo().no_bom_product_create(
embryo_template.with_context(active_test=False).product_variant_id,
item,
order_id,
embryo_key,
product_seria,
product
)
if isinstance(embryo_product, models.Model): # 确保返回的是记录而非错误码
embryo_product.write({'tracking': tracking_method})
if embryo_product == -3:
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
# 设置胚料 BOM 类型
if embryo_key in ('automation', 'manual', 'material_customer_provided'):
embryo_bom_type = 'normal'
elif embryo_key == 'outsourcing':
embryo_bom_type = 'subcontract'
elif embryo_key == 'purchase':
embryo_bom_type = 'purchase'
else:
embryo_bom_type = 'normal'
# 创建胚料 BOM 及 BOM 行
embryo_bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create(
embryo_product, embryo_bom_type, True, tracking=tracking_method)
embryo_bom_line = embryo_bom.with_user(self.env.ref("base.user_admin")).bom_create_line(embryo_product)
if not embryo_bom_line:
raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配')
# 创建成品 BOM包含胚料
product_bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create(
product, bom_type, 'product', code, tracking=tracking_method)
product_bom.with_user(self.env.ref("base.user_admin")).bom_create_line_has(embryo_product)
# 赋值 BOM ID
self.bom_id = product_bom.id
# 将成品模板的内容复制到成品上
customer_provided_embryo = self.env.ref(
'jikimo_sale_multiple_supply_methods.product_template_embryo_customer_provided').sudo()
# 创建坯料客供料的批量不需要创建bom
material_customer_provided_embryo = self.env['product.template'].sudo().no_bom_product_create(
customer_provided_embryo.with_context(active_test=False).product_variant_id,
item,
order_id, 'material_customer_provided', product_seria, product)
# 成品配置bom
product_bom_material_customer_provided = self.env['mrp.bom'].with_user(
self.env.ref("base.user_admin")).bom_create(
product, bom_type, 'product', code)
product_bom_material_customer_provided.with_user(
self.env.ref("base.user_admin")).bom_create_line_has(
material_customer_provided_embryo)
self.bom_id = product_bom_material_customer_provided.id
elif self.product_id.materials_type_id.gain_way == '自加工':
self_machining_id = self.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo()
# 创建坯料
self_machining_embryo = self.env['product.template'].sudo().no_bom_product_create(
self_machining_id,
item,
order_id, 'self_machining', product_seria, product)
# 创建坯料的bom
self_machining_bom = self.env['mrp.bom'].with_user(
self.env.ref("base.user_admin")).bom_create(
self_machining_embryo, 'normal', False)
# 创建坯料里bom的组件
self_machining_bom_line = self_machining_bom.with_user(
self.env.ref("base.user_admin")).bom_create_line(
self_machining_embryo)
if not self_machining_bom_line:
raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配')
# 产品配置bom
product_bom_self_machining = self.env['mrp.bom'].with_user(
self.env.ref("base.user_admin")).bom_create(
product, bom_type, 'product', code)
product_bom_self_machining.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
self_machining_embryo)
self.bom_id = product_bom_self_machining.id
elif self.product_id.materials_type_id.gain_way == '外协':
outsource_id = self.env.ref('sf_dlm.product_embryo_sf_outsource').sudo()
# 创建坯料
outsource_embryo = self.env['product.template'].sudo().no_bom_product_create(outsource_id,
item,
order_id,
'subcontract',
product_seria,
product)
if outsource_embryo == -3:
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
# 创建坯料的bom
outsource_bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create(
outsource_embryo,
'subcontract', True)
# 创建坯料的bom的组件
outsource_bom_line = outsource_bom.with_user(
self.env.ref("base.user_admin")).bom_create_line(outsource_embryo)
if not outsource_bom_line:
raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配')
# 产品配置bom
product_bom_outsource = self.env['mrp.bom'].with_user(
self.env.ref("base.user_admin")).bom_create(product, bom_type, 'product', code)
product_bom_outsource.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
outsource_embryo)
self.bom_id = product_bom_outsource.id
elif self.product_id.materials_type_id.gain_way == '采购':
purchase_id = self.env.ref('sf_dlm.product_embryo_sf_purchase').sudo()
purchase_embryo = self.env['product.template'].sudo().no_bom_product_create(purchase_id,
item,
order_id,
'purchase',
product_seria,
product)
if purchase_embryo and purchase_embryo == -3:
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
else:
# 产品配置bom
product_bom_purchase = self.env['mrp.bom'].with_user(
self.env.ref("base.user_admin")).bom_create(product, bom_type, 'product', code)
product_bom_purchase.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
purchase_embryo)
self.bom_id = product_bom_purchase.id
def _action_launch_stock_rule(self):
"""
触发库存规则(如采购、生产),并确认相关拣货单。
"""
procurements = []
group_id = self.sale_order_id.procurement_group_id
if not group_id:
# 没有分组则创建
group_id = self.env['procurement.group'].create(self._prepare_procurement_group_vals())
self.sale_order_id.procurement_group_id = group_id
else:
# 若已有分组但字段有变动则更新
updated_vals = {}
if group_id.partner_id != self.sale_order_id.partner_shipping_id:
updated_vals.update({'partner_id': self.sale_order_id.partner_shipping_id.id})
@@ -888,42 +861,27 @@ class SfProductionDemandPlan(models.Model):
updated_vals.update({'move_type': self.sale_order_id.picking_policy})
if updated_vals:
group_id.write(updated_vals)
# 构造 procurement 所需的字段
values = self._prepare_procurement_values(group_id=group_id)
# 单位换算
line_uom = self.sale_order_line_id.product_uom
quant_uom = self.product_id.uom_id
plan_uom_qty, procurement_uom = line_uom._adjust_uom_quantities(self.plan_uom_qty, quant_uom)
# 创建 procurement 请求
procurements.append(self.env['procurement.group'].Procurement(
self.product_id, plan_uom_qty, procurement_uom,
self.sale_order_id.partner_shipping_id.property_stock_customer,
self.product_id.display_name, self.sale_order_id.name, self.sale_order_id.company_id, values))
# 执行调度
if procurements:
procurement_group = self.env['procurement.group']
if self.env.context.get('import_file'):
procurement_group = procurement_group.with_context(import_file=False)
procurement_group.run(procurements)
# 确认相关的拣货单
orders = self.mapped('sale_order_id')
for order in orders:
pickings_to_confirm = order.picking_ids.filtered(lambda p: p.state not in ['cancel', 'done'])
if pickings_to_confirm:
pickings_to_confirm.action_confirm()
return True
def _prepare_procurement_group_vals(self):
"""
构造创建 procurement group 所需的字段。
"""
return {
'name': self.sale_order_id.name,
'move_type': self.sale_order_id.picking_policy,
@@ -931,18 +889,11 @@ class SfProductionDemandPlan(models.Model):
'partner_id': self.sale_order_id.partner_shipping_id.id,
}
def _prepare_procurement_values(self, group_id=False):
"""
构造单个 procurement 请求所需的字段字典。
"""
self.ensure_one()
# 交货日期与计划日期
date_deadline = self.sale_order_id.commitment_date or (
self.sale_order_id.date_order + timedelta(days=self.sale_order_line_id.customer_lead or 0.0))
self.sale_order_id.date_order + timedelta(days=self.sale_order_line_id.customer_lead or 0.0))
date_planned = date_deadline - timedelta(days=self.sale_order_id.company_id.security_lead)
values = {
'group_id': group_id,
'sale_line_id': self.sale_order_line_id.id,
@@ -958,6 +909,63 @@ class SfProductionDemandPlan(models.Model):
'sequence': self.sale_order_line_id.sequence,
'demand_plan_line_id': self.id
}
return values
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)])
picking_ids = self.env['stock.picking'].sudo().search(
[('demand_plan_line_ids', 'in', self.ids)])
return {
'name': _('详情'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'sf.demand.plan.detail.wizard',
'target': 'new',
'views': [(False, 'form')],
'context': {
'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,
'default_in_stock_picking_ids': picking_ids.filtered(
lambda o: o.picking_type_sequence_code == 'IN'
).ids,
'default_dl_stock_picking_ids': picking_ids.filtered(
lambda o: o.picking_type_sequence_code == 'DL'
).ids,
'default_int_stock_picking_ids': picking_ids.filtered(
lambda o: o.picking_type_sequence_code == 'INT'
).ids,
'default_pc_stock_picking_ids': picking_ids.filtered(
lambda o: o.picking_type_sequence_code == 'PC'
).ids,
'default_sfp_stock_picking_ids': picking_ids.filtered(
lambda o: o.picking_type_sequence_code == 'SFP'
).ids,
'default_onin_stock_picking_ids': picking_ids.filtered(
lambda o: o.picking_type_sequence_code == 'OCIN'
).ids,
'default_ocout_stock_picking_ids': picking_ids.filtered(
lambda o: o.picking_type_sequence_code == 'OCOUT'
).ids,
'default_out_stock_picking_ids': picking_ids.filtered(
lambda o: o.picking_type_sequence_code == 'OUT'
).ids,
'default_res_stock_picking_ids': picking_ids.filtered(
lambda o: o.picking_type_sequence_code == 'RES'
).ids,
}}

View File

@@ -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]

View File

@@ -0,0 +1,16 @@
from odoo import fields, api, models, _
class StockPicking(models.Model):
_inherit = "stock.picking"
demand_plan_line_ids = fields.Many2many(comodel_name="sf.production.demand.plan",
string="需求计划明细", compute='_compute_demand_plan_line_ids', store=True)
@api.depends('move_ids_without_package')
def _compute_demand_plan_line_ids(self):
for line in self:
demand_plan_lines = self.env['sf.production.demand.plan']
if line.move_ids_without_package and line.move_ids_without_package.demand_plan_line_ids:
demand_plan_lines |= line.move_ids_without_package.demand_plan_line_ids
line.demand_plan_line_ids = demand_plan_lines.ids

View File

@@ -13,4 +13,7 @@ access_stock_route_group,stock.route.group,model_stock_route_group,base.group_us
access_stock_route_group_dispatch,stock.route.group.dispatch,model_stock_route_group,sf_base.group_plan_dispatch,1,1,0,0
access_sf_release_plan_wizard,sf.release.plan.wizard,model_sf_release_plan_wizard,base.group_user,1,0,0,0
access_sf_release_plan_wizard_for_dispatch,sf.release.plan.wizard for dispatch,model_sf_release_plan_wizard,sf_base.group_plan_dispatch,1,1,1,1
access_sf_release_plan_wizard_for_dispatch,sf.release.plan.wizard for dispatch,model_sf_release_plan_wizard,sf_base.group_plan_dispatch,1,1,1,1
access_sf_demand_plan_detail_wizard,sf.demand.plan.detail.wizard,model_sf_demand_plan_detail_wizard,base.group_user,1,0,0,0
access_sf_demand_plan_detail_wizard_for_dispatch,sf.demand.plan.detail.wizard for dispatch,model_sf_demand_plan_detail_wizard,sf_base.group_plan_dispatch,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
13 access_sf_demand_plan_detail_wizard_for_dispatch sf.demand.plan.detail.wizard for dispatch model_sf_demand_plan_detail_wizard sf_base.group_plan_dispatch 1 1 1 1
14
15
16
17
18
19

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

@@ -92,6 +92,10 @@
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
/>
<button name="edit_button" type="object" string="拆分" class="btn-primary"/>
<button string="详情" name="button_plan_detail" type="object"
class="btn-primary"
attrs="{'invisible': [('status', 'not in', ('50','60'))]}"
/>
</tree>
</field>
</record>

View File

@@ -110,6 +110,7 @@
/>
<button string="详情" name="button_plan_detail" type="object"
class="btn-primary"
attrs="{'invisible': [('status', 'not in', ('50','60'))]}"
/>
</tree>
</field>

View File

@@ -1,2 +1,3 @@
from . import sf_demand_plan_print_wizard
from . import sf_release_plan_wizard
from . import sf_demand_plan_detail_wizard

View File

@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
import logging
from odoo import models, fields, api, _
_logger = logging.getLogger(__name__)
class SfDemandPlanDetailWizard(models.TransientModel):
_name = 'sf.demand.plan.detail.wizard'
_description = u'需求计划详情向导'
mrp_production_ids = fields.Many2many('mrp.production', string='关联制造订单', readonly=True)
purchase_request_ids = fields.Many2many('purchase.request', string='关联采购申请', readonly=True)
standard_purchase_order_ids = fields.Many2many('purchase.order', string='关联标准采购',
relation='standard_purchase_order_rel',
column1='plan_detail_wizard_id', column2='purchase_order_id',
readonly=True)
consignment_purchase_order_ids = fields.Many2many('purchase.order', string='关联工序外协采购',
relation='consignment_purchase_order_rel',
column1='plan_detail_wizard_id', column2='purchase_order_id',
readonly=True)
outsourcing_purchase_order_ids = fields.Many2many('purchase.order', string='关联委外加工采购',
relation='outsourcing_purchase_order_rel',
column1='plan_detail_wizard_id', column2='purchase_order_id',
readonly=True)
outside_purchase_order_ids = fields.Many2many('purchase.order', string='关联外购订单采购',
relation='outside_purchase_order_rel',
column1='plan_detail_wizard_id', column2='purchase_order_id',
readonly=True)
in_stock_picking_ids = fields.Many2many('stock.picking', string='关联收料入库调拨单',
relation='in_stock_picking_rel',
column1='plan_detail_wizard_id', column2='stock_picking_id',
readonly=True)
dl_stock_picking_ids = fields.Many2many('stock.picking', string='关联客供料入库调拨单',
relation='dl_stock_picking_rel',
column1='plan_detail_wizard_id', column2='stock_picking_id',
readonly=True)
int_stock_picking_ids = fields.Many2many('stock.picking', string='关联内部调拨',
relation='int_stock_picking_rel',
column1='plan_detail_wizard_id', column2='stock_picking_id',
readonly=True)
pc_stock_picking_ids = fields.Many2many('stock.picking', string='关联生产发料调拨单',
relation='pc_stock_picking_rel',
column1='plan_detail_wizard_id', column2='stock_picking_id',
readonly=True)
sfp_stock_picking_ids = fields.Many2many('stock.picking', string='关联生产入库调拨单',
relation='sfp_stock_picking_rel',
column1='plan_detail_wizard_id', column2='stock_picking_id',
readonly=True)
onin_stock_picking_ids = fields.Many2many('stock.picking', string='关联外协入库调拨单',
relation='onin_stock_picking_rel',
column1='plan_detail_wizard_id', column2='stock_picking_id',
readonly=True)
ocout_stock_picking_ids = fields.Many2many('stock.picking', string='关联外协出库调拨单',
relation='ocout_stock_picking_rel',
column1='plan_detail_wizard_id', column2='stock_picking_id',
readonly=True)
out_stock_picking_ids = fields.Many2many('stock.picking', string='关联发料出库调拨单',
relation='out_stock_picking_rel',
column1='plan_detail_wizard_id', column2='stock_picking_id',
readonly=True)
res_stock_picking_ids = fields.Many2many('stock.picking', string='关联委外发料调拨单',
relation='res_stock_picking_rel',
column1='plan_detail_wizard_id', column2='stock_picking_id',
readonly=True)

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="action_plan_detail_form" model="ir.ui.view">
<field name="name">sf.demand.plan.detail.wizard.form</field>
<field name="model">sf.demand.plan.detail.wizard</field>
<field name="arch" type="xml">
<form string="详情">
<notebook>
<page string="采购申请" attrs="{'invisible': [('purchase_request_ids', '=', [])]}">
<field name="purchase_request_ids" widget="many2many"/>
</page>
<page string="制造订单" attrs="{'invisible': [('mrp_production_ids', '=', [])]}">
<field name="mrp_production_ids" widget="many2many"/>
</page>
<page string="标准采购" attrs="{'invisible': [('standard_purchase_order_ids', '=', [])]}">
<field name="standard_purchase_order_ids" widget="many2many"/>
</page>
<page string="工序外协采购" attrs="{'invisible': [('consignment_purchase_order_ids', '=', [])]}">
<field name="consignment_purchase_order_ids" widget="many2many"/>
</page>
<page string="委外加工采购" attrs="{'invisible': [('outsourcing_purchase_order_ids', '=', [])]}">
<field name="outsourcing_purchase_order_ids" widget="many2many"/>
</page>
<page string="外购订单采购" attrs="{'invisible': [('outside_purchase_order_ids', '=', [])]}">
<field name="outside_purchase_order_ids" widget="many2many"/>
</page>
<page string="收料入库" attrs="{'invisible': [('in_stock_picking_ids', '=', [])]}">
<field name="in_stock_picking_ids" widget="many2many"/>
</page>
<page string="客供料入库" attrs="{'invisible': [('dl_stock_picking_ids', '=', [])]}">
<field name="dl_stock_picking_ids" widget="many2many"/>
</page>
<page string="内部调拨" attrs="{'invisible': [('int_stock_picking_ids', '=', [])]}">
<field name="int_stock_picking_ids" widget="many2many"/>
</page>
<page string="生产发料" attrs="{'invisible': [('pc_stock_picking_ids', '=', [])]}">
<field name="pc_stock_picking_ids" widget="many2many"/>
</page>
<page string="生产入库" attrs="{'invisible': [('sfp_stock_picking_ids', '=', [])]}">
<field name="sfp_stock_picking_ids" widget="many2many"/>
</page>
<page string="外协入库" attrs="{'invisible': [('onin_stock_picking_ids', '=', [])]}">
<field name="onin_stock_picking_ids" widget="many2many"/>
</page>
<page string="外协出库" attrs="{'invisible': [('ocout_stock_picking_ids', '=', [])]}">
<field name="ocout_stock_picking_ids" widget="many2many"/>
</page>
<page string="发料出库" attrs="{'invisible': [('out_stock_picking_ids', '=', [])]}">
<field name="out_stock_picking_ids" widget="many2many"/>
</page>
<page string="委外发料" attrs="{'invisible': [('res_stock_picking_ids', '=', [])]}">
<field name="res_stock_picking_ids" widget="many2many"/>
</page>
</notebook>
</form>
</field>
</record>
</odoo>

View File

@@ -5,7 +5,7 @@ from odoo import models, fields, api, _
_logger = logging.getLogger(__name__)
class SfDemandPlanPrintWizard(models.TransientModel):
class SfDemandPlanPrintWizard(models.Model):
_name = 'sf.demand.plan.print.wizard'
_description = u'打印向导'
@@ -37,7 +37,7 @@ class SfDemandPlanPrintWizard(models.TransientModel):
if pdf_data:
try:
# 执行打印
# self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
record.status = 'success'
production_demand_plan_id = self.env['sf.production.demand.plan'].sudo().search(
[('model_id', '=', record.model_id)])