35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
|
|
import logging
|
|
from odoo import models, fields, api
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
class MrpWorkorder(models.Model):
|
|
_name = 'mrp.workorder'
|
|
_inherit = ['mrp.workorder']
|
|
|
|
def _compute_state(self):
|
|
super(MrpWorkorder, self)._compute_state()
|
|
for workorder in self:
|
|
work_ids = workorder.production_id.workorder_ids.filtered(lambda w: w.routing_type == '装夹预调' or w.routing_type == '人工线下加工')
|
|
for wo in work_ids:
|
|
if wo.state == 'ready' and not wo.production_id.product_id.is_print_program:
|
|
# 触发打印程序
|
|
pdf_data = workorder.processing_drawing
|
|
if pdf_data:
|
|
try:
|
|
# 执行打印
|
|
_logger.info(f"准备打印工单 {wo.name} 的PDF")
|
|
self.env['jikimo.printing'].print_pdf(pdf_data)
|
|
wo.production_id.product_id.is_print_program = True
|
|
_logger.info(f"工单 {wo.name} 的PDF已成功打印")
|
|
|
|
except Exception as e:
|
|
_logger.error(f"工单 {wo.name} 的PDF打印失败: {str(e)}")
|
|
|
|
class ProductTemplate(models.Model):
|
|
_inherit = 'product.template'
|
|
|
|
is_print_program = fields.Boolean(string='是否打印程序', default=False)
|
|
|