Merge branch 'develop' into feature/commercially_launched
This commit is contained in:
@@ -20,7 +20,9 @@ class AgvScheduling(models.Model):
|
||||
|
||||
name = fields.Char('任务单号', index=True, copy=False)
|
||||
agv_route_id = fields.Many2one('sf.agv.task.route', '任务路线')
|
||||
agv_route_type = fields.Selection(related='agv_route_id.route_type', string='任务类型', required=True)
|
||||
def _get_agv_route_type_selection(self):
|
||||
return self.env['sf.agv.task.route'].fields_get(['route_type'])['route_type']['selection']
|
||||
agv_route_type = fields.Selection(selection=_get_agv_route_type_selection, string='任务类型', required=True)
|
||||
start_site_id = fields.Many2one('sf.agv.site', '起点接驳站', required=True)
|
||||
end_site_id = fields.Many2one('sf.agv.site', '终点接驳站', tracking=True)
|
||||
site_state = fields.Selection([
|
||||
|
||||
@@ -265,6 +265,23 @@ class MrpProduction(models.Model):
|
||||
|
||||
part_name = fields.Char(string='零件名称', related='product_id.part_name', readonly=True)
|
||||
|
||||
# 判断制造的产品类型
|
||||
production_product_type = fields.Selection([
|
||||
('成品', '成品'),
|
||||
('坯料', '坯料'),
|
||||
('其他', '其他')
|
||||
], string='产品类型', compute='_compute_production_product_type')
|
||||
|
||||
@api.depends('product_id')
|
||||
def _compute_production_product_type(self):
|
||||
for record in self:
|
||||
if record.product_id.categ_id.name == '成品':
|
||||
record.production_product_type = '成品'
|
||||
elif record.product_id.categ_id.name == '坯料':
|
||||
record.production_product_type = '坯料'
|
||||
else:
|
||||
record.production_product_type = '其他'
|
||||
|
||||
@api.depends('product_id.manual_quotation')
|
||||
def _compute_manual_quotation(self):
|
||||
for item in self:
|
||||
@@ -776,11 +793,11 @@ class MrpProduction(models.Model):
|
||||
self.ensure_one()
|
||||
iot_code = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id) or self.env[
|
||||
'ir.sequence'].next_by_code('stock.lot.serial')
|
||||
iot_code_name = re.sub('[\u4e00-\u9fa5]', "", iot_code)
|
||||
# iot_code_name = re.sub('[\u4e00-\u9fa5]', "", iot_code)
|
||||
self.lot_producing_id = self.env['stock.lot'].create({
|
||||
'product_id': self.product_id.id,
|
||||
'company_id': self.company_id.id,
|
||||
'name': iot_code_name,
|
||||
'name': iot_code,
|
||||
})
|
||||
if self.move_finished_ids.filtered(lambda m: m.product_id == self.product_id).move_line_ids:
|
||||
self.move_finished_ids.filtered(
|
||||
|
||||
@@ -17,10 +17,10 @@ from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.addons.sf_mrs_connect.models.ftp_operate import FtpController
|
||||
|
||||
|
||||
|
||||
class ResMrpWorkOrder(models.Model):
|
||||
_inherit = 'mrp.workorder'
|
||||
_order = 'sequence asc'
|
||||
_description = '工单'
|
||||
|
||||
product_tmpl_name = fields.Char('坯料产品名称', related='production_bom_id.bom_line_ids.product_id.name')
|
||||
|
||||
@@ -69,6 +69,67 @@ class ResMrpWorkOrder(models.Model):
|
||||
|
||||
delivery_warning = fields.Selection([('normal', '正常'), ('warning', '告警'), ('overdue', '逾期')], string='时效',
|
||||
tracking=True)
|
||||
back_button_display = fields.Boolean(default=False, compute='_compute_back_button_display', store=True)
|
||||
|
||||
@api.depends('state')
|
||||
def _compute_back_button_display(self):
|
||||
for record in self:
|
||||
sorted_workorders = record.production_id.workorder_ids.filtered(lambda w: w.state != 'cancel').sorted(
|
||||
key=lambda w: w.sequence)
|
||||
if not sorted_workorders:
|
||||
continue
|
||||
position = next((idx for idx, workorder in enumerate(sorted_workorders) if workorder.id == record.id), -1)
|
||||
cur_workorder = sorted_workorders[position]
|
||||
if position == len(sorted_workorders) - 1:
|
||||
picking_ids = cur_workorder.production_id.sale_order_id.picking_ids
|
||||
finished_product_area = picking_ids.filtered(
|
||||
lambda picking: picking.location_dest_id.name == '成品存货区' and picking.state == 'done'
|
||||
)
|
||||
if finished_product_area:
|
||||
moves = self.env['stock.move'].search([
|
||||
('name', '=', cur_workorder.production_id.name),
|
||||
('state', '!=', 'cancel')
|
||||
])
|
||||
finish_move = next((move for move in moves if move.location_dest_id.name == '制造后'), None)
|
||||
if not finish_move and not cur_workorder.is_subcontract and not cur_workorder.routing_type == '解除装夹':
|
||||
record.back_button_display = True
|
||||
else:
|
||||
record.back_button_display = any(
|
||||
finish_move.move_dest_ids.ids not in move.ids and record.state == 'done'
|
||||
for picking in finished_product_area
|
||||
for move in picking.move_ids
|
||||
)
|
||||
else:
|
||||
if record.state == 'done':
|
||||
record.back_button_display = True
|
||||
else:
|
||||
record.back_button_display = False
|
||||
# tag_type
|
||||
if cur_workorder.is_subcontract or cur_workorder.routing_type == '解除装夹' or cur_workorder.routing_type == '切割' or any(
|
||||
detection_result.processing_panel == cur_workorder.processing_panel and
|
||||
detection_result.routing_type == cur_workorder.routing_type and
|
||||
cur_workorder.tag_type !='重新加工' and
|
||||
detection_result.test_results != '合格'
|
||||
for detection_result in cur_workorder.production_id.detection_result_ids
|
||||
):
|
||||
record.back_button_display = False
|
||||
else:
|
||||
next_workorder = sorted_workorders[position + 1]
|
||||
next_state = next_workorder.state
|
||||
if (next_state == 'ready' or (
|
||||
next_workorder.state == 'waiting' and next_workorder.is_subcontract)) and cur_workorder.state == 'done':
|
||||
record.back_button_display = True
|
||||
else:
|
||||
record.back_button_display = False
|
||||
if cur_workorder.is_subcontract or cur_workorder.routing_type == '解除装夹' or cur_workorder.routing_type == '切割' or any(
|
||||
detection_result.processing_panel == cur_workorder.processing_panel and
|
||||
detection_result.routing_type == cur_workorder.routing_type and
|
||||
cur_workorder.tag_type !='重新加工' and
|
||||
detection_result.test_results != '合格'
|
||||
for detection_result in cur_workorder.production_id.detection_result_ids
|
||||
):
|
||||
record.back_button_display = False
|
||||
|
||||
date_planned_start = fields.Datetime(tracking=True)
|
||||
|
||||
@api.depends('processing_panel')
|
||||
@@ -86,6 +147,82 @@ class ResMrpWorkOrder(models.Model):
|
||||
|
||||
manual_quotation = fields.Boolean('人工编程', default=False, compute=_compute_manual_quotation, store=True)
|
||||
|
||||
def button_back(self):
|
||||
if self.production_id.state == 'rework':
|
||||
raise UserError('制造订单为返工时不能进行工单回退')
|
||||
sorted_workorders = self.production_id.workorder_ids.filtered(lambda w: w.state != 'cancel').sorted(
|
||||
key=lambda w: w.sequence)
|
||||
position = next((idx for idx, workorder in enumerate(sorted_workorders) if workorder.id == self.id), -1)
|
||||
cur_workorder = sorted_workorders[position]
|
||||
if position == len(sorted_workorders) - 1:
|
||||
# 末工序
|
||||
picking_ids = cur_workorder.production_id.sale_order_id.picking_ids
|
||||
finished_product_area = picking_ids.filtered(
|
||||
lambda picking: picking.location_dest_id.name == '成品存货区' and picking.state == 'done'
|
||||
)
|
||||
moves = self.env['stock.move'].search([
|
||||
('name', '=', cur_workorder.production_id.name),
|
||||
('state', '!=', 'cancel')
|
||||
])
|
||||
finish_move = next((move for move in moves if move.location_dest_id.name == '制造后'), None) or []
|
||||
if any(
|
||||
finish_move.move_dest_ids.ids in move.ids
|
||||
for picking in finished_product_area
|
||||
for move in picking.move_ids
|
||||
):
|
||||
raise UserError('已入库,无法回退')
|
||||
else:
|
||||
moves = self.env['stock.move'].search([
|
||||
('name', '=', cur_workorder.production_id.name),
|
||||
('state', '!=', 'cancel')
|
||||
])
|
||||
move_lines = self.env['stock.move.line'].search([
|
||||
('reference', '=', cur_workorder.production_id.name),
|
||||
('state', '!=', 'cancel')
|
||||
])
|
||||
moves.state = 'assigned'
|
||||
external_assistance = move_lines.filtered(
|
||||
lambda picking: picking.location_id.name != '外协线边仓'
|
||||
)
|
||||
external_assistance.state = 'assigned'
|
||||
# move_lines.state = 'assigned'
|
||||
self.time_ids.date_end = None
|
||||
cur_workorder.state = 'progress'
|
||||
cur_workorder.production_id.state = 'progress'
|
||||
quality_check = self.env['quality.check'].search(
|
||||
[('workorder_id', '=', self.id)])
|
||||
for check_order in quality_check:
|
||||
if check_order.point_id.is_inspect:
|
||||
check_order.quality_state = 'waiting'
|
||||
else:
|
||||
check_order.quality_state = 'none'
|
||||
# move_dest_ids
|
||||
finished_quants = moves.mapped('move_line_ids.lot_id.quant_ids')
|
||||
finished_quants.quantity = 0
|
||||
finish_move = next((move for move in moves if move.location_dest_id.name == '制造后'), None)
|
||||
finish_move.move_dest_ids.reserved_availability = 0
|
||||
finish_move.move_dest_ids.move_line_ids.state = 'draft'
|
||||
finish_move.move_dest_ids.move_line_ids.unlink()
|
||||
# finish_move.move_dest_ids.move_line_ids.reserved_uom_qty = 0
|
||||
else:
|
||||
next_workorder = sorted_workorders[position + 1]
|
||||
next_state = next_workorder.state
|
||||
if next_state not in ['pending', 'waiting', 'ready']:
|
||||
raise UserError('下工序已经开始,无法回退')
|
||||
if next_workorder.is_subcontract:
|
||||
next_workorder.picking_ids.write({'state': 'waiting'})
|
||||
next_workorder.state = 'pending'
|
||||
self.time_ids.date_end = None
|
||||
cur_workorder.state = 'progress'
|
||||
cur_workorder.production_id.state = 'progress'
|
||||
quality_check = self.env['quality.check'].search(
|
||||
[('workorder_id', '=', self.id)])
|
||||
for check_order in quality_check:
|
||||
if check_order.point_id.is_inspect:
|
||||
check_order.quality_state = 'waiting'
|
||||
else:
|
||||
check_order.quality_state = 'none'
|
||||
|
||||
def _compute_working_users(self):
|
||||
super()._compute_working_users()
|
||||
for item in self:
|
||||
@@ -156,7 +293,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数")
|
||||
|
||||
picking_ids = fields.Many2many('stock.picking', string='外协出入库单',
|
||||
compute='_compute_surface_technics_picking_ids')
|
||||
compute='_compute_surface_technics_picking_ids', store=True)
|
||||
|
||||
purchase_id = fields.Many2many('purchase.order', string='外协采购单')
|
||||
surface_technics_picking_count = fields.Integer("外协出入库", compute='_compute_surface_technics_picking_ids')
|
||||
@@ -456,6 +593,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
("technology", "工艺"), ("customer redrawing", "客户改图")], string="原因", tracking=True)
|
||||
detailed_reason = fields.Text('详细原因')
|
||||
is_rework = fields.Boolean(string='是否返工', default=False)
|
||||
|
||||
# rework_flag = fields.Boolean(string='返工标志', compute='_compute_rework_flag')
|
||||
#
|
||||
# @api.depends('state', 'production_line_state')
|
||||
@@ -1087,9 +1225,12 @@ class ResMrpWorkOrder(models.Model):
|
||||
if (workorder.production_id.production_type == '人工线下加工'
|
||||
and workorder.production_id.schedule_state == '已排'
|
||||
and len(workorder.production_id.picking_ids.filtered(
|
||||
lambda w: w.state not in ['done', 'cancel'])) == 0
|
||||
and workorder.production_id.programming_state == '已编程'):
|
||||
lambda w: w.state not in ['done', 'cancel'])) == 0):
|
||||
# and workorder.production_id.programming_state == '已编程'
|
||||
if workorder.is_subcontract is True:
|
||||
if workorder.production_id.state == 'rework':
|
||||
workorder.state = 'waiting'
|
||||
continue
|
||||
purchase_orders_id = self._get_surface_technics_purchase_ids()
|
||||
if purchase_orders_id.state == 'purchase':
|
||||
workorder.state = 'ready'
|
||||
@@ -1104,6 +1245,9 @@ class ResMrpWorkOrder(models.Model):
|
||||
else:
|
||||
workorder.state = 'waiting'
|
||||
continue
|
||||
elif workorder.routing_type == '人工线下加工':
|
||||
if workorder.production_id.programming_state == '已编程':
|
||||
workorder.state = 'ready'
|
||||
else:
|
||||
workorder.state = 'ready'
|
||||
continue
|
||||
@@ -1145,6 +1289,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
mo.get_move_line(workorder.production_id, workorder))
|
||||
else:
|
||||
workorder.state = 'waiting'
|
||||
|
||||
# 重写工单开始按钮方法
|
||||
def button_start(self):
|
||||
# 判断工单状态是否为等待组件
|
||||
@@ -1311,7 +1456,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
'detailed_reason': record.detailed_reason,
|
||||
'processing_panel': record.processing_panel,
|
||||
'routing_type': record.routing_type,
|
||||
'handle_result': '待处理' if record.test_results in ['返工', '报废'] or record.is_rework is True else '',
|
||||
'handle_result': '待处理' if record.test_results in ['返工',
|
||||
'报废'] or record.is_rework is True else '',
|
||||
'test_results': record.test_results,
|
||||
'test_report': record.detection_report})],
|
||||
'is_scrap': True if record.test_results == '报废' else False
|
||||
@@ -1328,7 +1474,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
raise UserError('请先完成该工单的工艺外协再进行操作')
|
||||
# 表面工艺外协,最后一张工单
|
||||
workorders = self.production_id.workorder_ids
|
||||
subcontract_workorders = workorders.filtered(lambda wo: wo.is_subcontract == True and wo.state != 'cancel').sorted('sequence')
|
||||
subcontract_workorders = workorders.filtered(
|
||||
lambda wo: wo.is_subcontract == True and wo.state != 'cancel').sorted('sequence')
|
||||
if self == subcontract_workorders[-1]:
|
||||
# 给下一个库存移动就绪
|
||||
self.move_subcontract_workorder_ids[0].move_dest_ids._action_done()
|
||||
@@ -1385,7 +1532,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
# ('state', '!=', 'done')])
|
||||
# if raw_move:
|
||||
# raw_move.write({'state': 'done'})
|
||||
record.production_id.button_mark_done1()
|
||||
if record.production_id.state != 'rework':
|
||||
record.production_id.button_mark_done1()
|
||||
# record.production_id.state = 'done'
|
||||
|
||||
# ============工单完成,修改对应[质检单]的值=====================
|
||||
@@ -1551,6 +1699,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
# 根据工单对应的【作业_个性化记录】配置页签
|
||||
if any(item.code == 'PTD' for item in mw.routing_workcenter_id.individuation_page_ids):
|
||||
mw.individuation_page_PTD = True
|
||||
|
||||
# =============================================================================================
|
||||
|
||||
is_inspect = fields.Boolean('需送检', compute='_compute_is_inspect', store=True, default=False)
|
||||
@@ -1860,7 +2009,10 @@ class WorkPieceDelivery(models.Model):
|
||||
feeder_station_destination_id = fields.Many2one('sf.agv.site', '目的接驳站')
|
||||
task_delivery_time = fields.Datetime('任务下发时间')
|
||||
task_completion_time = fields.Datetime('任务完成时间')
|
||||
type = fields.Selection(related='route_id.route_type', string='类型')
|
||||
|
||||
def _get_agv_route_type_selection(self):
|
||||
return self.env['sf.agv.task.route'].fields_get(['route_type'])['route_type']['selection']
|
||||
type = fields.Selection(selection=_get_agv_route_type_selection, string='类型')
|
||||
delivery_duration = fields.Float('配送时长', compute='_compute_delivery_duration')
|
||||
status = fields.Selection(
|
||||
[('待下发', '待下发'), ('已下发', '待配送'), ('已配送', '已配送'), ('已取消', '已取消')], string='状态',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import re
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
@@ -109,15 +109,37 @@ class PurchaseOrder(models.Model):
|
||||
class PurchaseOrderLine(models.Model):
|
||||
_inherit = 'purchase.order.line'
|
||||
|
||||
part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True)
|
||||
part_number = fields.Char('零件图号', store=True, compute='_compute_related_product')
|
||||
part_name = fields.Char('零件名称', store=True,
|
||||
compute='_compute_related_product')
|
||||
related_product = fields.Many2one('product.product', string='关联产品',
|
||||
help='经此产品工艺加工成的成品')
|
||||
|
||||
# @api.depends('order_id.origin')
|
||||
# def _compute_related_product(self):
|
||||
# for record in self:
|
||||
# if record.product_id.detailed_type:
|
||||
# production_id = self.env['mrp.production'].search([('name', '=', record.order_id.origin)])
|
||||
# record.related_product = production_id.product_id if production_id else False
|
||||
# else:
|
||||
# record.related_product = False
|
||||
@api.depends('product_id')
|
||||
def _compute_related_product(self):
|
||||
for record in self:
|
||||
if record.product_id.categ_id.name == '坯料':
|
||||
product_name = ''
|
||||
match = re.search(r'(S\d{5}-\d)', record.product_id.name)
|
||||
# 如果匹配成功,提取结果
|
||||
if match:
|
||||
product_name = match.group(0)
|
||||
sale_order_name = ''
|
||||
match_sale = re.search(r'S(\d+)', record.product_id.name)
|
||||
if match_sale:
|
||||
sale_order_name = match_sale.group(0)
|
||||
sale_order = self.env['sale.order'].sudo().search(
|
||||
[('name', '=', sale_order_name)])
|
||||
if sale_order:
|
||||
filtered_order_line = sale_order.order_line.filtered(
|
||||
lambda order_line: re.search(f'{product_name}$', order_line.product_id.name)
|
||||
)
|
||||
record.part_number = filtered_order_line.product_id.part_number if filtered_order_line else None
|
||||
record.part_name = filtered_order_line.product_id.part_name if filtered_order_line else None
|
||||
else:
|
||||
record.part_number = record.product_id.part_number
|
||||
record.part_name = record.product_id.part_name
|
||||
# if record.product_id.detailed_type:
|
||||
# production_id = self.env['mrp.production'].search([('name', '=', record.order_id.origin)])
|
||||
# record.related_product = production_id.product_id if production_id else False
|
||||
# else:
|
||||
# record.related_product = False
|
||||
|
||||
@@ -3,5 +3,6 @@ from odoo import fields, models, api
|
||||
|
||||
class QualityCheck(models.Model):
|
||||
_inherit = "quality.check"
|
||||
_description = "质量检查"
|
||||
|
||||
is_inspect = fields.Boolean('需送检')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
import json
|
||||
from odoo import models, fields, api
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -24,6 +24,8 @@ class SaleOrder(models.Model):
|
||||
self.state = 'supply method'
|
||||
|
||||
def action_confirm(self):
|
||||
if self._get_forbidden_state_confirm() & set(self.mapped('state')):
|
||||
raise UserError(_('订单状态已发生变化,请刷新当前页面'))
|
||||
# 判断是否所有产品都选择了供货方式
|
||||
filter_line = self.order_line.filtered(lambda line: not line.supply_method)
|
||||
if filter_line:
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import base64
|
||||
import random
|
||||
import re
|
||||
|
||||
import qrcode
|
||||
from itertools import groupby
|
||||
from collections import defaultdict, namedtuple
|
||||
@@ -449,25 +452,15 @@ class ProductionLot(models.Model):
|
||||
"""Return the next serial number to be attributed to the product."""
|
||||
if product.tracking == "serial":
|
||||
last_serial = self.env['stock.lot'].search(
|
||||
[('company_id', '=', company.id), ('product_id', '=', product.id)],
|
||||
[('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'ilike', product.name)],
|
||||
limit=1, order='name desc')
|
||||
if last_serial:
|
||||
if product.categ_id.name == '刀具':
|
||||
return self.env['stock.lot'].get_tool_generate_lot_names1(company, product)
|
||||
else:
|
||||
# 对last_serial的name进行检测,如果不是以产品名称+数字的形式的就重新搜索
|
||||
if product.name.split('[')[0] not in last_serial.name:
|
||||
last_serial = self.env['stock.lot'].search(
|
||||
[('company_id', '=', company.id), ('product_id', '=', product.id),
|
||||
('name', 'ilike', product.name.split('[')[0])],
|
||||
limit=1, order='name desc')
|
||||
if not last_serial:
|
||||
return "%s-%03d" % (product.name, 1)
|
||||
return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name, 2)[1]
|
||||
now = datetime.now().strftime("%Y%m%d")
|
||||
if product.cutting_tool_model_id:
|
||||
split_codes = product.cutting_tool_model_id.code.split('-')
|
||||
return "%s-T-%s-%s-%03d" % (split_codes[0], now, product.specification_id.name, 1)
|
||||
move_line_id = self.env['stock.move.line'].sudo().search(
|
||||
[('company_id', '=', company.id), ('product_id', '=', product.id), ('lot_name', 'ilike', product.name)],
|
||||
limit=1, order='lot_name desc')
|
||||
if last_serial or move_line_id:
|
||||
return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name if (
|
||||
not move_line_id or
|
||||
(last_serial and last_serial.name > move_line_id.lot_name)) else move_line_id.lot_name, 2)[1]
|
||||
return "%s-%03d" % (product.name, 1)
|
||||
|
||||
qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')
|
||||
@@ -632,12 +625,12 @@ class StockPicking(models.Model):
|
||||
workorder = move_in.subcontract_workorder_id
|
||||
workorders = workorder.production_id.workorder_ids
|
||||
subcontract_workorders = workorders.filtered(lambda wo: wo.is_subcontract == True and wo.state!='cancel').sorted('sequence')
|
||||
if workorder == subcontract_workorders[-1]:
|
||||
self.env['stock.quant']._update_reserved_quantity(
|
||||
move_in.product_id, move_in.location_dest_id, move_in.product_uom_qty,
|
||||
lot_id=move_in.move_line_ids.lot_id,
|
||||
package_id=False, owner_id=False, strict=False
|
||||
)
|
||||
# if workorder == subcontract_workorders[-1]:
|
||||
# self.env['stock.quant']._update_reserved_quantity(
|
||||
# move_in.product_id, move_in.location_dest_id, move_in.product_uom_qty,
|
||||
# lot_id=move_in.move_line_ids.lot_id,
|
||||
# package_id=False, owner_id=False, strict=False
|
||||
# )
|
||||
workorder.button_finish()
|
||||
picking_type_out = self.env.ref('sf_manufacturing.outcontract_picking_out').id
|
||||
if res and self.picking_type_id.id == picking_type_out:
|
||||
@@ -653,6 +646,16 @@ class StockPicking(models.Model):
|
||||
stock_picking = stock_picking_list.filtered(lambda p: p.state not in ("done", "cancel"))
|
||||
if sale_id and not stock_picking:
|
||||
sale_id.write({'state': 'delivered'})
|
||||
if self.location_dest_id.name == '成品存货区' and self.state == 'done':
|
||||
for move in self.move_ids:
|
||||
for production in self.sale_order_id.mrp_production_ids:
|
||||
moves = self.env['stock.move'].search([
|
||||
('name', '=', production.name),
|
||||
('state', '!=', 'cancel')
|
||||
])
|
||||
finish_move = next((move for move in moves if move.location_dest_id.name == '制造后'), None)
|
||||
if finish_move.id in move.move_orig_ids.ids and finish_move.state == 'done':
|
||||
production.workorder_ids.write({'back_button_display': False})
|
||||
return res
|
||||
|
||||
# 创建 外协出库入单
|
||||
@@ -691,8 +694,8 @@ class StockPicking(models.Model):
|
||||
picking_in = self.create(
|
||||
moves_in._get_new_picking_values_Res(item, workorder, 'WH/OCIN/'))
|
||||
# pick_ids.append(picking_in.id)
|
||||
moves_in.write(
|
||||
{'picking_id': picking_in.id, 'state': 'waiting'})
|
||||
moves_in.write({'picking_id': picking_in.id})
|
||||
moves_in._action_confirm()
|
||||
moves_in._assign_picking_post_process(new=new_picking)
|
||||
# self.env.context.get('default_production_id')
|
||||
moves_out = self.env['stock.move'].sudo().with_context(context).create(
|
||||
@@ -702,8 +705,8 @@ class StockPicking(models.Model):
|
||||
picking_out = self.create(
|
||||
moves_out._get_new_picking_values_Res(item, workorder, 'WH/OCOUT/'))
|
||||
# pick_ids.append(picking_out.id)
|
||||
moves_out.write(
|
||||
{'picking_id': picking_out.id, 'state': 'waiting'})
|
||||
moves_out.write({'picking_id': picking_out.id})
|
||||
moves_out._action_confirm()
|
||||
moves_out._assign_picking_post_process(new=new_picking)
|
||||
|
||||
@api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id')
|
||||
@@ -721,6 +724,20 @@ class StockPicking(models.Model):
|
||||
'draft', 'sent']:
|
||||
picking.state = 'waiting'
|
||||
|
||||
@api.constrains('state', 'move_ids_without_package')
|
||||
def _check_move_ids_without_package(self):
|
||||
"""
|
||||
凡库存调拨单的【作业类型】=“收料入库、客供料入库”,且其产品行的【产品_库存_追溯】="按唯一序列号/按批次”的,当调拨单的【状态】=就绪时
|
||||
自动生成预分配序列号
|
||||
"""
|
||||
for sp in self:
|
||||
if (sp.picking_type_id.use_existing_lots is False and sp.picking_type_id.use_create_lots is True
|
||||
and sp.state == 'assigned'):
|
||||
if sp.move_ids_without_package:
|
||||
for move_id in sp.move_ids_without_package:
|
||||
if move_id.product_id.tracking in ['serial', 'lot'] and not move_id.move_line_nosuggest_ids:
|
||||
move_id.action_show_details()
|
||||
|
||||
|
||||
class ReStockMove(models.Model):
|
||||
_inherit = 'stock.move'
|
||||
@@ -738,25 +755,27 @@ class ReStockMove(models.Model):
|
||||
move.part_number = move.product_id.part_number
|
||||
move.part_name = move.product_id.part_name
|
||||
elif move.product_id.categ_id.type == '坯料':
|
||||
if move.origin:
|
||||
origin = move.origin.split(',')[0] if ',' in move.origin else move.origin
|
||||
mrp_productio_info = self.env['mrp.production'].sudo().search(
|
||||
[('name', '=', origin)])
|
||||
if mrp_productio_info:
|
||||
move.part_number = mrp_productio_info.part_number
|
||||
move.part_name = mrp_productio_info.part_name
|
||||
else:
|
||||
purchase_order_info = self.env['purchase.order'].sudo().search(
|
||||
[('name', '=', origin)])
|
||||
if purchase_order_info:
|
||||
mrp_production_ids = purchase_order_info._get_mrp_productions().ids
|
||||
if mrp_production_ids:
|
||||
mrp_productio_info = self.env['mrp.production'].sudo().search(
|
||||
[('id', '=', mrp_production_ids[0])])
|
||||
if mrp_productio_info:
|
||||
move.part_number = mrp_productio_info.part_number
|
||||
move.part_name = mrp_productio_info.part_name
|
||||
product_name = ''
|
||||
match = re.search(r'(S\d{5}-\d)', move.product_id.name)
|
||||
# 如果匹配成功,提取结果
|
||||
if match:
|
||||
product_name = match.group(0)
|
||||
if move.picking_id.sale_order_id:
|
||||
sale_order = move.picking_id.sale_order_id
|
||||
else:
|
||||
sale_order_name = ''
|
||||
match = re.search(r'(S\d+)', move.product_id.name)
|
||||
if match:
|
||||
sale_order_name = match.group(0)
|
||||
sale_order = self.env['sale.order'].sudo().search(
|
||||
[('name', '=', sale_order_name)])
|
||||
filtered_order_line = sale_order.order_line.filtered(
|
||||
lambda production: re.search(f'{product_name}$', production.product_id.name)
|
||||
)
|
||||
|
||||
if filtered_order_line:
|
||||
move.part_number = filtered_order_line.part_number
|
||||
move.part_name = filtered_order_line.part_name
|
||||
def _get_stock_move_values_Res(self, item, picking_type_id, group_id, move_dest_ids=False):
|
||||
route_id = self.env.ref('sf_manufacturing.route_surface_technology_outsourcing').id
|
||||
stock_rule = self.env['stock.rule'].sudo().search(
|
||||
@@ -856,11 +875,12 @@ class ReStockMove(models.Model):
|
||||
self.next_serial = self._get_tool_next_serial(self.company_id, self.product_id, self.origin)
|
||||
else:
|
||||
self.next_serial = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id)
|
||||
if (self.picking_type_id.use_existing_lots is False
|
||||
and self.picking_type_id.use_create_lots is True and not self.move_line_nosuggest_ids):
|
||||
self.action_assign_serial_show_details()
|
||||
if (self.picking_type_id.use_existing_lots is False
|
||||
and self.picking_type_id.use_create_lots is True and not self.move_line_nosuggest_ids):
|
||||
self.action_assign_serial_show_details()
|
||||
elif self.product_id.tracking == "lot":
|
||||
self._put_tool_lot(self.company_id, self.product_id, self.origin)
|
||||
if self.product_id.categ_id.name == '刀具':
|
||||
self._put_tool_lot(self.company_id, self.product_id, self.origin)
|
||||
|
||||
return {
|
||||
'name': _('Detailed Operations'),
|
||||
@@ -885,37 +905,22 @@ class ReStockMove(models.Model):
|
||||
),
|
||||
}
|
||||
|
||||
def put_move_line(self):
|
||||
"""
|
||||
确认订单时,自动分配序列号
|
||||
"""
|
||||
if self.product_id.tracking == "serial":
|
||||
if self.product_id.categ_id.name == '刀具':
|
||||
self.next_serial = self._get_tool_next_serial(self.company_id, self.product_id, self.origin)
|
||||
else:
|
||||
self.next_serial = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id)
|
||||
self._generate_serial_numbers()
|
||||
for item in self.move_line_nosuggest_ids:
|
||||
if item.lot_name:
|
||||
lot_name = item.lot_name
|
||||
if item.product_id.categ_id.name == '坯料':
|
||||
lot_name = lot_name.split('[', 1)[0]
|
||||
item.lot_qr_code = self.compute_lot_qr_code(lot_name)
|
||||
|
||||
def _put_tool_lot(self, company, product, origin):
|
||||
if product.tracking == "lot" and self.product_id.categ_id.name == '刀具':
|
||||
if not self.move_line_nosuggest_ids:
|
||||
lot_code = '%s-%s-%s' % ('%s-T-DJWL-%s' % (
|
||||
product.cutting_tool_model_id.code.split('-')[0], product.cutting_tool_material_id.code),
|
||||
datetime.now().strftime("%Y%m%d"), origin)
|
||||
move_line_ids = self.env['stock.move.line'].sudo().search([('lot_name', 'like', lot_code)], limit=1,
|
||||
order='id desc')
|
||||
move_line_ids = self.env['stock.move.line'].sudo().search(
|
||||
[('company_id', '=', company.id), ('lot_name', 'like', lot_code)], limit=1, order='id desc')
|
||||
if not move_line_ids:
|
||||
lot_code = '%s-001' % lot_code
|
||||
else:
|
||||
lot_code = '%s-%03d' % (lot_code, int(move_line_ids.lot_name[-3:]) + 1)
|
||||
lot_names = self.env['stock.lot'].generate_lot_names(lot_code, 1)
|
||||
move_lines_commands = self._generate_serial_move_line_commands_tool_lot(lot_names)
|
||||
for move_lines_command in move_lines_commands:
|
||||
move_lines_command[2]['qty_done'] = self.product_uom_qty
|
||||
self.write({'move_line_nosuggest_ids': move_lines_commands})
|
||||
for item in self.move_line_nosuggest_ids:
|
||||
if item.lot_name:
|
||||
@@ -943,10 +948,16 @@ class ReStockMove(models.Model):
|
||||
last_serial = self.env['stock.lot'].search(
|
||||
[('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'ilike', origin)],
|
||||
limit=1, order='id DESC')
|
||||
move_line_id = self.env['stock.move.line'].sudo().search(
|
||||
[('company_id', '=', company.id), ('product_id', '=', product.id), ('lot_name', 'ilike', origin)],
|
||||
limit=1, order='lot_name desc')
|
||||
split_codes = product.cutting_tool_model_id.code.split('-')
|
||||
if last_serial:
|
||||
if last_serial or move_line_id:
|
||||
return "%s-T-%s-%s-%03d" % (
|
||||
split_codes[0], origin, product.specification_id.name, int(last_serial.name[-3:]) + 1)
|
||||
split_codes[0], origin, product.specification_id.name,
|
||||
int(last_serial.name[-3:] if (not move_line_id or
|
||||
(last_serial and last_serial.name > move_line_id.lot_name))
|
||||
else move_line_id.lot_name[-3:]) + 1)
|
||||
else:
|
||||
return "%s-T-%s-%s-%03d" % (split_codes[0], origin, product.specification_id.name, 1)
|
||||
|
||||
@@ -1042,6 +1053,15 @@ class ReStockMove(models.Model):
|
||||
subcontract_workorder_id = fields.Many2one('mrp.workorder', '外协工单组件', check_company=True,
|
||||
index='btree_not_null')
|
||||
|
||||
def button_update_the_sequence_number(self):
|
||||
"""
|
||||
更新序列号 功能按钮
|
||||
"""
|
||||
self.move_line_nosuggest_ids.unlink()
|
||||
if self.state != 'assigned':
|
||||
self.state = 'assigned'
|
||||
return self.action_show_details()
|
||||
|
||||
|
||||
class ReStockQuant(models.Model):
|
||||
_inherit = 'stock.quant'
|
||||
|
||||
Reference in New Issue
Block a user