Browse Source

Promise error catching + UI + Better settings handle

Ghislain Loaec 2 years ago
parent
commit
e1d6ebb6c9

+ 15
- 2
src/pages/new-purchase-order-line/new-purchase-order-line.ts View File

@@ -33,6 +33,7 @@ export class NewPurchaseOrderLinePage {
33 33
   } = {
34 34
     discount: 0,
35 35
     price_subtotal: 0,
36
+    taxes_id: [],
36 37
     _taxes: []
37 38
   }
38 39
 
@@ -111,7 +112,7 @@ export class NewPurchaseOrderLinePage {
111 112
         }),
112 113
         this.timeout
113 114
       );
114
-    });
115
+    }).catch(this.showError);
115 116
   }
116 117
 
117 118
   createOrderLine() {
@@ -146,7 +147,7 @@ export class NewPurchaseOrderLinePage {
146 147
         this.subTotal();
147 148
         this.loadingPopup.dismiss();
148 149
       });
149
-    });
150
+    }).catch(this.showError);
150 151
   }
151 152
 
152 153
   subTotal() {
@@ -185,6 +186,9 @@ export class NewPurchaseOrderLinePage {
185 186
                 this.subTotal();
186 187
               }
187 188
               this.loadingPopup.dismiss();
189
+            }).catch((error) => {
190
+              this.loadingPopup.dismiss();
191
+              this.showError(error);
188 192
             });
189 193
           }
190 194
         }
@@ -193,4 +197,13 @@ export class NewPurchaseOrderLinePage {
193 197
     prompt.present();
194 198
   }
195 199
 
200
+  showError(error: string) {
201
+    let toast = this.toastCtrl.create({
202
+      message: `Error: ${error}`,
203
+      duration: 2000//,
204
+      //position: "top"
205
+    });
206
+    toast.present();
207
+  }
208
+
196 209
 }

+ 14
- 1
src/pages/new-purchase-order/new-purchase-order.ts View File

@@ -77,6 +77,9 @@ export class NewPurchaseOrderPage {
77 77
       ]).then(() => {
78 78
         this.loadingPopup.dismiss()
79 79
       });
80
+    }).catch((error) => {
81
+      this.loadingPopup.dismiss();
82
+      this.showError(error);
80 83
     });
81 84
   }
82 85
 
@@ -120,8 +123,9 @@ export class NewPurchaseOrderPage {
120 123
       this.timeout
121 124
     ).then(() => {
122 125
       this.loadingPopup.dismiss();
123
-    }).catch(() => {
126
+    }).catch((error) => {
124 127
       this.loadingPopup.dismiss();
128
+      this.showError(error);
125 129
     });
126 130
 
127 131
     //pickingOut[0].move_lines.map((moveLine: any) => {
@@ -207,4 +211,13 @@ export class NewPurchaseOrderPage {
207 211
     });
208 212
   }
209 213
 
214
+  showError(error: string) {
215
+    let toast = this.toastCtrl.create({
216
+      message: `Error: ${error}`,
217
+      duration: 2000//,
218
+      //position: "top"
219
+    });
220
+    toast.present();
221
+  }
222
+
210 223
 }

+ 14
- 2
src/pages/new-sale-order-line/new-sale-order-line.ts View File

@@ -33,6 +33,7 @@ export class NewSaleOrderLinePage {
33 33
   } = {
34 34
     discount: 0,
35 35
     price_subtotal: 0,
36
+    tax_id: [],
36 37
     _taxes: []
37 38
   }
38 39
 
@@ -111,7 +112,7 @@ export class NewSaleOrderLinePage {
111 112
         }),
112 113
         this.timeout
113 114
       );
114
-    });
115
+    }).catch(this.showError);
115 116
   }
116 117
 
117 118
   createOrderLine() {
@@ -147,7 +148,7 @@ export class NewSaleOrderLinePage {
147 148
         this.subTotal();
148 149
         this.loadingPopup.dismiss();
149 150
       });
