工单优化更新

This commit is contained in:
gqh
2022-11-15 16:16:21 +08:00
parent e23548a0d3
commit ba92f616a0
9 changed files with 89 additions and 140 deletions

View File

@@ -7,6 +7,7 @@ import math
from io import BytesIO
from odoo import api, fields, models, SUPERUSER_ID
from pystrich.code128 import Code128Encoder
from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__)
@@ -122,14 +123,6 @@ class MrpWorkOrder(models.Model):
Y10_axis = fields.Float(string='Uz10', default=0)
Z10_axis = fields.Float(string='Uz10', default=0)
# 扫码绑定托盘方法
def gettray(self):
return ""
# 解除托盘绑定
def unbindtray(self):
return ""
# 计算配料中心点和与x轴倾斜度方法
def getcenter(self):
x1 = self.X1_axis
@@ -173,30 +166,50 @@ class MrpWorkOrder(models.Model):
cnc_ids = fields.One2many("cnc.processing", 'workorder_id', string="CNC加工")
tray_code = fields.Char( string="托盘",compute='updateTrayState')
tray_code = fields.Char(string="托盘")
# 扫码绑定托盘方法
def gettray(self):
if self.tray_code != False:
values = self.env['sf.tray'].search([("code", "=", self.tray_code)])
if values:
if values.state == "占用":
raise ValidationError('该托盘已占用')
if values.state == "报损":
raise ValidationError('该托盘已损坏')
else:
values.update({
'workorder_id': self,
'production_id': self.production_id,
'state': '占用',
})
else:
raise ValidationError('该托盘编码已失效')
else:return ""
@api.depends('tray_code')
def updateTrayState(self):
tray = self.env['sf.tray'].search([("code",'=',self.tray_code)])
# 解除托盘绑定
def unbindtray(self):
tray = self.env['sf.tray'].search([("production_id", "=", self.production_id.id)])
if tray:
tray.workorder_id = self
else:
return ""
tray.unclamp()
return ""
def recreateManufacturing(self):
"""
重新生成制造订单
"""
values = self.env['mrp.production'].create_production1_values(self.production_id)
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(self.production_id.company_id).create(
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(
self.production_id.company_id).create(
values)
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
productions._create_workorder()
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
(
p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm()
p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm()
for production in productions:
origin_production = production.move_dest_ids and production.move_dest_ids[
@@ -231,8 +244,6 @@ class MrpWorkOrder(models.Model):
productions.create_workorder1(self.processing_panel)
return ""
def fetchCNC(self):
return ""
@@ -247,8 +258,6 @@ class MrpProduction(models.Model):
_description = "制造订单"
tray_ids = fields.One2many('sf.tray', 'production_id', string="托盘")
def create_production1_values(self, production):
production_values_str = {'origin': production.origin,
'product_id': production.product_id.id,