需求计划

This commit is contained in:
guanhuan
2025-05-22 17:40:56 +08:00
parent 50f8bf5ab1
commit e46e6dfc2a
3 changed files with 51 additions and 6 deletions

View File

@@ -20,12 +20,13 @@ class sf_production_plan(models.Model):
('4', ''), ('4', ''),
], string='优先级', default='3') ], string='优先级', default='3')
status = fields.Selection([ status = fields.Selection([
('10', '草稿'),
('20', '待确认'), ('20', '待确认'),
('30', '需求确认'), ('30', '需求确认'),
('40', '待下达生产'),
('50', '已下达'), ('50', '已下达'),
('100', '取消'), ('100', '取消'),
], string='状态') ], string='状态', compute='_compute_status', store=True)
sale_order_id = fields.Many2one(comodel_name="sale.order", sale_order_id = fields.Many2one(comodel_name="sale.order",
string="销售订单") string="销售订单")
sale_order_line_id = fields.Many2one(comodel_name="sale.order.line", sale_order_line_id = fields.Many2one(comodel_name="sale.order.line",
@@ -75,7 +76,7 @@ class sf_production_plan(models.Model):
'plan_process_parameter_rel', 'plan_process_parameter_rel',
string='表面工艺', string='表面工艺',
compute='_compute_model_process_parameters_ids' compute='_compute_model_process_parameters_ids'
, store=True
) )
product_remark = fields.Char("产品备注", related='product_id.model_remark') product_remark = fields.Char("产品备注", related='product_id.model_remark')
order_code = fields.Char('E-SHOP订单号', related='sale_order_id.order_code') order_code = fields.Char('E-SHOP订单号', related='sale_order_id.order_code')
@@ -88,12 +89,35 @@ class sf_production_plan(models.Model):
processing_time = fields.Char('程序工时') processing_time = fields.Char('程序工时')
planned_start_date = fields.Date('计划开工日期') planned_start_date = fields.Date('计划开工日期')
actual_start_date = fields.Date('实际开工日期') actual_start_date = fields.Date('实际开工日期', compute='_compute_actual_start_date')
actual_end_date = fields.Date('实际完工日期') actual_end_date = fields.Date('实际完工日期')
print_count = fields.Char('打印次数', default='T0C0') print_count = fields.Char('打印次数', default='T0C0')
sequence = fields.Integer('序号') sequence = fields.Integer('序号')
@api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line')
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 = '50' # 已下达
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' # 需求确认
# 检查所有制造订单的排程单状态
if all(order.product_id == record.product_id and order.schedule_state != '未排' for order in
record.sale_order_id.mrp_production_ids):
record.status = '50' # 已下达
if sale_order_state == 'cancel' or not record.sale_order_line_id:
record.status = '100' # 取消
@api.depends('product_id.part_number', 'product_id.model_name') @api.depends('product_id.part_number', 'product_id.model_name')
def _compute_part_number(self): def _compute_part_number(self):
for line in self: for line in self:
@@ -151,6 +175,23 @@ class sf_production_plan(models.Model):
else: else:
line.inventory_quantity_auto_apply = 0.0 line.inventory_quantity_auto_apply = 0.0
@api.depends('sale_order_id.mrp_production_ids.workorder_ids.date_start')
def _compute_actual_start_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)
if manufacturing_orders:
start_dates = [
workorder.date_start.date() for mo in manufacturing_orders
for workorder in mo.workorder_ids if workorder.date_start
]
record.actual_start_date = min(start_dates) if start_dates else None
else:
record.actual_start_date = None
else:
record.actual_start_date = None
@api.constrains('planned_start_date') @api.constrains('planned_start_date')
def _check_planned_start_date(self): def _check_planned_start_date(self):
for record in self: for record in self:

View File

@@ -1,3 +1,7 @@
.demand_plan_tree th:not(.o_list_record_selector,.row_no,[data-name=sequence]) { .demand_plan_tree th:not(.o_list_record_selector,.row_no,[data-name=sequence]) {
min-width: 98px !important; min-width: 98px !important;
}
.demand_plan_tree .o_list_table_grouped th:not(.o_list_record_selector,.row_no,[data-name=sequence]) {
min-width: 98px !important;
} }

View File

@@ -3,7 +3,7 @@
<field name="name">sf.production.demand.plan.tree</field> <field name="name">sf.production.demand.plan.tree</field>
<field name="model">sf.production.demand.plan</field> <field name="model">sf.production.demand.plan</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="需求计划" default_order="create_date desc" class="demand_plan_tree"> <tree string="需求计划" default_order="create_date desc" editable="bottom" class="demand_plan_tree">
<field name="sequence" widget="handle"/> <field name="sequence" widget="handle"/>
<field name="priority"/> <field name="priority"/>
<field name="status"/> <field name="status"/>
@@ -24,7 +24,7 @@
<field name="model_long"/> <field name="model_long"/>
<field name="materials_id"/> <field name="materials_id"/>
<field name="model_machining_precision"/> <field name="model_machining_precision"/>
<field name="model_process_parameters_ids"/> <field name="model_process_parameters_ids" widget="many2many_tags"/>
<field name="product_remark" optional="hide"/> <field name="product_remark" optional="hide"/>
<field name="order_code" optional="hide"/> <field name="order_code" optional="hide"/>
<field name="sale_order_id" optional="hide"/> <field name="sale_order_id" optional="hide"/>