diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 9eee5fe1..02113cd5 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -842,7 +842,7 @@ class MrpProduction(models.Model): # workorder.picking_ids.move_ids = False workorder.picking_ids = False purchase_order = self.env['purchase.order'].search( - [('state', '=', 'draft'), ('origin', '=', ','.join(production_process)), + [('state', '=', 'draft'), ('origin', '=', item.name), ('purchase_type', '=', 'consignment')]) for line in purchase_order.order_line: server_template = self.env['product.template'].search( @@ -850,7 +850,7 @@ class MrpProduction(models.Model): ('detailed_type', '=', 'service')]) purchase_order_line = self.env['purchase.order.line'].search( [('product_id', '=', server_template.product_variant_id.id), ('id', '=', line.id), - ('product_qty', '=', len(production_process))], limit=1, order='id desc') + ('product_qty', '=', 1)], limit=1, order='id desc') if purchase_order_line: line.unlink() diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 1600f9f7..f37aae72 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -241,9 +241,9 @@ class ResMrpWorkOrder(models.Model): ('production_id', '=', workorder.production_id.id)]) if previous_workorder: if previous_workorder.supplier_id != workorder.supplier_id: - process_product = self.env['product.template']._get_process_parameters_product( - previous_workorder.surface_technics_parameters_id) - domain += [('partner_id', '=', process_product.partner_id.id)] + # process_product = self.env['product.template']._get_process_parameters_product( + # previous_workorder.surface_technics_parameters_id) + domain += [('surface_technics_parameters_id', '=', workorder.surface_technics_parameters_id.id)] else: domain += [('surface_technics_parameters_id', '=', workorder.surface_technics_parameters_id.id)] picking_ids = self.env['stock.picking'].search(domain, order='id asc') @@ -270,55 +270,57 @@ class ResMrpWorkOrder(models.Model): def _compute_surface_technics_purchase_ids(self): for order in self: if order.routing_type == '表面工艺': - if order.production_id.production_type == '自动化产线加工': - domain = [('programming_no', '=', order.production_id.programming_no)] - else: - 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) + # if order.production_id.production_type == '自动化产线加工': + # domain = [('programming_no', '=', order.production_id.programming_no)] + # else: + # 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', '=', ','.join(production_list))] + domain = [('purchase_type', '=', 'consignment'), ('origin', '=', order.production_id.name)] purchase = self.env['purchase.order'].search(domain) purchase_num = 0 if not purchase: order.surface_technics_purchase_count = 0 - for line in purchase.order_line: - if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id: - if line.product_qty == len(production_no_remanufacture): - purchase_num += 1 - order.surface_technics_purchase_count = purchase_num + for po in purchase: + 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 == '表面工艺': - if self.production_id.production_type == '自动化产线加工': - domain = [('programming_no', '=', self.production_id.programming_no)] - else: - domain = [('origin', '=', self.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) + # if self.routing_type == '表面工艺': + # if self.production_id.production_type == '自动化产线加工': + # domain = [('programming_no', '=', self.production_id.programming_no)] + # else: + # domain = [('origin', '=', self.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', '=', self.surface_technics_parameters_id.id), # ('production_id', '=', self.production_id.id)]) # if technology_design.is_auto is False: # domain = [('origin', '=', self.production_id.name)] # else: - domain = [('origin', '=', ','.join(production_list)), ('purchase_type', '=', 'consignment')] + domain = [('origin', '=', self.production_id.name), ('purchase_type', '=', 'consignment')] purchase_orders = self.env['purchase.order'].search(domain) purchase_orders_id = None - for line in purchase_orders.order_line: - if line.product_id.server_product_process_parameters_id == self.surface_technics_parameters_id: - if line.product_qty == len(production_no_remanufacture): - purchase_orders_id = line.order_id.id + for po in purchase_orders: + for line in po.order_line: + if line.product_id.server_product_process_parameters_id == self.surface_technics_parameters_id: + if line.product_qty == 1: + purchase_orders_id = line.order_id.id result = { "type": "ir.actions.act_window", "res_model": "purchase.order", diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index ebbf5bd2..f5f685aa 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -9,8 +9,8 @@ from odoo.exceptions import ValidationError, UserError from odoo.modules import get_resource_path -# from OCC.Extend.DataExchange import read_step_file -# from OCC.Extend.DataExchange import write_stl_file +from OCC.Extend.DataExchange import read_step_file +from OCC.Extend.DataExchange import write_stl_file class ResProductMo(models.Model): diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index fb42da12..a5205640 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -283,7 +283,8 @@ class StockRule(models.Model): sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)]) # 如果订单为空,则获取来源制造订单的销售单 if not sale_order: - mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)], limit=1) + mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)], + limit=1) if mrp_production: sale_order = self.env['sale.order'].sudo().search([('name', '=', mrp_production.origin)]) else: @@ -670,10 +671,14 @@ class StockPicking(models.Model): # 创建 外协出库入单 def create_outcontract_picking(self, sorted_workorders_arr, item): + domain = [('origin', '=', item.name), ('name', 'ilike', 'OCOUT')] if len(sorted_workorders_arr) > 1: sorted_workorders_arr = sorted_workorders_arr[0] - stock_picking = self.env['stock.picking'].search([('origin', '=', item.name), ('name', 'ilike', 'OCOUT')]) - if not stock_picking or sorted_workorders_arr: + else: + domain += [ + ('surface_technics_parameters_id', '=', sorted_workorders_arr[0].surface_technics_parameters_id.id)] + stock_picking = self.env['stock.picking'].search(domain) + if not stock_picking: for sorted_workorders in sorted_workorders_arr: # pick_ids = [] if not sorted_workorders.picking_ids: diff --git a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py index 7c4000dc..14cebe41 100644 --- a/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py +++ b/sf_manufacturing/wizard/production_technology_re_adjust_wizard.py @@ -99,7 +99,8 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel): if workorder.sequence == 1: workorder.blocked_by_workorder_ids = None else: - workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0] + if workorder.blocked_by_workorder_ids: + workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0] productions._reset_work_order_sequence() if self.production_id.product_id.categ_id.type == '成品': productions._reset_subcontract_pick_purchase() @@ -109,5 +110,6 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel): workorders = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted( key=lambda a: a.sequence) if workorders[0].state in ['pending']: - if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程': + if workorders[ + 0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程': workorders[0].state = 'waiting' diff --git a/sf_manufacturing/wizard/production_technology_wizard.py b/sf_manufacturing/wizard/production_technology_wizard.py index 630a272e..01103746 100644 --- a/sf_manufacturing/wizard/production_technology_wizard.py +++ b/sf_manufacturing/wizard/production_technology_wizard.py @@ -65,4 +65,4 @@ class ProductionTechnologyWizard(models.TransientModel): key=lambda a: a.sequence) if workorder[0].state in ['pending']: if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程': - workorders[0].state = 'waiting' + workorder[0].state = 'waiting' diff --git a/sf_sale/models/quick_easy_order.py b/sf_sale/models/quick_easy_order.py index cb1886a1..081807a4 100644 --- a/sf_sale/models/quick_easy_order.py +++ b/sf_sale/models/quick_easy_order.py @@ -8,8 +8,8 @@ from datetime import datetime import requests from odoo import http from odoo.http import request -# from OCC.Extend.DataExchange import read_step_file -# from OCC.Extend.DataExchange import write_stl_file +from OCC.Extend.DataExchange import read_step_file +from OCC.Extend.DataExchange import write_stl_file from odoo import models, fields, api from odoo.modules import get_resource_path from odoo.exceptions import ValidationError, UserError diff --git a/sf_sale/models/quick_easy_order_old.py b/sf_sale/models/quick_easy_order_old.py index d963d021..87848e3a 100644 --- a/sf_sale/models/quick_easy_order_old.py +++ b/sf_sale/models/quick_easy_order_old.py @@ -5,8 +5,8 @@ import requests import os from datetime import datetime # from OCC.Core.GProp import GProp_GProps -# from OCC.Extend.DataExchange import read_step_file -# from OCC.Extend.DataExchange import write_stl_file +from OCC.Extend.DataExchange import read_step_file +from OCC.Extend.DataExchange import write_stl_file from odoo.addons.sf_base.commons.common import Common from odoo import models, fields, api from odoo.modules import get_resource_path diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index a73b0a35..9c0e0b09 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -250,35 +250,36 @@ class RePurchaseOrder(models.Model): server_product_process = [] production_process = product_id_to_production_names.get( production.product_id.id) + purchase_order = self.env['purchase.order'].search( + [('state', '=', 'draft'), ('origin', '=', production.name), + ('purchase_type', '=', 'consignment')], order='name asc') for pp in consecutive_process_parameters: server_template = self.env['product.template'].search( [('server_product_process_parameters_id', '=', pp.surface_technics_parameters_id.id), ('detailed_type', '=', 'service')]) - purchase_order_line = self.env['purchase.order.line'].search( - [('product_id', '=', server_template.product_variant_id.id), - ('product_qty', '=', len(production_process))], limit=1, order='id desc') - if not purchase_order_line: + if not purchase_order: server_product_process.append((0, 0, { 'product_id': server_template.product_variant_id.id, - 'product_qty': len(production_process), + 'product_qty': 1, 'product_uom': server_template.uom_id.id })) - else: - if production.name in production_process: - purchase_order = self.env['purchase.order'].search( - [('state', '=', 'draft'), ('origin', '=', ','.join(production_process)), - ('purchase_type', '=', 'consignment')]) - if not purchase_order: - server_product_process.append((0, 0, { - 'product_id': server_template.product_variant_id.id, - 'product_qty': len(production_process), - 'product_uom': server_template.uom_id.id - })) - + for purchase in purchase_order: + for po in purchase.order_line: + if server_template.server_product_process_parameters_id == pp.surface_technics_parameters_id: + purchase_order_line = self.env['purchase.order.line'].search( + [('product_id', '=', server_template.product_variant_id.id), + ('product_qty', '=', 1.0), ('id', '=', po.id)], limit=1, + order='id desc') + if not purchase_order_line and purchase not in purchase_order: + server_product_process.append((0, 0, { + 'product_id': server_template.product_variant_id.id, + 'product_qty': 1, + 'product_uom': server_template.uom_id.id + })) if server_product_process: self.env['purchase.order'].sudo().create({ 'partner_id': server_template.seller_ids[0].partner_id.id, - 'origin': ','.join(production_process), + 'origin': production.name, 'state': 'draft', 'purchase_type': 'consignment', 'order_line': server_product_process})