搭建排程基础架构

This commit is contained in:
mgw
2023-08-24 11:24:27 +08:00
parent 0b30408aae
commit bf7ef78b20
5 changed files with 111 additions and 7 deletions

View File

@@ -14,6 +14,49 @@ class MrpProduction(models.Model):
model_file = fields.Binary('模型文件', related='product_id.model_file')
schedule_state = fields.Selection([('未排', '未排'), ('已排', '已排')],
string='排程状态', default='未排')
# state = fields.Selection(selection_add=[('未排程', '未排程'), ('已排程', '已排程')])
# 生产线
production_line_id = fields.Many2one('sf.production.line', string='生产线')
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('未排程', '未排程'), ('已排程', '已排程'),
('progress', 'In Progress'),
('to_close', 'To Close'),
('done', 'Done'),
('cancel', 'Cancelled')], string='State',
compute='_compute_state', copy=False, index=True, readonly=True,
store=True, tracking=True,
help=" * Draft: The MO is not confirmed yet.\n"
" * Confirmed: The MO is confirmed, the stock rules and the reordering of the components are trigerred.\n"
" * In Progress: The production has started (on the MO or on the WO).\n"
" * To Close: The production is done, the MO has to be closed.\n"
" * Done: The MO is closed, the stock moves are posted. \n"
" * Cancelled: The MO has been cancelled, can't be confirmed anymore.")
# 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
def action_view_production_schedule(self):
self.ensure_one()
self.state = '已排程'
# if self.plan_start_time and self.plan_end_time:
# return None
# elif self.plan_start_time and not self.plan_end_time:
# # 如果没有给出计划结束时间,则计划结束时间为计划开始时间+采购周期+缓冲期
# # 采购周期
# purchase_cycle = 3
# # 缓冲期
# buffer_period = 1
# # 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期
# self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(days=buffer_period)
# return self.plan_end_time
# else:
# return None
def cancel_plan(self):
self.ensure_one()
self.state = 'confirmed'
# self.plan_start_time = None
# self.plan_end_time = None
@api.depends('request_ids')
def _compute_maintenance_count(self):

View File

@@ -40,7 +40,60 @@
decoration-warning="reservation_state != 'assigned' and components_availability_state in ('expected', 'available')"
decoration-danger="reservation_state != 'assigned' and components_availability_state == 'late'"/>
</xpath>
<xpath expr="//field[@name='state']" position="after">
<button name="action_view_production_schedule" string="生产排程" type="object" attrs="{'invisible': [('state', 'in', ['draft', 'cancel','已排程','progress','done','to_close'])]}"/>
<button name="cancel_plan" string="取消排程" type="object" attrs="{'invisible': [('state', 'in', ['draft', 'cancel','progress','done','to_close','confirmed'])]}"/>
</xpath>
</field>
</record>
<record id="custom_mrp_production_form_view" model="ir.ui.view">
<field name="name">custom.mrp.production.form</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="arch" type="xml">
<xpath expr="//header//field[@name='state']" position="replace">
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,已排程,progress,done"/>
</xpath>
<xpath expr="//header" position="inside">
<button name="action_view_production_schedule" string="生产排程" type="object" attrs="{'invisible': [('state', 'in', ['draft', 'cancel','已排程','progress','done','to_close'])]}"/>
<button name="cancel_plan" string="取消排程" type="object" attrs="{'invisible': [('state', 'in', ['draft', 'cancel','progress','done','to_close','confirmed'])]}"/>
</xpath>
<xpath expr="//sheet//group//group//field[@name='product_id']" position="after">
<field name="production_line_id"/>
</xpath>
</field>
</record>
<record id="custom_view_mrp_production_filter" model="ir.ui.view">
<field name="name">custom.mrp.production.select</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.view_mrp_production_filter"/>
<field name="arch" type="xml">
<xpath expr="//search" position="inside">
<searchpanel class="account_root">
<field name="state" icon="fa-filter"/>
</searchpanel>
</xpath>
<filter name='todo' position="replace"/>
</field>
</record>
<!-- <xpath expr="//filter[@name='filter_draft']" position="after"> -->
<!-- <filter string="已完成" name="filter_done" domain="[('state', '=', 'done')]"/> -->
<!-- </xpath> -->
<!-- <xpath expr="//filter[@name='filter_draft']" position="after"> -->
<!-- <filter string="已取消" name="filter_cancel" domain="[('state', '=', 'cancel')]"/> -->
<!-- </xpath> -->
<!-- <xpath expr="//filter[@name='filter_draft']" position="after"> -->
<!-- <filter string="进行中" name="filter_progress" domain="[('state', '=', 'progress')]"/> -->
<!-- </xpath> -->
<!-- <xpath expr="//filter[@name='filter_draft']" position="after"> -->
<!-- <filter string="已确认" name="filter_confirmed" domain="[('state', '=', 'confirmed')]"/> -->
<!-- </xpath> -->
<!-- <xpath expr="//filter[@name='filter_draft']" position="after"> -->
<!-- <filter string="草稿" name="filter_draft" domain="[('state', '=', 'draft')]"/> -->
<!-- </xpath> -->
</data>
</odoo>