150
-    });
151
+    }).catch(this.showError);
151 152
   }
152 153
 
153 154
   subTotal() {
@@ -189,6 +190,9 @@ export class NewSaleOrderLinePage {
189 190
                 this.subTotal();
190 191
               }
191 192
               this.loadingPopup.dismiss();
193
+            }).catch((error) => {
194
+              this.loadingPopup.dismiss();
195
+              this.showError(error);
192 196
             });
193 197
           }
194 198
         }
@@ -197,4 +201,12 @@ export class NewSaleOrderLinePage {
197 201
     prompt.present();
198 202
   }
199 203
 
204
+  showError(error: string) {
205
+    let toast = this.toastCtrl.create({
206
+      message: `Error: ${error}`,
207
+      duration: 2000//,
208
+      //position: "top"
209
+    });
210
+    toast.present();
211
+  }
200 212
 }

+ 14
- 1
src/pages/new-sale-order/new-sale-order.ts View File

@@ -69,6 +69,9 @@ export class NewSaleOrderPage {
69 69
       ]).then(() => {
70 70
         this.loadingPopup.dismiss()
71 71
       });
72
+    }).catch((error) => {
73
+      this.loadingPopup.dismiss();
74
+      this.showError(error);
72 75
     });
73 76
   }
74 77
 
@@ -107,8 +110,9 @@ export class NewSaleOrderPage {
107 110
       this.timeout
108 111
     ).then(() => {
109 112
       this.loadingPopup.dismiss();
110
-    }).catch(() => {
113
+    }).catch((error) => {
111 114
       this.loadingPopup.dismiss();
115
+      this.showError(error);
112 116
     });
113 117
 
114 118
     //pickingOut[0].move_lines.map((moveLine: any) => {
@@ -192,4 +196,13 @@ export class NewSaleOrderPage {
192 196
     });
193 197
   }
194 198
 
199
+  showError(error: string) {
200
+    let toast = this.toastCtrl.create({
201
+      message: `Error: ${error}`,
202
+      duration: 2000//,
203
+      //position: "top"
204
+    });
205
+    toast.present();
206
+  }
207
+
195 208
 }

+ 27
- 31
src/pages/picking-detail/picking-detail.html View File

@@ -14,39 +14,35 @@
14 14
     <ion-list-header>
15 15
       Produits
16 16
     </ion-list-header>
17
-    <ion-item-sliding *ngFor="let line of picking._lines">
18
-      <ion-item>
19
-        <ion-icon name="barcode" item-left></ion-icon>
20
-        <h3>{{line._name}}</h3>
21
-        <p [hidden]="!line._code">
22
-          Ref: {{ line._code}}
17
+    <ion-item *ngFor="let line of picking._lines">
18
+      <ion-icon name="barcode" item-left></ion-icon>
19
+      <h3>{{line._name}}</h3>
20
+      <p [hidden]="!line._code">
21
+        Ref: {{ line._code}}
22
+      </p>
23
+      <p [hidden]="line._lots.length <= 0">
24
+        Lot: {{ line._lots.join(' / ') }}
25
+      </p>
26
+      <ion-note item-right>
27
+        <p>
28
+          <ion-badge text-right color="light">
29
+            {{ line._qty }}
30
+            {{ line.product_uom[1] }}
31
+          </ion-badge>
23 32
         </p>
24
-        <p [hidden]="line._lots.length <= 0">
25
-          Lot: {{ line._lots.join(' / ') }}
33
+        <p text-right>
34
+          PU: {{ line.price_unit | currency:'EUR':true }}
26 35
         </p>
