需求计划

This commit is contained in:
guanhuan
2025-05-23 14:14:50 +08:00
parent e46e6dfc2a
commit a5243970d5
2 changed files with 48 additions and 6 deletions

View File

@@ -28,9 +28,9 @@ class sf_production_plan(models.Model):
('100', '取消'),
], string='状态', compute='_compute_status', store=True)
sale_order_id = fields.Many2one(comodel_name="sale.order",
string="销售订单")
string="销售订单", readonly=True)
sale_order_line_id = fields.Many2one(comodel_name="sale.order.line",
string="销售订单行")
string="销售订单行", readonly=True)
company_id = fields.Many2one(
related='sale_order_id.company_id',
store=True, index=True, precompute=True)
@@ -86,12 +86,15 @@ class sf_production_plan(models.Model):
route_id = fields.Many2one('stock.route', string='路线', related='sale_order_line_id.route_id', store=True)
date_order = fields.Datetime('下单日期', related='sale_order_id.date_order')
plan_remark = fields.Text("计划备注")
material_check = fields.Selection([
('0', "未齐套"),
('1', "已齐套"),
], string='投料齐套检查', compute='_compute_material_check', store=True)
processing_time = fields.Char('程序工时')
planned_start_date = fields.Date('计划开工日期')
actual_start_date = fields.Date('实际开工日期', compute='_compute_actual_start_date')
actual_end_date = fields.Date('实际完工日期')
print_count = fields.Char('打印次数', default='T0C0')
actual_start_date = fields.Date('实际开工日期', compute='_compute_actual_start_date', store=True)
actual_end_date = fields.Date('实际完工日期', compute='_compute_actual_end_date', store=True)
print_count = fields.Char('打印次数', default='T0C0', readonly=True)
sequence = fields.Integer('序号')
@@ -192,6 +195,44 @@ class sf_production_plan(models.Model):
else:
record.actual_start_date = None
@api.depends('sale_order_id.mrp_production_ids.workorder_ids.state',
'sale_order_id.mrp_production_ids.workorder_ids.date_finished')
def _compute_actual_end_date(self):
for record in self:
if record.sale_order_id and record.sale_order_id.mrp_production_ids:
manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered(
lambda mo: mo.product_id == record.product_id)
finished_orders = manufacturing_orders.filtered(lambda mo: mo.state == 'done')
if len(finished_orders) >= record.product_uom_qty:
end_dates = [
workorder.date_finished.date() for mo in finished_orders
for workorder in mo.workorder_ids if workorder.date_finished
]
record.actual_end_date = max(end_dates) if end_dates else None
else:
record.actual_end_date = None
else:
record.actual_end_date = None
@api.depends('sale_order_id.mrp_production_ids.move_raw_ids.forecast_availability',
'sale_order_id.mrp_production_ids.move_raw_ids.product_uom_qty')
def _compute_material_check(self):
for record in self:
if record.sale_order_id and record.sale_order_id.mrp_production_ids:
manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered(
lambda mo: mo.product_id == record.product_id)
if manufacturing_orders:
total_reserved = sum(mo.forecast_availability for mo in manufacturing_orders)
total_to_consume = sum(mo.product_uom_qty for mo in manufacturing_orders)
if total_reserved >= total_to_consume:
record.material_check = '1' # 已齐套
else:
record.material_check = '0' # 未齐套
else:
record.material_check = None
else:
record.material_check = None
@api.constrains('planned_start_date')
def _check_planned_start_date(self):
for record in self:

View File

@@ -33,6 +33,7 @@
<field name="route_id" optional="hide"/>
<field name="date_order"/>
<field name="plan_remark"/>
<field name="material_check"/>
<field name="processing_time"/>
<field name="planned_start_date"/>
<field name="actual_start_date"/>