@isTest public class DealerConsumableManageBatch1Test { static final String RC_BYOUIN = '病院'; static final String RC_HANBAOITEN = '販売店'; static final String RC_KEIYAKU = '契約'; private static String quoteNo = 'textQutote01'; public static String CurrencyIso = 'CNY'; private static Boolean isUnitPrice = true; private static Boolean isOfferAmount = true; private static Boolean isTotalPrice = true; private static Boolean isDiscountRate = true; private static Boolean isDiscountAmount = true; private static Boolean isTradingPrice = true; private static Boolean isContractDetail = true; private static Date offerExpireDate = Date.today(); private static String clientName = 'test client'; private static String offerComment = 'test comment'; private static Date offerPrintDate = Date.today(); private static String agentName = 'test agent name'; private static Id pricebookId = ControllerUtil.getStandardPricebook().Id; @isTest static void Test1(){ RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_BYOUIN limit 1]; Account hospital = new Account(Name = 'テスト病院'); hospital.RecordTypeId = recByoin.id; hospital.Site = 'テスト病院部門'; hospital.Alias_Name2__c = 'テスト病院別名'; insert hospital; // 产品 Product2 prd1 = new Product2(); prd1.ProductCode_Ext__c = 'Prd1'; prd1.ProductCode = 'Prd1'; prd1.Repair_Product_Code__c = 'Prd1_RP'; prd1.Name = 'Prd1'; prd1.Manual_Entry__c = false; prd1.Category2__c = '本体'; prd1.Category3__c = '纤维镜'; prd1.Category4__c = 'CV'; prd1.Category5__c = '260SL系列'; prd1.Asset_Model_No__c = '1001'; prd1.Important_product__c = true; prd1.Important_Rroduct_1GI__c = true; prd1.ENG_New__c = 'ENG2'; insert prd1; PricebookEntry entry = new PricebookEntry(Pricebook2Id = pricebookId, Product2Id = prd1.Id); entry.UnitPrice = 0; entry.IsActive = true; entry.UseStandardPrice = false; entry.CurrencyIsoCode = 'CNY'; insert entry; RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1]; Account sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Hospital__c = hospital.id; sellerA.Tax_Practice_No__c = '001'; sellerA.Sales_Shop_Class__c = '特約販売店(区域)'; sellerA.Business_Authorization_No__c = '001'; sellerA.Tax_Practice_Expiration_Date__c = Date.today().addDays(20); sellerA.Business_Paper_Expiration_Date__c = Date.today().addDays(20); insert sellerA; RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1]; Account contractA = new Account(Name = '*'); contractA.RecordTypeId = recKeiyaku.id; contractA.Agent_Ref__c = sellerA.id; contractA.Hospital__c=hospital.id; contractA.ParentId = sellerA.id; insert contractA; Tender_information__c te1 = new Tender_information__c(); te1.Name = 'TestZhaoBiao1'; insert te1; lexNewQuoteEntryController.selectAccountById(contractA.Id); StaticParameter.EscapeOppandStaTrigger = true; StaticParameter.EscapeConsumableOrderDetail2Trigger = true; RecordType recHanbaitenopp = [select id from RecordType where IsActive = true and SobjectType= 'Opportunity' and Name='引合' limit 1]; Opportunity opp = new Opportunity( Name='aiueo', StageName='出荷', CloseDate=Date.today()); opp.Trade__c = '外貿'; //opp.CurrencyIsoCode = CurrencyIso; opp.Sales_Root__c = '販売店'; opp.StageName = '出荷'; opp.Fixed_Check__c = false; opp.owner_not_automatically_update__c = true; //opp.Pricebook2Id = pricebook.id; opp.Purchase_Type__c = '一般引合'; opp.Promise_Class__c = '外貿'; opp.Fund_Basis__c = '政府資金'; opp.AccountId = contractA.id; opp.Hospital__c = contractA.id; opp.Agency1__c = sellerA.id; opp.Wholesale_Price__c = 9000; opp.Opportunity_stage__c = '预算已经批准'; opp.Close_Forecasted_Date__c = Date.today().addDays(50); opp.Special_Opp_lanhai__c = true; opp.CurrencyIsoCode = 'CNY'; insert opp; String quoc = '{"Name":"测试425","Cancel_Decide__c":false,"CreatedDate":"2023-10-03","PriceRefreshDate__c":"2023-10-03","MainEngineWithoutMonitor__c":false,"Interdepartmental__c":false,"Dealer_Final_Price__c":577632,"TotalPrice__c":753040,"Estimation_List_Price__c":722040,"QuoteNumber":"00333230","Quote_Expiration_Date__c":"2023-11-02","Unit_Price__c":false,"Offer_Amount__c":true,"TOTAL__c":true,"Discount__c":false,"Pricing__c":false,"Preferential_Trading_Price__c":false,"Contract__c":false,"Agency1__c":"0011000000V9RB6AAN","OCM_Agent1_Price__c":406460.8,"Agency1_Profit__c":171171.2,"Agency1_Profit_Rate__c":29.63,"Print_HP_Name__c":"上海交通大学医学院附属瑞金医院舟山分院","Agency2_Profit__c":0,"Agency2_Profit_Rate__c":0,"Quote_No__c":"SH-BF-ZJ0847324-01","Quote_Adjust_Amount__c":0,"Quote_Adjust_Calculate__c":null,"Discount_Amount__c":175408,"Discount_Amount_Calculate__c":23.29,"AgencyDiscount__c":52,"Gurantee_Period__c":"1","multiYearWarranty__c":true,"MultiYearWarrantyTotalPrice__c":31000,"Preferential_Gurantee_Period__c":true,"LineItemCount":2,"IsQuoteTrial__c":true,"OpportunityId":"006Hy00000A10ElIAJ","Opportunity":{"RecordTypeId":"01210000000QekKAAS","Id":"006Hy00000A10ElIAJ","RecordType":{"DeveloperName":"Opportunity","Id":"01210000000QekKAAS"}},"PriceRefreshPeriod":4,"QuoteName__c":"","QuoteTotal_Page__c":753040,"Dealer_Final_Price_Page__c":577632,"Quote_Adjust_Amount_Page__c":null,"OCM_Agent1_Price_Page__c":0,"Agent1_Agent2_Price_Page__c":null,"hidden_Estimation_List":"722040.00","Stocking_Price__c":206268,"Agency2__c":null}'; Quote quos = (Quote)JSON.deserialize(quoc,Quote.class); quos.Agency1__c = sellerA.id; quos.OpportunityId = opp.Id; quos.Pricebook2Id = pricebookId; quos.Opportunity.RecordType.Id=recKeiyaku.Id; // 删除ID属性 // 执行插入操作 insert quos; Map result = new Map(); lexNewQuoteEntryController.changedAfterPrint=true; lexNewQuoteEntryController.newQuoteFlag=true; // lexNewQuoteEntryController.dataEntry(); lexNewQuoteEntryController.qname=true; lexNewQuoteEntryController.dfpp=true; lexNewQuoteEntryController.qacc=true; lexNewQuoteEntryController.qaapc=true; lexNewQuoteEntryController.Agency1=true; lexNewQuoteEntryController.nAgency1=true; lexNewQuoteEntryController.oapp=true; lexNewQuoteEntryController.noapp=true; lexNewQuoteEntryController.Agency2=true; lexNewQuoteEntryController.nAgency2=true; lexNewQuoteEntryController.aapp=true; lexNewQuoteEntryController.naapp=true; lexNewQuoteEntryController.resultFlag(result); lexNewQuoteEntryController.selectQuoteById(quos.Id); // 报价行项目 QuoteLineItem target = new QuoteLineItem(); target.Name__c = 'テスト商品'; target.QuoteId = quos.id; target.Quantity = 1; target.Cost_Subtotal__c = 0; target.Cost__c = 200; target.Item_Order__c = 3; target.UnitPrice = 10; target.Product2Id = prd1.id; target.PricebookEntryId = entry.Id; insert target; String CheckItemCan = null; Boolean SkipQuotefilgc = false; boolean WinOrDecideAlertc = false; String activitiesCan = '[{"wrong_Register":false,"VenderName":"OSH","StorageStatus":null,"Specifications":1,"Sales_Possibility":null,"ProductGuranteePrice":0,"pageObject":{"attributes":{"type":"QuoteLineItem"},"Asset_Model_No__c":"CF-H170L","SFDA_Status__c":"有効","Product_Sales_Possibility__c":"○","Name__c":"CF-H170L:电子大肠内窥镜","BSS_Category__c":"GI Imaging","QuoteId":"0Q0Hy000000BLvXKAW","PricebookEntryId":"01u1000000DLEuZAAX","Qty_Unit__c":"1","Cost__c":87235,"UnitPrice__c":358440,"ListPrice__c":358440,"Quantity":1,"TotalPrice__c":358440,"ProductCode__c":"N4479980","Product_Cost__c":87235,"Product_ListPrice__c":358440,"UnitPrice_Page__c":358440,"AgencyUnitPrice__c":186388.8,"AgencySubtotal__c":186388.8,"Present__c":false,"multiYearWarranty__c":false,"If_Cancel_Guarantee__c":false,"GuaranteePeriod__c":1,"ServicePrice__c":0,"GuranteePrice__c":0,"ProductEntend_gurantee_period_all__c":0,"ProductGuranteePrice__c":0,"productServicePrice__c":0,"NoDiscountTotal__c":0,"provistonPeriod__c":0,"Maintenance_Price_Year__c":22000,"Quote":{"attributes":{"type":"Quote","url":"/services/data/v58.0/sobjects/Quote/0Q0Hy000000BLvXKAW"},"OpportunityId":"006Hy00000A10ElIAJ","Id":"0Q0Hy000000BLvXKAW","Opportunity":{"attributes":{"type":"Opportunity","url":"/services/data/v58.0/sobjects/Opportunity/006Hy00000A10ElIAJ"},"Trade__c":"内貿","Id":"006Hy00000A10ElIAJ"}},"PricebookEntry":{"attributes":{"type":"PricebookEntry","url":"/services/data/v58.0/sobjects/PricebookEntry/01u1000000DLEuZAAX"},"Product2Id":"01t10000002pc9SAAQ","Id":"01u1000000DLEuZAAX","Product2":{"attributes":{"type":"Product2","url":"/services/data/v58.0/sobjects/Product2/01t10000002pc9SAAQ"},"VenderName__c":"OSH","CanNotCancelledGurantee__c":false,"Is_DangerousChemicals__c":false,"SFDA_Status__c":"有効","Sales_Possibility__c":"○","Name":"CF-H170L:电子大肠内窥镜","Packing_list_manual__c":1,"Entend_gurantee_period_all__c":0,"Intra_Trade_Gurantee_RMB__c":0,"Intra_Trade_Service_RMB__c":0,"Maintenance_Price_Year__c":22000,"Repair_Contract_USD__c":2864,"Intra_Trade_Foreign_RMB__c":0,"NoDiscount_Foreign__c":0,"LastbuyProductFLG__c":false,"Category5__c":"170系列","Estimated_ConsumptionDueDate__c":"2023-10-01","Id":"01t10000002pc9SAAQ"}},"Id__c":"01t10000002pc9SAAQ","Quantity__c":1,"Subtotal__c":358440,"GuranteeType__c":"","ListPrice_Page":358440},"Maintenance_Price_Year":22000,"ListPrice_Page":358440,"lineNo":1,"latestInfo":{"Specifications":1,"SFDA_Status":"有効","Sales_Possibility":"○","ProductName":"CF-H170L:电子大肠内窥镜","ProductEntend_gurantee_period_all":0,"ProductCode":"N4479980","Maintenance_Price_Year":22000,"ListPrice":358440,"Is_DangerousChemicals":null,"Intra_Trade_Service":0,"Intra_Trade_Gurantee":0,"GuranteeType":"","Cost":87235,"CanNotCancelledGurantee":false},"Is_DangerousChemicals":false,"haveno_Register":false,"GuranteePrice":0,"Estimated_ConsumptionDueDate":"2023/10/01","Cost_Subtotal_c":87235,"Cost_c":87235,"changed_sfda":false,"changed_name":false,"changed_list":false,"changed_cost":false,"Category5":"170系列","CanNotCancelledGurantee":false,"Asset_Model":"CF-H170L","Quantity__c":1,"UnitPrice_Page__c":358440,"AgencySubtotal__c":186388.8,"AgencyUnitPrice__c":186388.8,"multiYearWarranty__c":false,"GuaranteePeriod__c":1,"NoDiscountTotal__c":0,"SFDA_Status__c":"有效","Name__c":"CF-H170L:电子大肠内窥镜","Subtotal__c":358440,"Name":"/01t10000002pc9SAAQ","EstimatedConsumptionDueDateclass":"slds-text-color_error slds-text-title_caps"},{"wrong_Register":false,"VenderName":"OSH","StorageStatus":null,"Specifications":1,"Sales_Possibility":null,"ProductGuranteePrice":32698,"pageObject":{"attributes":{"type":"QuoteLineItem"},"Asset_Model_No__c":"CF-H190I","SFDA_Status__c":"有効","Product_Sales_Possibility__c":"○","Name__c":"CF-H190I:电子结肠内窥镜","BSS_Category__c":"GI Imaging","QuoteId":"0Q0Hy000000BLvXKAW","PricebookEntryId":"01u1000000DLEuTAAX","Qty_Unit__c":"1","Cost__c":119033,"UnitPrice__c":394600,"ListPrice__c":363600,"Quantity":1,"TotalPrice__c":394600,"ProductCode__c":"N3802480","Product_Cost__c":119033,"Product_ListPrice__c":363600,"UnitPrice_Page__c":394600,"AgencyUnitPrice__c":220072,"AgencySubtotal__c":220072,"Present__c":false,"multiYearWarranty__c":true,"If_Cancel_Guarantee__c":false,"GuaranteePeriod__c":3,"ServicePrice__c":31000,"GuranteePrice__c":32698,"ProductEntend_gurantee_period_all__c":3,"ProductGuranteePrice__c":32698,"GuranteeType__c":"市场","warrantyType__c":"市场多年保修","productServicePrice__c":31000,"NoDiscountTotal__c":31000,"provistonPeriod__c":3,"Maintenance_Price_Year__c":19400,"Quote":{"attributes":{"type":"Quote","url":"/services/data/v58.0/sobjects/Quote/0Q0Hy000000BLvXKAW"},"OpportunityId":"006Hy00000A10ElIAJ","Id":"0Q0Hy000000BLvXKAW","Opportunity":{"attributes":{"type":"Opportunity","url":"/services/data/v58.0/sobjects/Opportunity/006Hy00000A10ElIAJ"},"Trade__c":"内貿","Id":"006Hy00000A10ElIAJ"}},"PricebookEntry":{"attributes":{"type":"PricebookEntry","url":"/services/data/v58.0/sobjects/PricebookEntry/01u1000000DLEuTAAX"},"Product2Id":"01t10000002pc9PAAQ","Id":"01u1000000DLEuTAAX","Product2":{"attributes":{"type":"Product2","url":"/services/data/v58.0/sobjects/Product2/01t10000002pc9PAAQ"},"VenderName__c":"OSH","CanNotCancelledGurantee__c":true,"Is_DangerousChemicals__c":false,"SFDA_Status__c":"有効","Sales_Possibility__c":"○","Name":"CF-H190I:电子结肠内窥镜","Packing_list_manual__c":1,"Entend_gurantee_period_all__c":3,"Intra_Trade_Gurantee_RMB__c":32698,"Intra_Trade_Service_RMB__c":31000,"GuranteeType__c":"市场","Maintenance_Price_Year__c":19400,"Repair_Contract_USD__c":2525,"Intra_Trade_Foreign_RMB__c":4045,"NoDiscount_Foreign__c":4035,"LastbuyProductFLG__c":false,"Category5__c":"190系列","Id":"01t10000002pc9PAAQ"}},"Id__c":"01t10000002pc9PAAQ","Quantity__c":1,"Subtotal__c":394600,"ListPrice_Page":363600},"Maintenance_Price_Year":19400,"ListPrice_Page":363600,"lineNo":2,"latestInfo":{"Specifications":1,"SFDA_Status":"有効","Sales_Possibility":"○","ProductName":"CF-H190I:电子结肠内窥镜","ProductEntend_gurantee_period_all":3,"ProductCode":"N3802480","Maintenance_Price_Year":19400,"ListPrice":363600,"Is_DangerousChemicals":null,"Intra_Trade_Service":31000,"Intra_Trade_Gurantee":32698,"GuranteeType":"市场","Cost":119033,"CanNotCancelledGurantee":true},"Is_DangerousChemicals":false,"haveno_Register":false,"GuranteePrice":32698,"Estimated_ConsumptionDueDate":"","Cost_Subtotal_c":119033,"Cost_c":119033,"changed_sfda":false,"changed_name":false,"changed_list":false,"changed_cost":false,"Category5":"190系列","CanNotCancelledGurantee":true,"Asset_Model":"CF-H190I","Quantity__c":1,"UnitPrice_Page__c":394600,"AgencySubtotal__c":220072,"AgencyUnitPrice__c":220072,"multiYearWarranty__c":true,"GuaranteePeriod__c":3,"warrantyType__c":"市场多年保修","NoDiscountTotal__c":31000,"SFDA_Status__c":"有效","Name__c":"CF-H190I:电子结肠内窥镜","Subtotal__c":394600,"Name":"/01t10000002pc9PAAQ","EstimatedConsumptionDueDateclass":""}]'; Boolean changedAfterPrintc = false; boolean enableSalesc = true; boolean newQuoteFlagc = true; String oppIdc = opp.Id; String oppInfoc = JSON.serialize(opp); boolean productStatusUpdatedc = false; String quoIdc = ''; String quoteGurantee_Periodc = null; String quotemultiYearWarrantyc = null; String selection_hpc = '杭州市丁桥医院'; Boolean quoteflg = true; prd1.Category5__c = '虚拟'; update prd1; lexNewQuoteEntryController.SaveQuote(activitiesCan,CheckItemCan,WinOrDecideAlertc,productStatusUpdatedc, oppInfoc,enableSalesc,quoc,oppIdc,quoIdc,newQuoteFlagc,changedAfterPrintc,quoteGurantee_Periodc, quotemultiYearWarrantyc,selection_hpc,SkipQuotefilgc,quoteflg,''); opp.StageName = '出荷'; opp.NotesApprovedNo__c = '8888'; opp.Opportunity_Category__c ='ET'; opp.RecordTypeId = recHanbaitenopp.Id; // Database.DMLOptions dmlOptions = new Database.DMLOptions(); // dmlOptions.DuplicateRuleHeader.AllowSave = true; // dmlOptions.DuplicateRuleHeader.RunAsCurrentUser = true; // dmlOptions.EmailHeader.triggerUserEmail = false; // Database.SaveResult updateResult; // Database.update(opp, dmlOptions); // updateResult = Database.update(opp, dmlOptions); update opp; Statu_Achievements__c Sac = new Statu_Achievements__c(name = 'zhucan_one', Opportunity__c = opp.id, DeliveryDate__c = Date.today(), ContractNO__c = 'ContractNO1', ContractAmount__c = 100,FirstApproveDate__c = Date.valueOf('2023-12-30')); insert Sac; List activities = (List)JSON.deserialize(activitiesCan,List.class); List ols = New List(); Quote quo = (Quote)JSON.deserialize(quoc,Quote.class); for (QELine s : activities) { OpportunityLineItem ol = new OpportunityLineItem(); ol.OpportunityId = opp.Id; ol.Id__c = s.pageObject.Id__c; ol.SFDA_Status__c = s.pageObject.SFDA_Status__c; ol.Name__c = s.pageObject.Name__c; ol.ListPrice__c = s.ListPrice_Page; ol.Quantity = s.pageObject.Quantity__c; ol.UnitPrice = 0; ol.UnitPrice__c = s.pageObject.UnitPrice_Page__c; ol.AgencyUnitPrice__c = s.pageObject.AgencyUnitPrice__c; ol.Present__c = s.pageObject.Present__c; ol.AgencySubtotal__c = s.pageObject.AgencySubtotal__c; ol.GuaranteePeriod__c = s.pageObject.GuaranteePeriod__c; ol.multiYearWarranty__c = s.pageObject.multiYearWarranty__c; ol.ServicePrice__c = s.pageObject.ServicePrice__c; ol.If_Cancel_Guarantee__c = s.pageObject.If_Cancel_Guarantee__c; ol.ProductEntend_gurantee_period_all__c = s.pageObject.ProductEntend_gurantee_period_all__c; ol.GuranteeType__c = s.pageObject.GuranteeType__c; ol.NoDiscountTotal__c = s.pageObject.NoDiscountTotal__c; ol.warrantyType__c = s.pageObject.warrantyType__c; ol.productServicePrice__c = s.pageObject.productServicePrice__c; ol.GuranteePrice__c = s.GuranteePrice; ol.ProductGuranteePrice__c = s.ProductGuranteePrice; ol.Maintenance_Price_Year__c = s.Maintenance_Price_Year; ol.provistonPeriod__c = s.pageObject.provistonPeriod__c; ol.Qty_Unit__c = s.pageObject.Qty_Unit__c; ol.Cost__c = s.pageObject.Cost__c; ol.BSS_Category__c = s.pageObject.BSS_Category__c; ol.CanNotCancelFlag__c = s.CanNotCancelledGurantee;//预测金额修改 fy ol.PricebookEntryId = entry.Id; ol.OCM_Sales_Forecast__c = 10000; ols.add(ol); } insert ols[0]; List opp1 = [SELECT id,Opportunity.OCM_man_province_no_dealer__c,Opportunity.Agency1__c FROM OpportunityLineItem where OpportunityId =:opp.Id]; System.debug('opp>>'+opp); for(OpportunityLineItem oppvalue : opp1){ System.debug('opp1value>>'+oppvalue); } system.debug('aa+'+opp1); Integer year = Date.today().addDays(-70).year(); Integer FYear = year; if(Date.today().addDays(-70)>=Date.newInstance(year, 4, 1)){ FYear = FYear+1; } String OCSMYear= 'FY'+FYear; String keys= opp1[0].Opportunity.Agency1__c+'-ET-'+OCSMYear+'-'+opp1[0].Opportunity.OCM_man_province_no_dealer__c; Dealer_ConsumableManage__c dc = new Dealer_ConsumableManage__c(); dc.TMS_Key__c = keys; dc.ET_ENG__c = 'ET'; dc.FY__c = OCSMYear; dc.Dealer_Name__c = sellerA.Id; dc.FY_S_1__c = 50; dc.FY_S_2__c = 50; dc.FY_S_3__c = 50; dc.FY_S_4__c = 50; dc.FY_S_5__c = 50; dc.FY_S_6__c = 50; dc.FY_S_7__c = 50; dc.FY_S_8__c = 50; dc.FY_S_9__c = 50; dc.FY_S_10__c = 50; dc.FY_S_11__c = 50; dc.FY_S_12__c = 50; insert dc; String keys1= opp1[0].Opportunity.Agency1__c+'-ENG-'+OCSMYear+'-'+opp1[0].Opportunity.OCM_man_province_no_dealer__c; Dealer_ConsumableManage__c dc1 = new Dealer_ConsumableManage__c(); dc1.TMS_Key__c = keys1; dc1.ET_ENG__c = 'ET'; dc1.FY__c = OCSMYear; dc1.Dealer_Name__c = sellerA.Id; insert dc1; Test.StartTest(); Database.executeBatch( new DealerConsumableManageBatch1(Date.today().addDays(-70),Date.today().addDays(50),false),10); Test.stopTest(); } @isTest static void Test2(){ RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_BYOUIN limit 1]; Account hospital = new Account(Name = 'テスト病院'); hospital.RecordTypeId = recByoin.id; hospital.Site = 'テスト病院部門'; hospital.Alias_Name2__c = 'テスト病院別名'; insert hospital; // 产品 Product2 prd1 = new Product2(); prd1.ProductCode_Ext__c = 'Prd1'; prd1.ProductCode = 'Prd1'; prd1.Repair_Product_Code__c = 'Prd1_RP'; prd1.Name = 'Prd1'; prd1.Manual_Entry__c = false; prd1.Category2__c = '本体'; prd1.Category3__c = '纤维镜'; prd1.Category4__c = 'CV'; prd1.Category5__c = '260SL系列'; prd1.Asset_Model_No__c = '1001'; prd1.Important_product__c = true; prd1.Important_Rroduct_1GI__c = true; prd1.ENG_New__c = 'ENG2'; insert prd1; PricebookEntry entry = new PricebookEntry(Pricebook2Id = pricebookId, Product2Id = prd1.Id); entry.UnitPrice = 0; entry.IsActive = true; entry.UseStandardPrice = false; entry.CurrencyIsoCode = 'CNY'; insert entry; RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1]; Account sellerA = new Account(Name = '販売店'); sellerA.RecordTypeId = recHanbaiten.id; sellerA.Hospital__c = hospital.id; sellerA.Tax_Practice_No__c = '001'; sellerA.Sales_Shop_Class__c = '特約販売店(区域)'; sellerA.Business_Authorization_No__c = '001'; sellerA.Tax_Practice_Expiration_Date__c = Date.today().addDays(20); sellerA.Business_Paper_Expiration_Date__c = Date.today().addDays(20); insert sellerA; RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1]; Account contractA = new Account(Name = '*'); contractA.RecordTypeId = recKeiyaku.id; contractA.Agent_Ref__c = sellerA.id; contractA.Hospital__c=hospital.id; contractA.ParentId = sellerA.id; insert contractA; Tender_information__c te1 = new Tender_information__c(); te1.Name = 'TestZhaoBiao1'; insert te1; lexNewQuoteEntryController.selectAccountById(contractA.Id); StaticParameter.EscapeOppandStaTrigger = true; StaticParameter.EscapeConsumableOrderDetail2Trigger = true; RecordType recHanbaitenopp = [select id from RecordType where IsActive = true and SobjectType= 'Opportunity' and Name='引合' limit 1]; Opportunity opp = new Opportunity( Name='aiueo', StageName='出荷', CloseDate=Date.today()); opp.Trade__c = '外貿'; //opp.CurrencyIsoCode = CurrencyIso; opp.Sales_Root__c = '販売店'; opp.StageName = '出荷'; opp.Fixed_Check__c = false; opp.owner_not_automatically_update__c = true; //opp.Pricebook2Id = pricebook.id; opp.Purchase_Type__c = '一般引合'; opp.Promise_Class__c = '外貿'; opp.Fund_Basis__c = '政府資金'; opp.AccountId = contractA.id; opp.Hospital__c = contractA.id; opp.Agency1__c = sellerA.id; opp.Wholesale_Price__c = 9000; opp.Opportunity_stage__c = '预算已经批准'; opp.Close_Forecasted_Date__c = Date.today().addDays(50); opp.Special_Opp_lanhai__c = true; opp.CurrencyIsoCode = 'CNY'; insert opp; String quoc = '{"Name":"测试425","Cancel_Decide__c":false,"CreatedDate":"2023-10-03","PriceRefreshDate__c":"2023-10-03","MainEngineWithoutMonitor__c":false,"Interdepartmental__c":false,"Dealer_Final_Price__c":577632,"TotalPrice__c":753040,"Estimation_List_Price__c":722040,"QuoteNumber":"00333230","Quote_Expiration_Date__c":"2023-11-02","Unit_Price__c":false,"Offer_Amount__c":true,"TOTAL__c":true,"Discount__c":false,"Pricing__c":false,"Preferential_Trading_Price__c":false,"Contract__c":false,"Agency1__c":"0011000000V9RB6AAN","OCM_Agent1_Price__c":406460.8,"Agency1_Profit__c":171171.2,"Agency1_Profit_Rate__c":29.63,"Print_HP_Name__c":"上海交通大学医学院附属瑞金医院舟山分院","Agency2_Profit__c":0,"Agency2_Profit_Rate__c":0,"Quote_No__c":"SH-BF-ZJ0847324-01","Quote_Adjust_Amount__c":0,"Quote_Adjust_Calculate__c":null,"Discount_Amount__c":175408,"Discount_Amount_Calculate__c":23.29,"AgencyDiscount__c":52,"Gurantee_Period__c":"1","multiYearWarranty__c":true,"MultiYearWarrantyTotalPrice__c":31000,"Preferential_Gurantee_Period__c":true,"LineItemCount":2,"IsQuoteTrial__c":true,"OpportunityId":"006Hy00000A10ElIAJ","Opportunity":{"RecordTypeId":"01210000000QekKAAS","Id":"006Hy00000A10ElIAJ","RecordType":{"DeveloperName":"Opportunity","Id":"01210000000QekKAAS"}},"PriceRefreshPeriod":4,"QuoteName__c":"","QuoteTotal_Page__c":753040,"Dealer_Final_Price_Page__c":577632,"Quote_Adjust_Amount_Page__c":null,"OCM_Agent1_Price_Page__c":0,"Agent1_Agent2_Price_Page__c":null,"hidden_Estimation_List":"722040.00","Stocking_Price__c":206268,"Agency2__c":null}'; Quote quos = (Quote)JSON.deserialize(quoc,Quote.class); quos.Agency1__c = sellerA.id; quos.OpportunityId = opp.Id; quos.Pricebook2Id = pricebookId; quos.Opportunity.RecordType.Id=recKeiyaku.Id; // 删除ID属性 // 执行插入操作 insert quos; Map result = new Map(); lexNewQuoteEntryController.changedAfterPrint=true; lexNewQuoteEntryController.newQuoteFlag=true; // lexNewQuoteEntryController.dataEntry(); lexNewQuoteEntryController.qname=true; lexNewQuoteEntryController.dfpp=true; lexNewQuoteEntryController.qacc=true; lexNewQuoteEntryController.qaapc=true; lexNewQuoteEntryController.Agency1=true; lexNewQuoteEntryController.nAgency1=true; lexNewQuoteEntryController.oapp=true; lexNewQuoteEntryController.noapp=true; lexNewQuoteEntryController.Agency2=true; lexNewQuoteEntryController.nAgency2=true; lexNewQuoteEntryController.aapp=true; lexNewQuoteEntryController.naapp=true; lexNewQuoteEntryController.resultFlag(result); lexNewQuoteEntryController.selectQuoteById(quos.Id); // 报价行项目 QuoteLineItem target = new QuoteLineItem(); target.Name__c = 'テスト商品'; target.QuoteId = quos.id; target.Quantity = 1; target.Cost_Subtotal__c = 0; target.Cost__c = 200; target.Item_Order__c = 3; target.UnitPrice = 10; target.Product2Id = prd1.id; target.PricebookEntryId = entry.Id; insert target; String CheckItemCan = null; Boolean SkipQuotefilgc = false; boolean WinOrDecideAlertc = false; String activitiesCan = '[{"wrong_Register":false,"VenderName":"OSH","StorageStatus":null,"Specifications":1,"Sales_Possibility":null,"ProductGuranteePrice":0,"pageObject":{"attributes":{"type":"QuoteLineItem"},"Asset_Model_No__c":"CF-H170L","SFDA_Status__c":"有効","Product_Sales_Possibility__c":"○","Name__c":"CF-H170L:电子大肠内窥镜","BSS_Category__c":"GI Imaging","QuoteId":"0Q0Hy000000BLvXKAW","PricebookEntryId":"01u1000000DLEuZAAX","Qty_Unit__c":"1","Cost__c":87235,"UnitPrice__c":358440,"ListPrice__c":358440,"Quantity":1,"TotalPrice__c":358440,"ProductCode__c":"N4479980","Product_Cost__c":87235,"Product_ListPrice__c":358440,"UnitPrice_Page__c":358440,"AgencyUnitPrice__c":186388.8,"AgencySubtotal__c":186388.8,"Present__c":false,"multiYearWarranty__c":false,"If_Cancel_Guarantee__c":false,"GuaranteePeriod__c":1,"ServicePrice__c":0,"GuranteePrice__c":0,"ProductEntend_gurantee_period_all__c":0,"ProductGuranteePrice__c":0,"productServicePrice__c":0,"NoDiscountTotal__c":0,"provistonPeriod__c":0,"Maintenance_Price_Year__c":22000,"Quote":{"attributes":{"type":"Quote","url":"/services/data/v58.0/sobjects/Quote/0Q0Hy000000BLvXKAW"},"OpportunityId":"006Hy00000A10ElIAJ","Id":"0Q0Hy000000BLvXKAW","Opportunity":{"attributes":{"type":"Opportunity","url":"/services/data/v58.0/sobjects/Opportunity/006Hy00000A10ElIAJ"},"Trade__c":"内貿","Id":"006Hy00000A10ElIAJ"}},"PricebookEntry":{"attributes":{"type":"PricebookEntry","url":"/services/data/v58.0/sobjects/PricebookEntry/01u1000000DLEuZAAX"},"Product2Id":"01t10000002pc9SAAQ","Id":"01u1000000DLEuZAAX","Product2":{"attributes":{"type":"Product2","url":"/services/data/v58.0/sobjects/Product2/01t10000002pc9SAAQ"},"VenderName__c":"OSH","CanNotCancelledGurantee__c":false,"Is_DangerousChemicals__c":false,"SFDA_Status__c":"有効","Sales_Possibility__c":"○","Name":"CF-H170L:电子大肠内窥镜","Packing_list_manual__c":1,"Entend_gurantee_period_all__c":0,"Intra_Trade_Gurantee_RMB__c":0,"Intra_Trade_Service_RMB__c":0,"Maintenance_Price_Year__c":22000,"Repair_Contract_USD__c":2864,"Intra_Trade_Foreign_RMB__c":0,"NoDiscount_Foreign__c":0,"LastbuyProductFLG__c":false,"Category5__c":"170系列","Estimated_ConsumptionDueDate__c":"2023-10-01","Id":"01t10000002pc9SAAQ"}},"Id__c":"01t10000002pc9SAAQ","Quantity__c":1,"Subtotal__c":358440,"GuranteeType__c":"","ListPrice_Page":358440},"Maintenance_Price_Year":22000,"ListPrice_Page":358440,"lineNo":1,"latestInfo":{"Specifications":1,"SFDA_Status":"有効","Sales_Possibility":"○","ProductName":"CF-H170L:电子大肠内窥镜","ProductEntend_gurantee_period_all":0,"ProductCode":"N4479980","Maintenance_Price_Year":22000,"ListPrice":358440,"Is_DangerousChemicals":null,"Intra_Trade_Service":0,"Intra_Trade_Gurantee":0,"GuranteeType":"","Cost":87235,"CanNotCancelledGurantee":false},"Is_DangerousChemicals":false,"haveno_Register":false,"GuranteePrice":0,"Estimated_ConsumptionDueDate":"2023/10/01","Cost_Subtotal_c":87235,"Cost_c":87235,"changed_sfda":false,"changed_name":false,"changed_list":false,"changed_cost":false,"Category5":"170系列","CanNotCancelledGurantee":false,"Asset_Model":"CF-H170L","Quantity__c":1,"UnitPrice_Page__c":358440,"AgencySubtotal__c":186388.8,"AgencyUnitPrice__c":186388.8,"multiYearWarranty__c":false,"GuaranteePeriod__c":1,"NoDiscountTotal__c":0,"SFDA_Status__c":"有效","Name__c":"CF-H170L:电子大肠内窥镜","Subtotal__c":358440,"Name":"/01t10000002pc9SAAQ","EstimatedConsumptionDueDateclass":"slds-text-color_error slds-text-title_caps"},{"wrong_Register":false,"VenderName":"OSH","StorageStatus":null,"Specifications":1,"Sales_Possibility":null,"ProductGuranteePrice":32698,"pageObject":{"attributes":{"type":"QuoteLineItem"},"Asset_Model_No__c":"CF-H190I","SFDA_Status__c":"有効","Product_Sales_Possibility__c":"○","Name__c":"CF-H190I:电子结肠内窥镜","BSS_Category__c":"GI Imaging","QuoteId":"0Q0Hy000000BLvXKAW","PricebookEntryId":"01u1000000DLEuTAAX","Qty_Unit__c":"1","Cost__c":119033,"UnitPrice__c":394600,"ListPrice__c":363600,"Quantity":1,"TotalPrice__c":394600,"ProductCode__c":"N3802480","Product_Cost__c":119033,"Product_ListPrice__c":363600,"UnitPrice_Page__c":394600,"AgencyUnitPrice__c":220072,"AgencySubtotal__c":220072,"Present__c":false,"multiYearWarranty__c":true,"If_Cancel_Guarantee__c":false,"GuaranteePeriod__c":3,"ServicePrice__c":31000,"GuranteePrice__c":32698,"ProductEntend_gurantee_period_all__c":3,"ProductGuranteePrice__c":32698,"GuranteeType__c":"市场","warrantyType__c":"市场多年保修","productServicePrice__c":31000,"NoDiscountTotal__c":31000,"provistonPeriod__c":3,"Maintenance_Price_Year__c":19400,"Quote":{"attributes":{"type":"Quote","url":"/services/data/v58.0/sobjects/Quote/0Q0Hy000000BLvXKAW"},"OpportunityId":"006Hy00000A10ElIAJ","Id":"0Q0Hy000000BLvXKAW","Opportunity":{"attributes":{"type":"Opportunity","url":"/services/data/v58.0/sobjects/Opportunity/006Hy00000A10ElIAJ"},"Trade__c":"内貿","Id":"006Hy00000A10ElIAJ"}},"PricebookEntry":{"attributes":{"type":"PricebookEntry","url":"/services/data/v58.0/sobjects/PricebookEntry/01u1000000DLEuTAAX"},"Product2Id":"01t10000002pc9PAAQ","Id":"01u1000000DLEuTAAX","Product2":{"attributes":{"type":"Product2","url":"/services/data/v58.0/sobjects/Product2/01t10000002pc9PAAQ"},"VenderName__c":"OSH","CanNotCancelledGurantee__c":true,"Is_DangerousChemicals__c":false,"SFDA_Status__c":"有効","Sales_Possibility__c":"○","Name":"CF-H190I:电子结肠内窥镜","Packing_list_manual__c":1,"Entend_gurantee_period_all__c":3,"Intra_Trade_Gurantee_RMB__c":32698,"Intra_Trade_Service_RMB__c":31000,"GuranteeType__c":"市场","Maintenance_Price_Year__c":19400,"Repair_Contract_USD__c":2525,"Intra_Trade_Foreign_RMB__c":4045,"NoDiscount_Foreign__c":4035,"LastbuyProductFLG__c":false,"Category5__c":"190系列","Id":"01t10000002pc9PAAQ"}},"Id__c":"01t10000002pc9PAAQ","Quantity__c":1,"Subtotal__c":394600,"ListPrice_Page":363600},"Maintenance_Price_Year":19400,"ListPrice_Page":363600,"lineNo":2,"latestInfo":{"Specifications":1,"SFDA_Status":"有効","Sales_Possibility":"○","ProductName":"CF-H190I:电子结肠内窥镜","ProductEntend_gurantee_period_all":3,"ProductCode":"N3802480","Maintenance_Price_Year":19400,"ListPrice":363600,"Is_DangerousChemicals":null,"Intra_Trade_Service":31000,"Intra_Trade_Gurantee":32698,"GuranteeType":"市场","Cost":119033,"CanNotCancelledGurantee":true},"Is_DangerousChemicals":false,"haveno_Register":false,"GuranteePrice":32698,"Estimated_ConsumptionDueDate":"","Cost_Subtotal_c":119033,"Cost_c":119033,"changed_sfda":false,"changed_name":false,"changed_list":false,"changed_cost":false,"Category5":"190系列","CanNotCancelledGurantee":true,"Asset_Model":"CF-H190I","Quantity__c":1,"UnitPrice_Page__c":394600,"AgencySubtotal__c":220072,"AgencyUnitPrice__c":220072,"multiYearWarranty__c":true,"GuaranteePeriod__c":3,"warrantyType__c":"市场多年保修","NoDiscountTotal__c":31000,"SFDA_Status__c":"有效","Name__c":"CF-H190I:电子结肠内窥镜","Subtotal__c":394600,"Name":"/01t10000002pc9PAAQ","EstimatedConsumptionDueDateclass":""}]'; Boolean changedAfterPrintc = false; boolean enableSalesc = true; boolean newQuoteFlagc = true; String oppIdc = opp.Id; String oppInfoc = JSON.serialize(opp); boolean productStatusUpdatedc = false; String quoIdc = ''; String quoteGurantee_Periodc = null; String quotemultiYearWarrantyc = null; String selection_hpc = '杭州市丁桥医院'; Boolean quoteflg = true; prd1.Category5__c = '虚拟'; update prd1; lexNewQuoteEntryController.SaveQuote(activitiesCan,CheckItemCan,WinOrDecideAlertc,productStatusUpdatedc, oppInfoc,enableSalesc,quoc,oppIdc,quoIdc,newQuoteFlagc,changedAfterPrintc,quoteGurantee_Periodc, quotemultiYearWarrantyc,selection_hpc,SkipQuotefilgc,quoteflg,''); opp.StageName = '出荷'; opp.NotesApprovedNo__c = '8888'; opp.Opportunity_Category__c ='ET'; opp.RecordTypeId = recHanbaitenopp.Id; // Database.DMLOptions dmlOptions = new Database.DMLOptions(); // dmlOptions.DuplicateRuleHeader.AllowSave = true; // dmlOptions.DuplicateRuleHeader.RunAsCurrentUser = true; // dmlOptions.EmailHeader.triggerUserEmail = false; // Database.SaveResult updateResult; // Database.update(opp, dmlOptions); // updateResult = Database.update(opp, dmlOptions); update opp; Statu_Achievements__c Sac = new Statu_Achievements__c(name = 'zhucan_one', Opportunity__c = opp.id, DeliveryDate__c = Date.today(), ContractNO__c = 'ContractNO1', ContractAmount__c = 100,FirstApproveDate__c = Date.valueOf('2023-12-30')); insert Sac; List activities = (List)JSON.deserialize(activitiesCan,List.class); List ols = New List(); Quote quo = (Quote)JSON.deserialize(quoc,Quote.class); for (QELine s : activities) { OpportunityLineItem ol = new OpportunityLineItem(); ol.OpportunityId = opp.Id; ol.Id__c = s.pageObject.Id__c; ol.SFDA_Status__c = s.pageObject.SFDA_Status__c; ol.Name__c = s.pageObject.Name__c; ol.ListPrice__c = s.ListPrice_Page; ol.Quantity = s.pageObject.Quantity__c; ol.UnitPrice = 0; ol.UnitPrice__c = s.pageObject.UnitPrice_Page__c; ol.AgencyUnitPrice__c = s.pageObject.AgencyUnitPrice__c; ol.Present__c = s.pageObject.Present__c; ol.AgencySubtotal__c = s.pageObject.AgencySubtotal__c; ol.GuaranteePeriod__c = s.pageObject.GuaranteePeriod__c; ol.multiYearWarranty__c = s.pageObject.multiYearWarranty__c; ol.ServicePrice__c = s.pageObject.ServicePrice__c; ol.If_Cancel_Guarantee__c = s.pageObject.If_Cancel_Guarantee__c; ol.ProductEntend_gurantee_period_all__c = s.pageObject.ProductEntend_gurantee_period_all__c; ol.GuranteeType__c = s.pageObject.GuranteeType__c; ol.NoDiscountTotal__c = s.pageObject.NoDiscountTotal__c; ol.warrantyType__c = s.pageObject.warrantyType__c; ol.productServicePrice__c = s.pageObject.productServicePrice__c; ol.GuranteePrice__c = s.GuranteePrice; ol.ProductGuranteePrice__c = s.ProductGuranteePrice; ol.Maintenance_Price_Year__c = s.Maintenance_Price_Year; ol.provistonPeriod__c = s.pageObject.provistonPeriod__c; ol.Qty_Unit__c = s.pageObject.Qty_Unit__c; ol.Cost__c = s.pageObject.Cost__c; ol.BSS_Category__c = s.pageObject.BSS_Category__c; ol.CanNotCancelFlag__c = s.CanNotCancelledGurantee;//预测金额修改 fy ol.PricebookEntryId = entry.Id; ol.OCM_Sales_Forecast__c = 10000; ols.add(ol); } insert ols[0]; List opp1 = [SELECT id,Opportunity.OCM_man_province_no_dealer__c,Opportunity.Agency1__c FROM OpportunityLineItem where OpportunityId =:opp.Id]; System.debug('opp>>'+opp); for(OpportunityLineItem oppvalue : opp1){ System.debug('opp1value>>'+oppvalue); } Test.StartTest(); Database.executeBatch( new DealerConsumableManageBatch1(Date.today().addDays(-70),Date.today().addDays(50),false),10); Test.stopTest(); } public class QELinelatestInfo { public String ProductCode { get; set; } public String ProductName { get; set; } public String SFDA_Status { get; set; } public String Sales_Possibility { get; set; } public Decimal ListPrice { get; set; } public Decimal Cost { get; set; } public Integer Specifications {get; set;} public string GuranteeType {get; set;} public Decimal Intra_Trade_Gurantee {get; set;} public Decimal ProductEntend_gurantee_period_all {get; set;} public Decimal Intra_Trade_Service {get; set;} public Decimal Maintenance_Price_Year {get; set;} public Boolean CanNotCancelledGurantee {get; set;} public Boolean Is_DangerousChemicals {get; set;} } public class QELine { public Integer lineNo; public String Asset_Model; public String Sales_Possibility; public QuoteLineItem pageObject; public Decimal Cost_c; public Decimal Cost_Subtotal_c; public Decimal ListPrice_Page; public String StorageStatus; public Integer Specifications; public String VenderName; public Boolean CanNotCancelledGurantee; public Boolean Is_DangerousChemicals; public QELinelatestInfo latestInfo; public boolean changed_name; public boolean changed_sfda; public boolean changed_list; public boolean changed_cost; public boolean haveno_Register; public boolean wrong_Register; public String Estimated_ConsumptionDueDate; public Decimal GuranteePrice; public Decimal ProductGuranteePrice; public decimal Maintenance_Price_Year; public String Category5; } }