View File

@@ -13,7 +13,7 @@
'author': 'jikimo',
'website': 'https://sf.cs.jikimo.com',
# 此处依赖sf_manufacturing是因为我要重写其中的一个字段operation_id的string故需要sf_manufacturing先安装
'depends': ['mrp', 'mrp_workorder'],
'depends': ['mrp', 'mrp_workorder', 'sf_manufacturing'],
'data': [
'security/ir.model.access.csv',
'views/view.xml'

View File

@@ -13,7 +13,8 @@ class sf_pl_plan(models.Model):
# sequence = fields.Integer(string='序号', required=True, copy=False, readonly=True, index=True,
# default=lambda self: self.env['ir.sequence'].sudo().next_by_code('sf.pl.plan'))
sequence = fields.Integer(string='序号', required=True, copy=False, readonly=True, index=True)
current_operation_name = fields.Char(string='当前工序名称', size=64, default='坯料预制')
current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划')
production_line_id = fields.Many2one('sf.production.line', string='生产线')
@api.model
def create(self, vals):

View File

@@ -43,6 +43,7 @@
<field name="plan_start_time"/>
<field name="plan_end_time"/>
<field name="state"/>
<field name="production_line_id"/>
</group>
<group string="规格信息" col="1">
<group col="3">
@@ -86,7 +87,7 @@
<field name="model">sf.pl.plan</field>
<field name="arch" type="xml">
<gantt class="o_mrp_workorder_gantt" date_stop="plan_end_time" date_start="plan_start_time"
string="坯料预制计划" default_group_by="current_operation_name" create="0"
string="制造订单生产计划" default_group_by="production_line_id" create="0"
delete="0" sample="1"
display_unavailability="1"
color="state"
@@ -142,16 +143,22 @@
</record>
<!-- <record id="sf_pl_plan_action" model="ir.actions.act_window"> -->
<!-- <field name="name">制造订单生产计划</field> -->
<!-- <field name="type">ir.actions.act_window</field> -->
<!-- <field name="res_model">sf.pl.plan</field> -->
<!-- <field name="view_mode">tree,form,gantt</field> -->
<!-- </record> -->
<record id="sf_pl_plan_action" model="ir.actions.act_window">
<field name="name">坯料预制计划</field>
<field name="name">造订单生产计划</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sf.pl.plan</field>
<field name="view_mode">tree,form,gantt</field>
<field name="res_model">mrp.production</field>
<field name="view_mode">gantt,tree,form</field>
</record>
<menuitem
id="sf_pl_plan_menu"
name="坯料预制计划"
name="制造订单生产计划"
parent="mrp_workorder.mrp_workorder_menu_planning"
sequence="10"
action="sf_pl_plan_action"