27
-        <ion-note item-right>
28
-          <p>
29
-            <ion-badge text-right color="light">
30
-              {{ line._qty }}
31
-              {{ line.product_uom[1] }}
32
-            </ion-badge>
33
-          </p>
34
-          <p text-right>
35
-            PU: {{ line.price_unit | currency:'EUR':true }}
36
-          </p>
37
-          <p>
38
-            <ion-badge text-right color="odoo" [hidden]="line._discount == 0">
39
-              -{{ line._discount }}%
40
-            </ion-badge>
41
-            <ion-note text-right color="odoo">
42
-              {{ line.price_subtotal | currency:'EUR':true }}
43
-            </ion-note>
44
-          </p>
45
-        </ion-note>
46
-      </ion-item>
47
-      <ion-item-options side="right">
48
-      </ion-item-options>
49
-    </ion-item-sliding>
36
+        <p>
37
+          <ion-badge text-right color="odoo" [hidden]="line._discount == 0">
38
+            -{{ line._discount }}%
39
+          </ion-badge>
40
+          <ion-note text-right color="odoo">
41
+            {{ line.price_subtotal | currency:'EUR':true }}
42
+          </ion-note>
43
+        </p>
44
+      </ion-note>
45
+    </ion-item>
50 46
     <ion-item text-right>
51 47
       Total HT :
52 48
       <ion-note color="odoo">{{ picking._order.amount_untaxed | currency:'EUR':true }}</ion-note>

+ 13
- 4
src/pages/picking-detail/picking-detail.ts View File

@@ -50,8 +50,6 @@ export class PickingDetailPage {
50 50
       return this.fetchData();
51 51
     }).then(() => {
52 52
       this.loadingPopup.dismiss();
53
-    }).catch(() => {
54
-      this.loadingPopup.dismiss();
55 53
     });
56 54
   }
57 55
 
@@ -63,7 +61,6 @@ export class PickingDetailPage {
63 61
         //position: "top"
64 62
       });
65 63
       toast.present();
66
-      throw 'Timeoout';
67 64
     })]);
68 65
   }
69 66
 
@@ -83,7 +80,19 @@ export class PickingDetailPage {
83 80
         console.log('picking', picking);
84 81
       }),
85 82
       this.timeout
86
-    );
83
+    ).catch((error) => {
84
+      this.showError(error);
85
+    });
86
+  }
87
+
88
+  showError(error: string) {
89
+    clearTimeout(this._timeout);
90
+    let toast = this.toastCtrl.create({
91
+      message: `Error: ${error}`,
92
+      duration: 2000//,
93
+      //position: "top"
94
+    });
95
+    toast.present();
87 96
   }
88 97
 
89 98
 }

+ 2
- 14
src/pages/picking-list/picking-list.html View File

@@ -29,9 +29,8 @@
29 29
         </ion-label>
30 30
       </ion-item-divider>
31 31
 
32
-      <ion-item-sliding *ngFor="let picking of pickingGroup.pickings" #slidingItem [hidden]="false">
33 32
 
34
-        <button ion-item (click)="showPicking(picking)">
33
+        <ion-item *ngFor="let picking of pickingGroup.pickings" (click)="showPicking(picking)">
35 34
           <ion-icon name="{{ getIcon() }}" item-left color="{{ getColor(picking) }}"></ion-icon>
36 35
           <h3>{{picking.name}} ({{picking.origin}})</h3>
37 36
           <p>
@@ -40,18 +39,7 @@
40 39
           <ion-badge item-right color="light">
41 40
             {{ picking.move_lines.length }} produit{{ picking.move_lines.length > 1 ? 's' : '' }}
42 41
           </ion-badge>
43
-        </button>
44
-
45
-        <ion-item-options>
46
-          <!--button ion-button color="favorite" (click)="addFavorite(slidingItem, picking)" *ngIf="segment === 'all'">
47
-            Favorite
48
-          </button>
49
-          <button ion-button color="danger" (click)="removeFavorite(slidingItem, picking, 'Remove Favorite')" *ngIf="segment === 'favorites'">
50
-            Remove
51
-          </button-->
52
-        </ion-item-options>
53
-
54
-      </ion-item-sliding>
42
+        </ion-item>
55 43
 
