修改制造订单的状态字段以及与排程单的交互逻辑,优化一些翻译

This commit is contained in:
mgw
2024-01-08 19:02:59 +08:00
parent bc4a4df53e
commit fbaa81fe7a
6 changed files with 93 additions and 7 deletions

View File

@@ -12,12 +12,74 @@ class MrpProduction(models.Model):
maintenance_count = fields.Integer(compute='_compute_maintenance_count', string="Number of maintenance requests")
request_ids = fields.One2many('maintenance.request', 'production_id')
model_file = fields.Binary('模型文件', related='product_id.model_file')
schedule_state = fields.Selection([('未排', '未排'), ('已排', '已排')],
schedule_state = fields.Selection([('未排', '未排'), ('已排', '已排'), ('已完成', '已完成')],
string='排程状态', default='未排')
# state = fields.Selection(selection_add=[
# ('pending_scheduling', '待排程'),
# ('pending_processing', '待加工'),
# ('completed', '已完工')
# ])
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('progress', '待排程'),
('pending_processing', '待加工'),
('completed', '已完工'),
('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.")
check_status = fields.Boolean(string='启用状态', default=False, readonly=True)
active = fields.Boolean(string='已归档', default=True)
@api.depends(
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state',
'workorder_ids.state', 'product_qty', 'qty_producing', 'schedule_state')
def _compute_state(self):
for production in self:
if not production.state or not production.product_uom_id:
production.state = 'draft'
elif production.state == 'cancel' or (production.move_finished_ids and all(
move.state == 'cancel' for move in production.move_finished_ids)):
production.state = 'cancel'
elif (
production.state == 'done'
or (production.move_raw_ids and all(
move.state in ('cancel', 'done') for move in production.move_raw_ids))
and all(move.state in ('cancel', 'done') for move in production.move_finished_ids)
):
production.state = 'done'
elif production.workorder_ids and all(
wo_state in ('done', 'cancel') for wo_state in production.workorder_ids.mapped('state')):
production.state = 'to_close'
elif not production.workorder_ids and float_compare(production.qty_producing, production.product_qty,
precision_rounding=production.product_uom_id.rounding) >= 0:
production.state = 'to_close'
elif any(wo_state in ('progress', 'done') for wo_state in production.workorder_ids.mapped('state')):
production.state = 'progress'
elif production.product_uom_id and not float_is_zero(production.qty_producing,
precision_rounding=production.product_uom_id.rounding):
production.state = 'progress'
elif any(not float_is_zero(move.quantity_done,
precision_rounding=move.product_uom.rounding or move.product_id.uom_id.rounding)
for move in production.move_raw_ids):
production.state = 'progress'
# 新添加的状态逻辑
if production.state == 'progress' and production.schedule_state == '已排':
production.state = 'pending_processing'
elif production.state == 'progress' and production.schedule_state == '已完成':
production.state = 'completed'
def action_check(self):
"""
审核启用

View File

@@ -58,6 +58,9 @@
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='state']" position="attributes">
<attribute name="statusbar_visible">draft,confirmed,progress,pending_processing,completed,done</attribute>
</xpath>
<xpath expr="//form//header//button[@name='action_confirm']" position="after">
<field name="active" invisible="1"/>
<field name="check_status" invisible="1"/>

View File

@@ -12,14 +12,30 @@ class sf_production_plan(models.Model):
_name = 'sf.production.plan'
_description = 'sf_production_plan'
_inherit = ['mail.thread']
_order = 'state desc, write_date desc'
# _order = 'state desc, write_date desc'
state = fields.Selection([
('draft', '待排程'),
('done', '已排程'),
('processing', '加工'),
('processing', '加工'),
('finished', '已完成')
], string='工单状态', tracking=True)
state_order = fields.Integer(compute='_compute_state_order', store=True)
@api.depends('state')
def _compute_state_order(self):
order_mapping = {
'draft': 1,
'done': 2,
'processing': 3,
'finished': 4
}
for record in self:
record.state_order = order_mapping.get(record.state, 0)
_order = 'state_order asc, write_date desc'
name = fields.Char(string='工单编号')
active = fields.Boolean(string='已归档', default=True)
# selected = fields.Boolean(default=False)
@@ -51,6 +67,11 @@ class sf_production_plan(models.Model):
sequence = fields.Integer(string='序号', copy=False, readonly=True, index=True)
current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划')
@api.onchange('state')
def _onchange_state(self):
if self.state == 'finished':
self.production_id.schedule_state = '已完成'
# @api.model
# def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
# """

View File

@@ -11,7 +11,7 @@
<!-- <button name="do_production_schedule" type="object" string="批量排程"/> -->
<button string="批量排程" name="%(sf_plan.action_plan_some)d" type="action" class="btn-primary"/>
</header>
<field name="state" widget="badge" decoration-warning="state == 'draft'" decoration-success="state == 'done'"/>
<field name="state" widget="badge" decoration-warning="state == 'draft'" decoration-success="state == 'done'" decoration-info="state == 'processing'" decoration-danger="state == 'finished'"/>
<field name="name"/>
<field name="origin"/>
<field name="order_deadline"/>

View File

@@ -34,7 +34,7 @@ class Action_Plan_All_Wizard(models.TransientModel):
plan_obj = self.env['sf.production.plan'].browse(plan.id)
plan_obj.production_line_id = self.production_line_id.id
plan_obj.do_production_schedule()
plan_obj.state = 'done'
# plan_obj.state = 'done'
print('处理计划:', plan.id, '完成')
# # 获取当前生产线

View File

@@ -39704,7 +39704,7 @@ msgstr "付款中"
#: model_terms:ir.ui.view,arch_db:quality.quality_alert_view_search
#: model_terms:ir.ui.view,arch_db:quality_control.quality_check_view_search
msgid "In Progress"
msgstr "进行中"
msgstr "待排程"
#. module: stock
#: model:ir.model.fields,field_description:stock.field_stock_warehouse__in_type_id
@@ -112590,7 +112590,7 @@ msgstr ""
#: model:ir.model,name:sf_manufacturing.model_mrp_production
#: model:ir.ui.menu,name:sf_plan.mrp_custom_menu
msgid "制造订单"
msgstr "生产订单"
msgstr "制造订单"
#. module: sf_plan
#: model:ir.actions.act_window,name:sf_plan.sf_production_plan_action