Accept Merge Request #2284: (feature/物料需求计划管理 -> develop)

Merge Request: 校验修改

Created By: @管欢
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @管欢
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2284
This commit is contained in:
管欢
2025-07-14 16:16:20 +08:00
committed by Coding
3 changed files with 28 additions and 21 deletions

View File

@@ -38,7 +38,7 @@ class SfDemandPlan(models.Model):
related='product_id.blank_type')
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型',
related='product_id.blank_precision')
manual_quotation = fields.Boolean('人工编程',related='product_id.manual_quotation', default=False)
manual_quotation = fields.Boolean('人工编程', related='product_id.manual_quotation', default=False)
embryo_long = fields.Char('坯料尺寸(mm)', compute='_compute_embryo_long', store=True)
is_incoming_material = fields.Boolean('客供料', related='sale_order_line_id.is_incoming_material', store=True)
pending_qty = fields.Float(
@@ -222,15 +222,12 @@ class SfDemandPlan(models.Model):
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty'))
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
for line in self.line_ids:
if line.manual_quotation and line.custom_made_type == 'automation':
raise ValidationError(f"产品{line.product_id.name}为人工编程,不能选择自动化产线加工")
if not self.overdelivery_allowed and line_ids.filtered(lambda p: p.location_id.id == customer_location_id):
if float_compare(sum_product_uom_qty, self.product_uom_qty,
precision_rounding=self.product_id.uom_id.rounding) == 1:
precision_rounding=self.product_id.uom_id.rounding) == 1:
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
elif float_compare(sum_product_uom_qty, self.product_uom_qty,
precision_rounding=self.product_id.uom_id.rounding) == 1:
precision_rounding=self.product_id.uom_id.rounding) == 1:
return {
'name': _('需求计划'),
'type': 'ir.actions.act_window',
@@ -246,11 +243,12 @@ class SfDemandPlan(models.Model):
else:
for demand_plan_line_id in line_ids:
demand_plan_line_id.action_confirm()
#需求要求取值格式是来源+来源明细行ID,但是来源明细行ID取得就是product_id.name得最后一位所以这里也直接截取product_id.name
# 需求要求取值格式是来源+来源明细行ID,但是来源明细行ID取得就是product_id.name得最后一位所以这里也直接截取product_id.name
@api.depends('product_id.name')
def _compute_demand_plan_number(self):
for line in self:
product_name = line.product_id.name or ''
product_name = line.product_id.name or ''
plan_no = None
if line.product_id:
# 使用正则表达式匹配P-后面的所有字符
@@ -259,4 +257,4 @@ class SfDemandPlan(models.Model):
plan_no = match.group(1)
line.demand_plan_number = plan_no
else:
line.demand_plan_number = None
line.demand_plan_number = None

View File

@@ -81,6 +81,7 @@ class SfProductionDemandPlan(models.Model):
related='product_id.blank_type')
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型',
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')
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
@@ -169,22 +170,30 @@ class SfProductionDemandPlan(models.Model):
finished_product_arrival_date = fields.Date('采购计划到货(成品)')
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
manual_quotation = fields.Boolean('人工编程',related='product_id.manual_quotation',default=False)
manual_quotation = fields.Boolean('人工编程', related='product_id.manual_quotation', default=False)
@api.constrains('plan_uom_qty')
def _check_plan_uom_qty(self):
line_ids = self.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0)
if line_ids:
raise ValidationError(_("计划量不能小于等于0"))
@api.constrains('new_supply_method')
def _check_new_supply_method(self):
@api.constrains('supply_method')
def _check_supply_method(self):
product_name = []
product = []
for line in self:
if line.new_supply_method == 'purchase' and line.is_incoming_material:
if line.supply_method == 'purchase' and line.is_incoming_material:
product_name.append(line.product_id.display_name)
if line.supply_method == 'automation' and line.manual_quotation:
product.append(line.product_id.display_name)
if product_name:
unique_product_names = list(set(product_name))
raise UserError('当前(%s)产品为客供料,不能选择外购' % ','.join(unique_product_names))
if product:
unique_product = list(set(product))
raise UserError('当前(%s)产品为人工编程,不能选择自动化产线加工' % ','.join(unique_product))
@api.depends('new_supply_method')
def _compute_custom_made_type(self):
@@ -346,7 +355,8 @@ class SfProductionDemandPlan(models.Model):
def update_sale_order_state(self):
# demand_plan = self.env['sf.demand.plan'].sudo().search([('sale_order_id', '=', self.sale_order_id.id)])
# demand_plan_state = demand_plan.filtered(lambda line: line.state != '40')
production_demand_plan = self.env['sf.production.demand.plan'].sudo().search([('sale_order_id', '=', self.sale_order_id.id)])
production_demand_plan = self.env['sf.production.demand.plan'].sudo().search(
[('sale_order_id', '=', self.sale_order_id.id)])
production_demand_plan_state = production_demand_plan.filtered(lambda line: line.status in ('10', '20', '30'))
if not production_demand_plan_state:
# 修改销售订单为加工中
@@ -618,7 +628,7 @@ class SfProductionDemandPlan(models.Model):
warning_messages = []
for product, data in product_data.items():
if float_compare(data['plan_uom_qty'], data['product_uom_qty'],
precision_rounding=product.uom_id.rounding) == 1:
precision_rounding=product.uom_id.rounding) == 1:
warning_messages.append(
_("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") %
(product.display_name, data['plan_uom_qty'], data['product_uom_qty'])
@@ -642,19 +652,17 @@ class SfProductionDemandPlan(models.Model):
def button_release_plan(self):
self.ensure_one()
if not self.new_supply_method:
raise ValidationError(f"供货方式不能为空!")
if self.product_id.manual_quotation and self.custom_made_type == 'automation':
raise ValidationError(f"产品{self.product_id.name}为人工编程,不能选择自动化产线加工")
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')
if self.location_id.id == customer_location_id:
check_overdelivery_allowed = True
if check_overdelivery_allowed:
if float_compare(self.plan_uom_qty, self.product_uom_qty,precision_rounding=self.product_id.uom_id.rounding) == 1:
if float_compare(self.plan_uom_qty, self.product_uom_qty,
precision_rounding=self.product_id.uom_id.rounding) == 1:
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
elif float_compare(self.plan_uom_qty, self.product_uom_qty,precision_rounding=self.product_id.uom_id.rounding) == 1:
elif float_compare(self.plan_uom_qty, self.product_uom_qty,
precision_rounding=self.product_id.uom_id.rounding) == 1:
return {
'name': _('需求计划'),
'type': 'ir.actions.act_window',

View File

@@ -39,6 +39,7 @@
<field name="blank_type" optional="hide"/>
<field name="blank_precision"/>
<field name="embryo_long"/>
<field name="unit_number" optional="hide"/>
<field name="materials_id"/>
<field name="model_machining_precision"/>
<field name="model_process_parameters_ids" widget="many2many_tags"/>