diff --git a/jikimo_sale_multiple_supply_methods/__init__.py b/jikimo_sale_multiple_supply_methods/__init__.py index e7a30879..a1ff64da 100644 --- a/jikimo_sale_multiple_supply_methods/__init__.py +++ b/jikimo_sale_multiple_supply_methods/__init__.py @@ -7,11 +7,16 @@ from odoo import api, SUPERUSER_ID def _data_install(cr, registry): env = api.Environment(cr, SUPERUSER_ID, {}) # 获取所有需要设置的产品模板 - env.ref('jikimo_sale_multiple_supply_methods.product_product_purchase').product_tmpl_id.write({'active': False}) - env.ref('jikimo_sale_multiple_supply_methods.product_product_manual_processing').product_tmpl_id.write({'active': False, 'single_manufacturing': True}) - env.ref('jikimo_sale_multiple_supply_methods.product_product_default').product_tmpl_id.write({'active': False}) - env.ref('jikimo_sale_multiple_supply_methods.product_product_raw_material_customer_provided').product_tmpl_id.write({'active': False}) - env.ref('jikimo_sale_multiple_supply_methods.product_product_outsourcing').product_tmpl_id.write({'active': False}) + env.ref('jikimo_sale_multiple_supply_methods.product_template_purchase').product_variant_id.write({'active': False}) + env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').product_variant_id.write({'active': False, 'single_manufacturing': True}) + env.ref('jikimo_sale_multiple_supply_methods.product_template_default').product_variant_id.write({'active': False}) + env.ref('jikimo_sale_multiple_supply_methods.product_template_raw_material_customer_provided').product_variant_id.write({'active': False}) + env.ref('jikimo_sale_multiple_supply_methods.product_template_outsourcing').product_variant_id.write({'active': False}) + env.ref('sf_dlm.product_embryo_sf_self_machining').product_tmpl_id.write({'categ_type': '坯料'}) + env.ref('sf_dlm.product_template_sf').product_tmpl_id.write({'categ_type': '成品'}) + env.ref('sf_dlm.product_embryo_sf_outsource').product_tmpl_id.write({'categ_type': '坯料'}) + env.ref('sf_dlm.product_embryo_sf_purchase').product_tmpl_id.write({'categ_type': '坯料'}) + # 为三步制造增加规则 warehouse = env['stock.warehouse'].search([('company_id', '=', env.company.id)], limit=1) product_route_id = warehouse.pbm_route_id diff --git a/jikimo_sale_multiple_supply_methods/controllers/main.py b/jikimo_sale_multiple_supply_methods/controllers/main.py index 17a8c9a4..9127f80e 100644 --- a/jikimo_sale_multiple_supply_methods/controllers/main.py +++ b/jikimo_sale_multiple_supply_methods/controllers/main.py @@ -19,7 +19,8 @@ class JikimoSaleRoutePicking(Sf_Bf_Connect): res = {'status': 1, 'factory_order_no': ''} # _logger.info('get_bfm_process_order_list:%s' % kw['order_number']) try: - product_id = request.env.ref('jikimo_sale_multiple_supply_methods.product_product_default').sudo() + product_id = request.env.ref('jikimo_sale_multiple_supply_methods.product_template_default').with_context(active_test=False).sudo().product_variant_id + _logger.info('product_id:%s' % product_id) company_id = request.env.ref('base.main_company').sudo() bfm_process_order_list = json.loads(kw['bfm_process_order_list']) order_id = request.env['sale.order'].with_user(request.env.ref("base.user_admin")).sale_order_create( diff --git a/jikimo_sale_multiple_supply_methods/data/product_data.xml b/jikimo_sale_multiple_supply_methods/data/product_data.xml index 43c8bfba..d0921f78 100644 --- a/jikimo_sale_multiple_supply_methods/data/product_data.xml +++ b/jikimo_sale_multiple_supply_methods/data/product_data.xml @@ -1,7 +1,7 @@ - + 人工线下加工模板 @@ -16,10 +16,11 @@ true serial true + 成品 true - + 成品外购模板 @@ -30,10 +31,11 @@ + 成品 true - + 成品委外加工模板 @@ -44,10 +46,11 @@ + 成品 true - + 成品初始化模板 @@ -57,6 +60,7 @@ + 成品 true @@ -65,7 +69,7 @@ - + 坯料客供料模板 @@ -79,6 +83,7 @@ + 坯料 diff --git a/jikimo_sale_multiple_supply_methods/models/quick_easy_order.py b/jikimo_sale_multiple_supply_methods/models/quick_easy_order.py index d61d3a6f..89d3a6d8 100644 --- a/jikimo_sale_multiple_supply_methods/models/quick_easy_order.py +++ b/jikimo_sale_multiple_supply_methods/models/quick_easy_order.py @@ -56,7 +56,7 @@ class QuickEasyOrder(models.Model): 'part_name': '', }) company_id = self.env.ref('base.main_company').sudo() - product_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_product_default').sudo() + product_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_default').sudo().with_context(active_test=False).product_variant_id # user_id = request.env.ref('base.user_admin').sudo() order_id = self.env['sale.order'].sale_order_create(company_id, 'XXXXX', 'XXXXX', 'XXXXX', str(datetime.now()), '现结', '支付宝', state='draft') diff --git a/jikimo_sale_multiple_supply_methods/models/sale_order.py b/jikimo_sale_multiple_supply_methods/models/sale_order.py index 8da34134..27cecac6 100644 --- a/jikimo_sale_multiple_supply_methods/models/sale_order.py +++ b/jikimo_sale_multiple_supply_methods/models/sale_order.py @@ -31,18 +31,18 @@ class SaleOrder(models.Model): # 根据供货方式修改成品模板 if line.supply_method == 'automation': bom_type = 'normal' - product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo() + product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo().product_tmpl_id elif line.supply_method == 'outsourcing': bom_type = 'subcontract' - product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_product_outsourcing').sudo() + product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_outsourcing').sudo() elif line.supply_method == 'purchase': - product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_product_purchase').sudo() + product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_purchase').sudo() elif line.supply_method == 'manual': bom_type = 'normal' - product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_product_manual_processing').sudo() + product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo() # 复制成品模板上的属性 - line.product_id.product_tmpl_id.copy_template(product_template_id.product_tmpl_id) + line.product_id.product_tmpl_id.copy_template(product_template_id) order_id = self product = line.product_id @@ -66,10 +66,10 @@ class SaleOrder(models.Model): # 当成品上带有客供料选项时,生成坯料时选择“客供料”路线 if line.is_incoming_material: # 将成品模板的内容复制到成品上 - customer_provided_embryo = self.env.ref('jikimo_sale_multiple_supply_methods.product_product_raw_material_customer_provided').sudo() + customer_provided_embryo = self.env.ref('jikimo_sale_multiple_supply_methods.product_tempalte_raw_material_customer_provided').sudo() # 创建坯料,客供料的批量不需要创建bom material_customer_provided_embryo = self.env['product.template'].sudo().no_bom_product_create( - customer_provided_embryo, + customer_provided_embryo.with_context(active_test=False).product_variant_id, item, order_id, 'material_customer_provided', 0, product) # 成品配置bom diff --git a/sf_manufacturing/__manifest__.py b/sf_manufacturing/__manifest__.py index 98c71f21..3320f943 100644 --- a/sf_manufacturing/__manifest__.py +++ b/sf_manufacturing/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'sf', 'website': 'https://www.sf.jikimo.com', - 'depends': ['sf_base', 'sf_maintenance', 'web_widget_model_viewer', 'sf_warehouse','jikimo_attachment_viewer', 'jikimo_sale_multiple_supply_methods'], + 'depends': ['sf_base', 'sf_maintenance', 'web_widget_model_viewer', 'sf_warehouse','jikimo_attachment_viewer'], 'data': [ 'data/stock_data.xml', 'data/empty_racks_data.xml', diff --git a/sf_manufacturing/models/model_type.py b/sf_manufacturing/models/model_type.py index 9058e005..d08b024b 100644 --- a/sf_manufacturing/models/model_type.py +++ b/sf_manufacturing/models/model_type.py @@ -10,7 +10,7 @@ class ModelType(models.Model): product_routing_tmpl_ids = fields.One2many('sf.product.model.type.routing.sort', 'product_model_type_id', '成品工序模板(自动化产线加工') embryo_routing_tmpl_ids = fields.One2many('sf.embryo.model.type.routing.sort', 'embryo_model_type_id', - '坯料工序模板') + '坯料工序模板(人工线下加工)') surface_technics_routing_tmpl_ids = fields.One2many('sf.surface_technics.model.type.routing.sort', 'surface_technics_model_type_id', '表面工艺工序模板') diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 1257d9f8..bffc524e 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -277,8 +277,7 @@ class MrpProduction(models.Model): precision_rounding=move.product_uom.rounding or move.product_id.uom_id.rounding) for move in production.move_raw_ids if move.product_id): production.state = 'progress' - elif not production.technology_design_ids: - production.state = 'technology_to_confirmed' + # 新添加的状态逻辑 if ( production.state == 'to_close' or production.state == 'progress') and production.schedule_state == '未排': @@ -1302,17 +1301,17 @@ class MrpProduction(models.Model): return production_values_str # 增加制造订单类型 - production_type = fields.Selection( - [('自动化产线加工', '自动化产线加工'), ('人工线下加工', '人工线下加工')], - string='制造类型', - compute='_compute_production_type', - store=True - ) + # production_type = fields.Selection( + # [('自动化产线加工', '自动化产线加工'), ('人工线下加工', '人工线下加工')], + # string='制造类型', + # compute='_compute_production_type', + # store=True + # ) - @api.depends('product_id.is_manual_processing') - def _compute_production_type(self): - for production in self: - production.production_type = '自动化产线加工' if not production.product_id.is_manual_processing else '人工线下加工' + # @api.depends('product_id.is_manual_processing') + # def _compute_production_type(self): + # for production in self: + # production.production_type = '自动化产线加工' if not production.product_id.is_manual_processing else '人工线下加工' class sf_detection_result(models.Model): diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 73a1fbee..b3d80e47 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -66,358 +66,358 @@ class stockWarehouse(models.Model): class StockRule(models.Model): _inherit = 'stock.rule' - @api.model - def _run_pull(self, procurements): - logging.info(procurements) - moves_values_by_company = defaultdict(list) - mtso_products_by_locations = defaultdict(list) + # @api.model + # def _run_pull(self, procurements): + # logging.info(procurements) + # moves_values_by_company = defaultdict(list) + # mtso_products_by_locations = defaultdict(list) - # To handle the `mts_else_mto` procure method, we do a preliminary loop to - # isolate the products we would need to read the forecasted quantity, - # in order to to batch the read. We also make a sanitary check on the - # `location_src_id` field. + # # To handle the `mts_else_mto` procure method, we do a preliminary loop to + # # isolate the products we would need to read the forecasted quantity, + # # in order to to batch the read. We also make a sanitary check on the + # # `location_src_id` field. - # list1 = [] - # for item in procurements: - # num = int(item[0].product_qty) - # if num > 1: - # for no in range(1, num+1): - # - # Procurement = namedtuple('Procurement', ['product_id', 'product_qty', - # 'product_uom', 'location_id', 'name', 'origin', - # 'company_id', - # 'values']) - # s = Procurement(product_id=item[0].product_id,product_qty=1.0,product_uom=item[0].product_uom, - # location_id=item[0].location_id, - # name=item[0].name, - # origin=item[0].origin, - # company_id=item[0].company_id, - # values=item[0].values, - # ) - # item1 = list(item) - # item1[0]=s - # - # list1.append(tuple(item1)) - # else: - # list1.append(item) + # # list1 = [] + # # for item in procurements: + # # num = int(item[0].product_qty) + # # if num > 1: + # # for no in range(1, num+1): + # # + # # Procurement = namedtuple('Procurement', ['product_id', 'product_qty', + # # 'product_uom', 'location_id', 'name', 'origin', + # # 'company_id', + # # 'values']) + # # s = Procurement(product_id=item[0].product_id,product_qty=1.0,product_uom=item[0].product_uom, + # # location_id=item[0].location_id, + # # name=item[0].name, + # # origin=item[0].origin, + # # company_id=item[0].company_id, + # # values=item[0].values, + # # ) + # # item1 = list(item) + # # item1[0]=s + # # + # # list1.append(tuple(item1)) + # # else: + # # list1.append(item) - for procurement, rule in procurements: - if not rule.location_src_id: - msg = _('No source location defined on stock rule: %s!') % (rule.name,) - raise ProcurementException([(procurement, msg)]) + # for procurement, rule in procurements: + # if not rule.location_src_id: + # msg = _('No source location defined on stock rule: %s!') % (rule.name,) + # raise ProcurementException([(procurement, msg)]) - if rule.procure_method == 'mts_else_mto': - mtso_products_by_locations[rule.location_src_id].append(procurement.product_id.id) + # if rule.procure_method == 'mts_else_mto': + # mtso_products_by_locations[rule.location_src_id].append(procurement.product_id.id) - # Get the forecasted quantity for the `mts_else_mto` procurement. - forecasted_qties_by_loc = {} - for location, product_ids in mtso_products_by_locations.items(): - products = self.env['product.product'].browse(product_ids).with_context(location=location.id) - forecasted_qties_by_loc[location] = {product.id: product.free_qty for product in products} + # # Get the forecasted quantity for the `mts_else_mto` procurement. + # forecasted_qties_by_loc = {} + # for location, product_ids in mtso_products_by_locations.items(): + # products = self.env['product.product'].browse(product_ids).with_context(location=location.id) + # forecasted_qties_by_loc[location] = {product.id: product.free_qty for product in products} - # Prepare the move values, adapt the `procure_method` if needed. - procurements = sorted(procurements, key=lambda proc: float_compare(proc[0].product_qty, 0.0, - precision_rounding=proc[ - 0].product_uom.rounding) > 0) - list2 = [] - for item in procurements: - num = int(item[0].product_qty) + # # Prepare the move values, adapt the `procure_method` if needed. + # procurements = sorted(procurements, key=lambda proc: float_compare(proc[0].product_qty, 0.0, + # precision_rounding=proc[ + # 0].product_uom.rounding) > 0) + # list2 = [] + # for item in procurements: + # num = int(item[0].product_qty) - product = self.env['product.product'].search( - [("id", '=', item[0].product_id.id)]) - product_tmpl = self.env['product.template'].search( - ["&", ("id", '=', product.product_tmpl_id.id), ('single_manufacturing', "!=", False)]) - if product_tmpl: - if num > 1: - for no in range(1, num + 1): - Procurement = namedtuple('Procurement', ['product_id', 'product_qty', - 'product_uom', 'location_id', 'name', 'origin', - 'company_id', - 'values']) - s = Procurement(product_id=item[0].product_id, product_qty=1.0, product_uom=item[0].product_uom, - location_id=item[0].location_id, - name=item[0].name, - origin=item[0].origin, - company_id=item[0].company_id, - values=item[0].values, - ) - item1 = list(item) - item1[0] = s + # product = self.env['product.product'].search( + # [("id", '=', item[0].product_id.id)]) + # product_tmpl = self.env['product.template'].search( + # ["&", ("id", '=', product.product_tmpl_id.id), ('single_manufacturing', "!=", False)]) + # if product_tmpl: + # if num > 1: + # for no in range(1, num + 1): + # Procurement = namedtuple('Procurement', ['product_id', 'product_qty', + # 'product_uom', 'location_id', 'name', 'origin', + # 'company_id', + # 'values']) + # s = Procurement(product_id=item[0].product_id, product_qty=1.0, product_uom=item[0].product_uom, + # location_id=item[0].location_id, + # name=item[0].name, + # origin=item[0].origin, + # company_id=item[0].company_id, + # values=item[0].values, + # ) + # item1 = list(item) + # item1[0] = s - list2.append(tuple(item1)) - else: - list2.append(item) - else: - list2.append(item) + # list2.append(tuple(item1)) + # else: + # list2.append(item) + # else: + # list2.append(item) - for procurement, rule in list2: - procure_method = rule.procure_method - if rule.procure_method == 'mts_else_mto': - qty_needed = procurement.product_uom._compute_quantity(procurement.product_qty, - procurement.product_id.uom_id) - if float_compare(qty_needed, 0, precision_rounding=procurement.product_id.uom_id.rounding) <= 0: - procure_method = 'make_to_order' - for move in procurement.values.get('group_id', self.env['procurement.group']).stock_move_ids: - if move.rule_id == rule and float_compare(move.product_uom_qty, 0, - precision_rounding=move.product_uom.rounding) > 0: - procure_method = move.procure_method - break - forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id] -= qty_needed - elif float_compare(qty_needed, forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id], - precision_rounding=procurement.product_id.uom_id.rounding) > 0: - procure_method = 'make_to_order' - else: - forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id] -= qty_needed - procure_method = 'make_to_stock' - move_values = rule._get_stock_move_values(*procurement) - move_values['procure_method'] = procure_method - moves_values_by_company[procurement.company_id.id].append(move_values) + # for procurement, rule in list2: + # procure_method = rule.procure_method + # if rule.procure_method == 'mts_else_mto': + # qty_needed = procurement.product_uom._compute_quantity(procurement.product_qty, + # procurement.product_id.uom_id) + # if float_compare(qty_needed, 0, precision_rounding=procurement.product_id.uom_id.rounding) <= 0: + # procure_method = 'make_to_order' + # for move in procurement.values.get('group_id', self.env['procurement.group']).stock_move_ids: + # if move.rule_id == rule and float_compare(move.product_uom_qty, 0, + # precision_rounding=move.product_uom.rounding) > 0: + # procure_method = move.procure_method + # break + # forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id] -= qty_needed + # elif float_compare(qty_needed, forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id], + # precision_rounding=procurement.product_id.uom_id.rounding) > 0: + # procure_method = 'make_to_order' + # else: + # forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id] -= qty_needed + # procure_method = 'make_to_stock' + # move_values = rule._get_stock_move_values(*procurement) + # move_values['procure_method'] = procure_method + # moves_values_by_company[procurement.company_id.id].append(move_values) - for company_id, moves_values in moves_values_by_company.items(): - # create the move as SUPERUSER because the current user may not have the rights to do it (mto product - # launched by a sale for example) - moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( - moves_values) - # Since action_confirm launch following procurement_group we should activate it. - moves._action_confirm() - return True + # for company_id, moves_values in moves_values_by_company.items(): + # # create the move as SUPERUSER because the current user may not have the rights to do it (mto product + # # launched by a sale for example) + # moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( + # moves_values) + # # Since action_confirm launch following procurement_group we should activate it. + # moves._action_confirm() + # return True def attachment_update(self, name, res_id, res_field): attachment_info = self.env['ir.attachment'].sudo().search( [('res_id', '=', res_id), ('res_field', '=', res_field)], limit=1) attachment_info.write({'name': name}) - @api.model - def _run_manufacture(self, procurements): - productions_values_by_company = defaultdict(list) - errors = [] - for procurement, rule in procurements: - if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) <= 0: - # If procurement contains negative quantity, don't create a MO that would be for a negative value. - continue - bom = rule._get_matching_bom(procurement.product_id, procurement.company_id, procurement.values) + # @api.model + # def _run_manufacture(self, procurements): + # productions_values_by_company = defaultdict(list) + # errors = [] + # for procurement, rule in procurements: + # if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) <= 0: + # # If procurement contains negative quantity, don't create a MO that would be for a negative value. + # continue + # bom = rule._get_matching_bom(procurement.product_id, procurement.company_id, procurement.values) - productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom)) + # productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom)) - if errors: - raise ProcurementException(errors) + # if errors: + # raise ProcurementException(errors) - for company_id, productions_values in productions_values_by_company.items(): - # create the MO as SUPERUSER because the current user may not have the rights to do it - # (mto product launched by a sale for example) - '''创建制造订单''' - productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( - productions_values) + # for company_id, productions_values in productions_values_by_company.items(): + # # create the MO as SUPERUSER because the current user may not have the rights to do it + # # (mto product launched by a sale for example) + # '''创建制造订单''' + # productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( + # productions_values) - # self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) - # self.env['stock.move'].sudo().create(productions._get_moves_finished_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() - # - self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) - 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() - # 处理 根据制造订单生成的采购单坯料入库时到原材料库,手动将原材料位置该为坯料存货区 - for production in productions: - if production.picking_ids: - product_type_id = production.picking_ids[0].move_ids[0].product_id.categ_id - if product_type_id.name == '坯料': - location_id = self.env['stock.location'].search([('name', '=', '坯料存货区')]) - if not location_id: - logging.info(f'没有搜索到【坯料存货区】: {location_id}') - break - for picking_id in production.picking_ids: - if picking_id.picking_type_id.name == '内部调拨': - if picking_id.location_dest_id.product_type != product_type_id: - picking_id.location_dest_id = location_id.id - elif picking_id.picking_type_id.name == '生产发料': - if picking_id.location_id.product_type != product_type_id: - picking_id.location_id = location_id.id + # ''' + # 创建工单 + # ''' + # # productions._create_workorder() + # # + # self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) + # 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() + # # 处理 根据制造订单生成的采购单坯料入库时到原材料库,手动将原材料位置该为坯料存货区 + # for production in productions: + # if production.picking_ids: + # product_type_id = production.picking_ids[0].move_ids[0].product_id.categ_id + # if product_type_id.name == '坯料': + # location_id = self.env['stock.location'].search([('name', '=', '坯料存货区')]) + # if not location_id: + # logging.info(f'没有搜索到【坯料存货区】: {location_id}') + # break + # for picking_id in production.picking_ids: + # if picking_id.picking_type_id.name == '内部调拨': + # if picking_id.location_dest_id.product_type != product_type_id: + # picking_id.location_dest_id = location_id.id + # elif picking_id.picking_type_id.name == '生产发料': + # if picking_id.location_id.product_type != product_type_id: + # picking_id.location_id = location_id.id - for production in productions: - ''' - 创建制造订单时生成序列号 - ''' - production.action_generate_serial() - origin_production = production.move_dest_ids and production.move_dest_ids[ - 0].raw_material_production_id or False - orderpoint = production.orderpoint_id - if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual': - production.message_post( - body=_('This production order has been created from Replenishment Report.'), - message_type='comment', - subtype_xmlid='mail.mt_note') - elif orderpoint: - production.message_post_with_view( - 'mail.message_origin_link', - values={'self': production, 'origin': orderpoint}, - subtype_id=self.env.ref('mail.mt_note').id) - elif origin_production: - production.message_post_with_view( - 'mail.message_origin_link', - values={'self': production, 'origin': origin_production}, - subtype_id=self.env.ref('mail.mt_note').id) + # for production in productions: + # ''' + # 创建制造订单时生成序列号 + # ''' + # production.action_generate_serial() + # origin_production = production.move_dest_ids and production.move_dest_ids[ + # 0].raw_material_production_id or False + # orderpoint = production.orderpoint_id + # if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual': + # production.message_post( + # body=_('This production order has been created from Replenishment Report.'), + # message_type='comment', + # subtype_xmlid='mail.mt_note') + # elif orderpoint: + # production.message_post_with_view( + # 'mail.message_origin_link', + # values={'self': production, 'origin': orderpoint}, + # subtype_id=self.env.ref('mail.mt_note').id) + # elif origin_production: + # production.message_post_with_view( + # 'mail.message_origin_link', + # values={'self': production, 'origin': origin_production}, + # subtype_id=self.env.ref('mail.mt_note').id) - ''' - 创建生产计划 - ''' - # 工单耗时 - workorder_duration = 0 - for workorder in production.workorder_ids: - workorder_duration += workorder.duration_expected + # ''' + # 创建生产计划 + # ''' + # # 工单耗时 + # workorder_duration = 0 + # for workorder in production.workorder_ids: + # workorder_duration += workorder.duration_expected - sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)]) - if sale_order: - # sale_order.write({'schedule_status': 'to schedule'}) - self.env['sf.production.plan'].sudo().with_company(company_id).create({ - 'name': production.name, - 'order_deadline': sale_order.deadline_of_delivery, - 'production_id': production.id, - 'date_planned_start': production.date_planned_start, - 'origin': production.origin, - 'product_qty': production.product_qty, - 'product_id': production.product_id.id, - 'state': 'draft', - }) - technology_design_values = [] - all_production = productions - grouped_product_ids = {k: list(g) for k, g in groupby(all_production, key=lambda x: x.product_id.id)} - # 初始化一个字典来存储每个product_id对应的生产订单名称列表 - product_id_to_production_names = {} - # 对于每个product_id,获取其所有生产订单的名称 - for product_id, all_production in grouped_product_ids.items(): - # 为同一个product_id创建一个生产订单名称列表 - product_id_to_production_names[product_id] = [production.name for production in all_production] - for production_item in productions: - production_programming = self.env['mrp.production'].search( - [('product_id.id', '=', production_item.product_id.id), - ('origin', '=', production_item.origin)], - limit=1, order='id asc') - if production_item.product_id.id in product_id_to_production_names: - if production_item.product_id.model_process_parameters_ids: - is_purchase = False - sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids, - key=lambda w: w.id) + # sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)]) + # if sale_order: + # # sale_order.write({'schedule_status': 'to schedule'}) + # self.env['sf.production.plan'].sudo().with_company(company_id).create({ + # 'name': production.name, + # 'order_deadline': sale_order.deadline_of_delivery, + # 'production_id': production.id, + # 'date_planned_start': production.date_planned_start, + # 'origin': production.origin, + # 'product_qty': production.product_qty, + # 'product_id': production.product_id.id, + # 'state': 'draft', + # }) + # technology_design_values = [] + # all_production = productions + # grouped_product_ids = {k: list(g) for k, g in groupby(all_production, key=lambda x: x.product_id.id)} + # # 初始化一个字典来存储每个product_id对应的生产订单名称列表 + # product_id_to_production_names = {} + # # 对于每个product_id,获取其所有生产订单的名称 + # for product_id, all_production in grouped_product_ids.items(): + # # 为同一个product_id创建一个生产订单名称列表 + # product_id_to_production_names[product_id] = [production.name for production in all_production] + # for production_item in productions: + # # production_programming = self.env['mrp.production'].search( + # # [('product_id.id', '=', production_item.product_id.id), + # # ('origin', '=', production_item.origin)], + # # limit=1, order='id asc') + # if production_item.product_id.id in product_id_to_production_names: + # if production_item.product_id.model_process_parameters_ids: + # is_purchase = False + # sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids, + # key=lambda w: w.id) - consecutive_process_parameters = [] - m = 0 - for i in range(len(sorted_process_parameters) - 1): - if m == 0: - is_purchase = False - if self.env['product.template']._get_process_parameters_product( - sorted_process_parameters[i]).partner_id == self.env[ - 'product.template']._get_process_parameters_product(sorted_process_parameters[ - i + 1]).partner_id and \ - sorted_process_parameters[i].gain_way == '外协': - if sorted_process_parameters[i] not in consecutive_process_parameters: - consecutive_process_parameters.append(sorted_process_parameters[i]) - consecutive_process_parameters.append(sorted_process_parameters[i + 1]) - m += 1 - continue - else: - if m == len(consecutive_process_parameters) - 1 and m != 0: - self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, - production_item, - product_id_to_production_names) - if sorted_process_parameters[i] in consecutive_process_parameters: - is_purchase = True - consecutive_process_parameters = [] - m = 0 - # 当前面的连续外协采购单生成再生成当前外协采购单 - if is_purchase is False: - self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, - production_item, - product_id_to_production_names) - if m == len(consecutive_process_parameters) - 1 and m != 0: - self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, - production_item, - product_id_to_production_names) - if sorted_process_parameters[i] in consecutive_process_parameters: - is_purchase = True - consecutive_process_parameters = [] - m = 0 - if m == len(consecutive_process_parameters) - 1 and m != 0: - self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, - production_item, - product_id_to_production_names) - if is_purchase is False and m == 0: - if len(sorted_process_parameters) == 1: - self.env['purchase.order'].get_purchase_order(sorted_process_parameters, - production_item, - product_id_to_production_names) - else: - self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i], - production_item, - product_id_to_production_names) - if not technology_design_values: - if production.product_id.categ_id.type == '成品': - production.product_id.model_processing_panel = 'ZM,FM' - # 根据加工面板的面数及成品工序模板生成工序设计 - i = 0 - for k in (production.product_id.model_processing_panel.split(',')): - product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search( - [('product_model_type_id', '=', production.product_id.product_model_type_id.id)], - order='sequence asc' - ) - for route in product_routing_workcenter: - i += 1 - technology_design_values.append( - self.env['sf.technology.design'].json_technology_design_str(k, route, i)) - surface_technics_arr = [] - route_workcenter_arr = [] - for process_param in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids.filtered( - lambda st: st.id in production.product_id.model_process_parameters_ids.ids): - # if item.route_workcenter_id.surface_technics_id.id: - # for process_param in production.product_id.model_process_parameters_ids: - logging.info('process_param:%s%s' % (process_param.id, process_param.name)) - if item.route_workcenter_id.surface_technics_id == process_param.process_id: - logging.info( - 'surface_technics_id:%s%s' % ( - item.route_workcenter_id.surface_technics_id.id, - item.route_workcenter_id.surface_technics_id.name)) - surface_technics_arr.append( - item.route_workcenter_id.surface_technics_id.id) - route_workcenter_arr.append(item.route_workcenter_id.id) - if surface_technics_arr: - production_process = self.env['sf.production.process'].search( - [('id', 'in', surface_technics_arr)], - order='sequence asc' - ) - for p in production_process: - logging.info('production_process:%s' % p.name) - process_parameter = production.product_id.model_process_parameters_ids.filtered( - lambda pm: pm.process_id.id == p.id) - product_production_process = self.env['product.template'].search( - [('server_product_process_parameters_id', '=', - process_parameter.id)]) - if process_parameter: - i += 1 - route_production_process = self.env[ - 'mrp.routing.workcenter'].search( - [('surface_technics_id', '=', p.id), - ('id', 'in', route_workcenter_arr)]) - technology_design_values.append( - self.env['sf.technology.design'].json_technology_design_str(k, - route_production_process, - product_production_process, - i)) - productions.technology_design_ids = technology_design_values + # consecutive_process_parameters = [] + # m = 0 + # for i in range(len(sorted_process_parameters) - 1): + # if m == 0: + # is_purchase = False + # if self.env['product.template']._get_process_parameters_product( + # sorted_process_parameters[i]).partner_id == self.env[ + # 'product.template']._get_process_parameters_product(sorted_process_parameters[ + # i + 1]).partner_id and \ + # sorted_process_parameters[i].gain_way == '外协': + # if sorted_process_parameters[i] not in consecutive_process_parameters: + # consecutive_process_parameters.append(sorted_process_parameters[i]) + # consecutive_process_parameters.append(sorted_process_parameters[i + 1]) + # m += 1 + # continue + # else: + # if m == len(consecutive_process_parameters) - 1 and m != 0: + # self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, + # production_item, + # product_id_to_production_names) + # if sorted_process_parameters[i] in consecutive_process_parameters: + # is_purchase = True + # consecutive_process_parameters = [] + # m = 0 + # # 当前面的连续外协采购单生成再生成当前外协采购单 + # if is_purchase is False: + # self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, + # production_item, + # product_id_to_production_names) + # if m == len(consecutive_process_parameters) - 1 and m != 0: + # self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, + # production_item, + # product_id_to_production_names) + # if sorted_process_parameters[i] in consecutive_process_parameters: + # is_purchase = True + # consecutive_process_parameters = [] + # m = 0 + # if m == len(consecutive_process_parameters) - 1 and m != 0: + # self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, + # production_item, + # product_id_to_production_names) + # if is_purchase is False and m == 0: + # if len(sorted_process_parameters) == 1: + # self.env['purchase.order'].get_purchase_order(sorted_process_parameters, + # production_item, + # product_id_to_production_names) + # else: + # self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i], + # production_item, + # product_id_to_production_names) + # if not technology_design_values: + # if production.product_id.categ_id.type == '成品': + # production.product_id.model_processing_panel = 'ZM,FM' + # # 根据加工面板的面数及成品工序模板生成工序设计 + # i = 0 + # for k in (production.product_id.model_processing_panel.split(',')): + # product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search( + # [('product_model_type_id', '=', production.product_id.product_model_type_id.id)], + # order='sequence asc' + # ) + # for route in product_routing_workcenter: + # i += 1 + # technology_design_values.append( + # self.env['sf.technology.design'].json_technology_design_str(k, route, i)) + # surface_technics_arr = [] + # route_workcenter_arr = [] + # for process_param in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids.filtered( + # lambda st: st.id in production.product_id.model_process_parameters_ids.ids): + # # if item.route_workcenter_id.surface_technics_id.id: + # # for process_param in production.product_id.model_process_parameters_ids: + # logging.info('process_param:%s%s' % (process_param.id, process_param.name)) + # if item.route_workcenter_id.surface_technics_id == process_param.process_id: + # logging.info( + # 'surface_technics_id:%s%s' % ( + # item.route_workcenter_id.surface_technics_id.id, + # item.route_workcenter_id.surface_technics_id.name)) + # surface_technics_arr.append( + # item.route_workcenter_id.surface_technics_id.id) + # route_workcenter_arr.append(item.route_workcenter_id.id) + # if surface_technics_arr: + # production_process = self.env['sf.production.process'].search( + # [('id', 'in', surface_technics_arr)], + # order='sequence asc' + # ) + # for p in production_process: + # logging.info('production_process:%s' % p.name) + # process_parameter = production.product_id.model_process_parameters_ids.filtered( + # lambda pm: pm.process_id.id == p.id) + # product_production_process = self.env['product.template'].search( + # [('server_product_process_parameters_id', '=', + # process_parameter.id)]) + # if process_parameter: + # i += 1 + # route_production_process = self.env[ + # 'mrp.routing.workcenter'].search( + # [('surface_technics_id', '=', p.id), + # ('id', 'in', route_workcenter_arr)]) + # technology_design_values.append( + # self.env['sf.technology.design'].json_technology_design_str(k, + # route_production_process, + # product_production_process, + # i)) + # productions.technology_design_ids = technology_design_values - # # 同一个产品多个制造订单对应一个编程单和模型库 - # # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递 - # if not production_item.programming_no: - # if not production_programming.programming_no: - # production_item.fetchCNC( - # ', '.join(product_id_to_production_names[production_item.product_id.id])) - # else: - # production_item.write({'programming_no': production_programming.programming_no, - # 'programming_state': '编程中'}) - return True + # # # 同一个产品多个制造订单对应一个编程单和模型库 + # # # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递 + # # if not production_item.programming_no: + # # if not production_programming.programming_no: + # # production_item.fetchCNC( + # # ', '.join(product_id_to_production_names[production_item.product_id.id])) + # # else: + # # production_item.write({'programming_no': production_programming.programming_no, + # # 'programming_state': '编程中'}) + # return True class ProductionLot(models.Model): diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index c218c2d5..2bccedf0 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -36,8 +36,8 @@ decoration-success="reservation_state == 'assigned'"/> - + @@ -91,7 +91,7 @@ - + - +