56 44
     </ion-item-group>
57 45
 

+ 14
- 4
src/pages/picking-list/picking-list.ts View File

@@ -51,8 +51,6 @@ export class PickingListPage {
51 51
       return this.fetchData();
52 52
     }).then(() => {
53 53
       this.loadingPopup.dismiss();
54
-    }).catch(() => {
55
-      this.loadingPopup.dismiss();
56 54
     });
57 55
   }
58 56
 
@@ -72,7 +70,7 @@ export class PickingListPage {
72 70
         //position: "top"
73 71
       });
74 72
       toast.present();
75
-      throw 'Timeoout';
73
+      //throw 'Timeout';
76 74
     })]);
77 75
   }
78 76
 
@@ -113,7 +111,9 @@ export class PickingListPage {
113 111
         clearTimeout(this._timeout);
114 112
       }),
115 113
       this.timeout
116
-    );
114
+    ).catch((error: string) => {
115
+      this.showError(error);
116
+    });
117 117
   }
118 118
 
119 119
   doRefresh(refresher: any) {
@@ -140,4 +140,14 @@ export class PickingListPage {
140 140
     }
141 141
   }
142 142
 
143
+  showError(error: string) {
144
+    clearTimeout(this._timeout);
145
+    let toast = this.toastCtrl.create({
146
+      message: `Error: ${error}`,
147
+      duration: 2000//,
148
+      //position: "top"
149
+    });
150
+    toast.present();
151
+  }
152
+
143 153
 }

+ 16
- 14
src/pages/settings/settings.ts View File

@@ -45,20 +45,22 @@ export class SettingsPage {
45 45
     this.submitted = true;
46 46
 
47 47
     if (form.valid) {
48
-      this.settingsData.setApiUrl(this.settings.apiUrl);
49
-      this.settingsData.setUsername(this.settings.username);
50
-      this.settingsData.setPassword(this.settings.password);
51
-      this.settingsData.setDatabase(this.settings.database);
52
-      this.settingsData.setTimeout(this.settings.timeout);
53
-      this.settingsData.setOrderLimit(this.settings.orderLimit);
54
-      this.odooService.load().then(() => {
55
-        let toast = this.toastCtrl.create({
56
-          message: "Configuration enregistrée",
57
-          duration: 2000
58
-        });
59
-        toast.present();
60
-      }, this.onError.bind(this));
61
-      //this.navCtrl.push(TabsPage);
48
+      Promise.all([
49
+        this.settingsData.setApiUrl(this.settings.apiUrl),
50
+        this.settingsData.setUsername(this.settings.username),
51
+        this.settingsData.setPassword(this.settings.password),
52
+        this.settingsData.setDatabase(this.settings.database),
53
+        this.settingsData.setTimeout(this.settings.timeout),
54
+        this.settingsData.setOrderLimit(this.settings.orderLimit)
55
+      ]).then(() => {
56
+        return this.odooService.load().then(() => {
57
+          let toast = this.toastCtrl.create({
58
+            message: "Configuration enregistrée",
59
+            duration: 2000
60
+          });
61
+          toast.present();
62
+        }, this.onError.bind(this));
63
+      });
62 64
     }
63 65
   }
64 66
 }

+ 2
- 1
src/providers/odoo-service.ts View File

@@ -347,6 +347,7 @@ export class OdooService {
347 347
         product_uos: null,
348 348
         price_unit: 0,
349 349
         tax_id: [],
350
+        taxes_id: [],
350 351
         discount: 0,
351 352
         price_subtotal: 0,
352 353
         date_planned: new Date()
@@ -869,7 +870,7 @@ export class OdooService {
869 870
         } else {
870 871
           resolve(orderLine);
871 872
         }
872
-      });
873
+      }).catch(reject);
873 874
     });
874 875
 
875 876
   }