高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@isTest
private class ConsumableOrderDetail1TriggerTest {
    static testMethod void testInsert() {
        Consumable_order__c co = new Consumable_order__c();
        co.Name = 'testorderSum';
        insert co;
 
        //插入明细1
        Consumable_orderdetails__c cod1 = new Consumable_orderdetails__c();
        cod1.Name = 'testorderdetail1';
        cod1.Consumable_order__c = co.Id;
        //cod1.Sum_of_money__c=10000;
        cod1.Dealer_Custom_Price__c=1000;
        cod1.Consumable_count__c=10;
        //cod1.Invoice_Cost_RMB__c=1000;
        //Invoice_Cost_RMB__c=Shipment_amount__c - RrturnPro_Cost_RMB__c - InvoicedProCost_RMB__c < 0 , 0, Shipment_amount__c - RrturnPro_Cost_RMB__c - InvoicedProCost_RMB__c
        cod1.Invoiced_Procount__c=5;
        cod1.InvoicedProCost_RMB__c=5000;
        //cod1.Shipment_amount__c=8000;
        //Shipment_Count__c * Delivery_List_RMB__c
        cod1.Shipment_Count__c =8;
        cod1.Delivery_List_RMB__c=1000;
        //cod1.RrturnPro_Cost_RMB__c=2000;
        //ReturnGoods_unitPrice__c * RrturnPro_count__c
        //cod1.ReturnGoods_unitPrice__c=1000;
        cod1.RrturnPro_count__c=2;
 
        upsert cod1;
 
        Consumable_order__c order1 = [select id,Total_amount__c,Total_num__c,InvoiceNotPro_total_amount__c,Total_Invoiced_Procount__c,InvoicedPro_total_amount__c,Shipment_total_amount__c, RrturnPro_total_count__c,RrturnPro_total_amount__c,Invoice_total_amount__c from Consumable_order__c where Id = :co.Id];
 
        //System.assertEquals(10000,order1.Total_amount__c);
        //System.assertEquals(10,order1.Total_num__c);
        //System.assertEquals(1000,order1.InvoiceNotPro_total_amount__c);
        //System.assertEquals(5,order1.Total_Invoiced_Procount__c);
        //System.assertEquals(5000,order1.InvoicedPro_total_amount__c);
        //System.assertEquals(8000,order1.Shipment_total_amount__c);
        //System.assertEquals(2,order1.RrturnPro_total_count__c);
        //System.assertEquals(2000,order1.RrturnPro_total_amount__c);
        //System.assertEquals(5000,order1.Invoice_total_amount__c);
 
        //插入明细2
        Consumable_orderdetails__c cod2 = new Consumable_orderdetails__c();
        cod2.Name = 'testorderdetail2';
        cod2.Consumable_order__c = co.Id;
        //cod1.Sum_of_money__c=10000;
        cod2.Dealer_Custom_Price__c=1000;
        cod2.Consumable_count__c=10;
        //cod1.Invoice_Cost_RMB__c=1000;
        //Invoice_Cost_RMB__c=Shipment_amount__c - RrturnPro_Cost_RMB__c - InvoicedProCost_RMB__c < 0 , 0, Shipment_amount__c - RrturnPro_Cost_RMB__c - InvoicedProCost_RMB__c
        cod2.Invoiced_Procount__c=5;
        cod2.InvoicedProCost_RMB__c=5000;
        //cod1.Shipment_amount__c=8000;
        //Shipment_Count__c * Delivery_List_RMB__c
        cod2.Shipment_Count__c =8;
        cod2.Delivery_List_RMB__c=1000;
        //cod1.RrturnPro_Cost_RMB__c=2000;
        //ReturnGoods_unitPrice__c * RrturnPro_count__c
        //cod2.ReturnGoods_unitPrice__c=1000;
        cod2.RrturnPro_count__c=2;
        upsert cod2;
 
        Consumable_order__c order2 = [select id,Total_amount__c,Total_num__c,InvoiceNotPro_total_amount__c,Total_Invoiced_Procount__c,InvoicedPro_total_amount__c,Shipment_total_amount__c, RrturnPro_total_count__c,RrturnPro_total_amount__c,Invoice_total_amount__c from Consumable_order__c where Id = :co.Id];
 
        //System.assertEquals(20000,order2.Total_amount__c);
        //System.assertEquals(20,order2.Total_num__c);
        //System.assertEquals(2000,order2.InvoiceNotPro_total_amount__c);
        //System.assertEquals(10,order2.Total_Invoiced_Procount__c);
        //System.assertEquals(10000,order2.InvoicedPro_total_amount__c);
        //System.assertEquals(16000,order2.Shipment_total_amount__c);
        //System.assertEquals(4,order2.RrturnPro_total_count__c);
        //System.assertEquals(4000,order2.RrturnPro_total_amount__c);
        //System.assertEquals(10000,order2.Invoice_total_amount__c);
 
        //变更明细2
        Consumable_orderdetails__c cod3 = new Consumable_orderdetails__c();
        cod3.Name = 'testorderdetail2';
        cod3.Id=cod2.id;
        //cod1.Sum_of_money__c=10000;
        cod3.Dealer_Custom_Price__c=1000;
        cod3.Consumable_count__c=20;
        //cod1.Invoice_Cost_RMB__c=1000;
        //Invoice_Cost_RMB__c=Shipment_amount__c - RrturnPro_Cost_RMB__c - InvoicedProCost_RMB__c < 0 , 0, Shipment_amount__c - RrturnPro_Cost_RMB__c - InvoicedProCost_RMB__c
        cod3.Invoiced_Procount__c=5;
        cod3.InvoicedProCost_RMB__c=5000;
        //cod1.Shipment_amount__c=8000;
        //Shipment_Count__c * Delivery_List_RMB__c
        cod3.Shipment_Count__c =8;
        cod3.Delivery_List_RMB__c=1000;
        //cod1.RrturnPro_Cost_RMB__c=2000;
        //ReturnGoods_unitPrice__c * RrturnPro_count__c
        //cod3.ReturnGoods_unitPrice__c=1000;
        cod3.RrturnPro_count__c=2;
        upsert cod3;
 
        Consumable_order__c order3 = [select id,Total_amount__c,Total_num__c,InvoiceNotPro_total_amount__c,Total_Invoiced_Procount__c,InvoicedPro_total_amount__c,Shipment_total_amount__c, RrturnPro_total_count__c,RrturnPro_total_amount__c,Invoice_total_amount__c from Consumable_order__c where Id = :co.Id];
 
        //System.assertEquals(30000,order3.Total_amount__c);
        //System.assertEquals(30,order3.Total_num__c);
        //System.assertEquals(2000,order3.InvoiceNotPro_total_amount__c);
        //System.assertEquals(10,order3.Total_Invoiced_Procount__c);
        //System.assertEquals(10000,order3.InvoicedPro_total_amount__c);
        //System.assertEquals(16000,order3.Shipment_total_amount__c);
        //System.assertEquals(4,order3.RrturnPro_total_count__c);
        //System.assertEquals(4000,order3.RrturnPro_total_amount__c);
        //System.assertEquals(10000,order3.Invoice_total_amount__c);
 
        //删除明细2
        Consumable_orderdetails__c cod4 = new Consumable_orderdetails__c();
        cod4.Id=cod2.Id;
        delete cod4;
 
        Consumable_order__c order4 = [select id,Total_amount__c,Total_num__c,InvoiceNotPro_total_amount__c,Total_Invoiced_Procount__c,InvoicedPro_total_amount__c,Shipment_total_amount__c, RrturnPro_total_count__c,RrturnPro_total_amount__c,Invoice_total_amount__c from Consumable_order__c where Id = :co.Id];
 
        //System.assertEquals(10000,order1.Total_amount__c);
        //System.assertEquals(10,order1.Total_num__c);
        //System.assertEquals(1000,order1.InvoiceNotPro_total_amount__c);
        //System.assertEquals(5,order1.Total_Invoiced_Procount__c);
        //System.assertEquals(5000,order1.InvoicedPro_total_amount__c);
        //System.assertEquals(8000,order1.Shipment_total_amount__c);
        //System.assertEquals(2,order1.RrturnPro_total_count__c);
        //System.assertEquals(2000,order1.RrturnPro_total_amount__c);
        //System.assertEquals(5000,order1.Invoice_total_amount__c);
 
    }
}