校验修改
This commit is contained in:
@@ -222,9 +222,6 @@ class SfDemandPlan(models.Model):
|
|||||||
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
|
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
|
||||||
sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty'))
|
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')
|
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 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,
|
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:
|
||||||
|
|||||||
@@ -170,22 +170,30 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
finished_product_arrival_date = fields.Date('采购计划到货(成品)')
|
finished_product_arrival_date = fields.Date('采购计划到货(成品)')
|
||||||
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
||||||
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, 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')
|
@api.constrains('plan_uom_qty')
|
||||||
def _check_plan_uom_qty(self):
|
def _check_plan_uom_qty(self):
|
||||||
line_ids = self.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0)
|
line_ids = self.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0)
|
||||||
if line_ids:
|
if line_ids:
|
||||||
raise ValidationError(_("计划量不能小于等于0"))
|
raise ValidationError(_("计划量不能小于等于0"))
|
||||||
|
|
||||||
@api.constrains('new_supply_method')
|
@api.constrains('supply_method')
|
||||||
def _check_new_supply_method(self):
|
def _check_supply_method(self):
|
||||||
product_name = []
|
product_name = []
|
||||||
|
product = []
|
||||||
for line in self:
|
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)
|
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:
|
if product_name:
|
||||||
unique_product_names = list(set(product_name))
|
unique_product_names = list(set(product_name))
|
||||||
raise UserError('当前(%s)产品为客供料,不能选择外购' % ','.join(unique_product_names))
|
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')
|
@api.depends('new_supply_method')
|
||||||
def _compute_custom_made_type(self):
|
def _compute_custom_made_type(self):
|
||||||
@@ -347,7 +355,8 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
def update_sale_order_state(self):
|
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 = 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')
|
# 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'))
|
production_demand_plan_state = production_demand_plan.filtered(lambda line: line.status in ('10', '20', '30'))
|
||||||
if not production_demand_plan_state:
|
if not production_demand_plan_state:
|
||||||
# 修改销售订单为加工中
|
# 修改销售订单为加工中
|
||||||
@@ -619,7 +628,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
warning_messages = []
|
warning_messages = []
|
||||||
for product, data in product_data.items():
|
for product, data in product_data.items():
|
||||||
if 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:
|
precision_rounding=product.uom_id.rounding) == 1:
|
||||||
warning_messages.append(
|
warning_messages.append(
|
||||||
_("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") %
|
_("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") %
|
||||||
(product.display_name, data['plan_uom_qty'], data['product_uom_qty'])
|
(product.display_name, data['plan_uom_qty'], data['product_uom_qty'])
|
||||||
@@ -643,19 +652,17 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
|
|
||||||
def button_release_plan(self):
|
def button_release_plan(self):
|
||||||
self.ensure_one()
|
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
|
check_overdelivery_allowed = False
|
||||||
if not self.demand_plan_id.overdelivery_allowed:
|
if not self.demand_plan_id.overdelivery_allowed:
|
||||||
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||||
if self.location_id.id == customer_location_id:
|
if self.location_id.id == customer_location_id:
|
||||||
check_overdelivery_allowed = True
|
check_overdelivery_allowed = True
|
||||||
if check_overdelivery_allowed:
|
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"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
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 {
|
return {
|
||||||
'name': _('需求计划'),
|
'name': _('需求计划'),
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
|
|||||||
Reference in New Issue
Block a user