物料需求计划管理

This commit is contained in:
guanhuan
2025-06-25 15:33:24 +08:00
parent deda36a0f9
commit 413cf43ea0
3 changed files with 39 additions and 48 deletions

View File

@@ -50,19 +50,10 @@ class ReSaleOrder(models.Model):
def action_view_demand_plan(self):
self.ensure_one()
demand_plan_ids = self.env['sf.production.demand.plan'].sudo().search([('sale_order_id', '=', self.id)]).ids
action = {
return {
'res_model': 'sf.production.demand.plan',
'type': 'ir.actions.act_window',
'name': _("需求计划"),
'domain': [('id', 'in', demand_plan_ids)],
'view_mode': 'tree',
}
if len(demand_plan_ids) == 1:
action.update({
'view_mode': 'form',
'res_id': demand_plan_ids[0],
})
else:
action.update({
'name': _("需求计划"),
'domain': [('id', 'in', demand_plan_ids)],
'view_mode': 'tree',
})
return action

View File

@@ -30,7 +30,7 @@ class SfProductionDemandPlan(models.Model):
('50', '待下达生产'),
('60', '已下达'),
('100', '取消'),
], string='状态', default='30', compute='_compute_status', store=True)
], string='状态', default='30', readonly=True)
demand_plan_id = fields.Many2one(comodel_name="sf.demand.plan",
string="物料需求", readonly=True)
sale_order_id = fields.Many2one(comodel_name="sale.order",
@@ -154,41 +154,41 @@ class SfProductionDemandPlan(models.Model):
[('demand_plan_selectable', '=', True), ('stock_route_group_ids', '=', group_id.id)])
if route_ids:
pdp.route_ids = route_ids.ids
break
continue
pdp.route_ids = None
@api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line',
'sale_order_id.mrp_production_ids.state')
def _compute_status(self):
for record in self:
if record.sale_order_id:
sale_order_state = record.sale_order_id.state
if sale_order_state in ('draft', 'sent', 'supply method'):
record.status = '20' # 待确认
if record.supply_method in ('purchase', 'outsourcing') and sale_order_state in (
'sale', 'processing', 'physical_distribution', 'delivered',
'done') and sale_order_state != 'cancel':
record.status = '60' # 已下达
if record.supply_method in ('automation', 'manual'):
if sale_order_state in (
'sale', 'processing', 'physical_distribution', 'delivered',
'done') and sale_order_state != 'cancel':
record.status = '30' # 需求确认
# 检查所有制造订单的排程单状态,有一个为待排程状态,就为待下达生产
pending_productions = record.sale_order_id.mrp_production_ids.filtered(
lambda p: p.state == 'confirmed' and p.product_id.id == record.product_id.id
)
if pending_productions:
record.status = '50' # 待下达生产
# 检查所有制造订单的排程单状态
if record.sale_order_id.mrp_production_ids:
product_productions = record.sale_order_id.mrp_production_ids.filtered(
lambda p: p.product_id.id == record.product_id.id
)
if product_productions and all(order.schedule_state != '未排' for order in product_productions):
record.status = '60' # 已下达
if sale_order_state == 'cancel' or not record.sale_order_line_id:
record.status = '100' # 取消
# @api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line',
# 'sale_order_id.mrp_production_ids.state')
# def _compute_status(self):
# for record in self:
# if record.sale_order_id:
# sale_order_state = record.sale_order_id.state
# if sale_order_state in ('draft', 'sent', 'supply method'):
# record.status = '20' # 待确认
# if record.supply_method in ('purchase', 'outsourcing') and sale_order_state in (
# 'sale', 'processing', 'physical_distribution', 'delivered',
# 'done') and sale_order_state != 'cancel':
# record.status = '60' # 已下达
# if record.supply_method in ('automation', 'manual'):
# if sale_order_state in (
# 'sale', 'processing', 'physical_distribution', 'delivered',
# 'done') and sale_order_state != 'cancel':
# record.status = '30' # 需求确认
# # 检查所有制造订单的排程单状态,有一个为待排程状态,就为待下达生产
# pending_productions = record.sale_order_id.mrp_production_ids.filtered(
# lambda p: p.state == 'confirmed' and p.product_id.id == record.product_id.id
# )
# if pending_productions:
# record.status = '50' # 待下达生产
# # 检查所有制造订单的排程单状态
# if record.sale_order_id.mrp_production_ids:
# product_productions = record.sale_order_id.mrp_production_ids.filtered(
# lambda p: p.product_id.id == record.product_id.id
# )
# if product_productions and all(order.schedule_state != '未排' for order in product_productions):
# record.status = '60' # 已下达
# if sale_order_state == 'cancel' or not record.sale_order_line_id:
# record.status = '100' # 取消
@api.depends('sale_order_line_id.product_id.name')
def _compute_sale_order_line_number(self):

View File

@@ -19,7 +19,7 @@ class SfStockRoute(models.Model):
[('supply_method', 'in', stock_route_group)])
if demand_plan_ids:
sr.demand_plan_ids = demand_plan_ids.ids
break
continue
sr.demand_plan_ids = None
# def name_get(self):