申请编程需求

This commit is contained in:
mgw
2025-01-09 14:07:35 +08:00
parent 35fb6f7119
commit fc16c867aa
7 changed files with 179 additions and 1 deletions

View File

@@ -4,3 +4,4 @@ from . import production_wizard
from . import production_technology_wizard
from . import production_technology_re_adjust_wizard
from . import mrp_workorder_batch_replan_wizard
from . import sf_programming_reason

View File

@@ -0,0 +1,55 @@
from odoo import models, fields, api
class sf_programming_reason(models.TransientModel):
_name = 'sf.programming.reason'
_description = '重新编程原因'
production_id = fields.Many2one('mrp.production')
reason = fields.Text('重新编程原因')
reprogramming_count = fields.Integer(string='重新编程次数')
programming_state = fields.Char(string='编程状态')
@api.model
def default_get(self, fields):
res = super(sf_programming_reason, self).default_get(fields)
if self._context.get('active_id'):
production = self.env['mrp.production'].browse(self._context.get('active_id'))
res.update({
'reprogramming_count': production._cron_get_programming_state()['reprogramming_num'],
'programming_state': production.programming_state, # 假设制造订单模型中有这个字段
})
return res
def action_confirm(self):
print('self.production_id.programming_state:', self.production_id.programming_state)
self.production_id.update_programming_state()
self.production_id.write(
{'programming_state': '编程中', 'work_state': '编程中'})
cloud_programming = self.production_id._cron_get_programming_state()
self.production_id.programming_record_ids.create({
'number': len(self.production_id.programming_record_ids) + 1,
'production_id': self.production_id.id,
'reason': self.reason,
'programming_method': cloud_programming['programme_way'],
'current_programming_count': cloud_programming['reprogramming_num'],
'target_production_id': cloud_programming['production_order_no'],
'apply_time': self._context.get('apply_time'),
'send_time': cloud_programming['programming_time'],
})
# 返回弹窗提示“已下达编程任务和消息,请等待编程单下发”
return {
'type': 'ir.actions.act_window',
'res_model': 'sf.programming.reason',
'view_mode': 'form',
'target': 'new',
'context': {
'default_production_id': self.production_id.id,
'active_id': self.production_id.id,
},
'view_id': self.env.ref('sf_manufacturing.sf_programming_reason_message_view').id,
}

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="sf_programming_reason_form_view">
<field name="name">sf.programming.reason.form.view</field>
<field name="model">sf.programming.reason</field>
<field name="arch" type="xml">
<form>
<group>
<label for="reason" string="重新编程原因:"/>
<field name="reason" widget="textarea" nolabel="1"/>
<p class="text-muted">注意:该制造订单产品已申请重新编程次数为<field name="reprogramming_count" readonly="1" nolabel="1" class="oe_inline"/>,且当前编程状态为<field name="programming_state" readonly="1" nolabel="1" class="oe_inline"/></p>
</group>
<field name="production_id" invisible="True"/>
<footer>
<button name="action_confirm" string="确认" type="object" class="btn-primary"/>
<button string="丢弃" special="cancel" class="btn-secondary"/>
</footer>
</form>
</field>
</record>
<!-- 弹窗提示“已下达编程任务和消息,请等待编程单下发” -->
<record model="ir.ui.view" id="sf_programming_reason_message_view">
<field name="name">sf.programming.reason.message.view</field>
<field name="model">sf.programming.reason</field>
<field name="arch" type="xml">
<form>
<p>已下达编程任务和消息,请等待编程单下发!</p>
</form>
<footer>
<button string="关闭" special="cancel" class="btn-secondary"/>
</footer>
</field>
</record>
<!-- 重新编程原因弹窗 -->
<record id="sf_programming_reason_action" model="ir.actions.act_window">
<field name="name">重新编程原因</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sf.programming.reason</field>
<field name="view_mode">form</field>
<field name="view_id" ref="sf_programming_reason_form_view"/>
<field name="target">new</field>
</record>
</odoo>