diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 1b746b40..d26e6c33 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -2,7 +2,6 @@ import re import json import logging import base64 -import traceback import urllib.parse from datetime import date from datetime import datetime, timedelta @@ -17,7 +16,8 @@ from odoo.addons.sf_base.commons.common import Common from odoo.exceptions import UserError, ValidationError from odoo.addons.sf_mrs_connect.models.ftp_operate import FtpController -_logger = logging.getLogger(__name__) + + class ResMrpWorkOrder(models.Model): _inherit = 'mrp.workorder' _order = 'sequence asc' @@ -275,22 +275,34 @@ class ResMrpWorkOrder(models.Model): def _compute_surface_technics_purchase_ids(self): for order in self: if order.routing_type == '表面工艺' and order.state not in ['cancel']: - domain = [('purchase_type', '=', 'consignment'), - ('origin', 'like', '%' + self.production_id.name + '%'), + # if order.production_id.production_type == '自动化产线加工': + # domain = [('programming_no', '=', order.production_id.programming_no)] + # else:buzhdiao + # domain = [('origin', '=', order.production_id.origin)] + # production_programming = self.env['mrp.production'].search(domain, order='name asc') + # production_list = [production.name for production in production_programming] + # production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False) + # technology_design = self.env['sf.technology.design'].search( + # [('process_parameters_id', '=', order.surface_technics_parameters_id.id), + # ('production_id', '=', order.production_id.id)]) + # if technology_design.is_auto is False: + # domain = [('origin', '=', order.production_id.name)] + # else: + domain = [('purchase_type', '=', 'consignment'), ('origin', '=', order.production_id.name), ('state', '!=', 'cancel')] purchase = self.env['purchase.order'].search(domain) - order.surface_technics_purchase_count = 0 + purchase_num = 0 if not purchase: order.surface_technics_purchase_count = 0 for po in purchase: - if any( - line.product_id and line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id - for line in po.order_line): - order.surface_technics_purchase_count = 1 + for line in po.order_line: + if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id: + if line.product_qty == 1: + purchase_num += 1 + order.surface_technics_purchase_count = purchase_num else: order.surface_technics_purchase_count = 0 - def action_view_surface_technics_purchase(self): self.ensure_one() # if self.routing_type == '表面工艺': @@ -1285,7 +1297,7 @@ 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).sorted('sequence') if self == subcontract_workorders[-1]: # 给下一个库存移动就绪 self.move_subcontract_workorder_ids[0].move_dest_ids._action_done() @@ -1309,8 +1321,8 @@ class ResMrpWorkOrder(models.Model): is_production_id = False rework_workorder = record.production_id.workorder_ids.filtered(lambda p: p.state == 'rework') done_workorder = record.production_id.workorder_ids.filtered(lambda p1: p1.state in ['done']) - if (len(rework_workorder) + len(done_workorder) == len(record.production_id.workorder_ids.filtered(lambda wo: wo.state != 'cancel'))) or ( - len(done_workorder) == len(record.production_id.workorder_ids.filtered(lambda wo: wo.state != 'cancel'))): + if (len(rework_workorder) + len(done_workorder) == len(record.production_id.workorder_ids)) or ( + len(done_workorder) == len(record.production_id.workorder_ids)): is_production_id = True if record.routing_type in ['解除装夹'] or ( record.is_rework is True and record.routing_type in ['装夹预调']): diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 86a75759..495a5d59 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -605,10 +605,10 @@ class StockPicking(models.Model): sale_info = self.env['sale.order'].sudo().search( [('name', '=', sale_name)]) else: - production_list = self.env['mrp.production'].sudo().search( + sale_order_line = self.env['sale.order.line'].sudo().search( [('product_id', '=', product_id.id)]) - if production_list: - sale_info = production_list[0].sale_order_id + if sale_order_line: + sale_info = sale_order_line[0].order_id if sale_info: item.sale_order_id = sale_info.id item.retrospect_ref = sale_info.order_code