Skip to content

Commit e679c10

Browse files
committed
[IMP] cleanup
1 parent 7f10b04 commit e679c10

File tree

4 files changed

+6
-81
lines changed

4 files changed

+6
-81
lines changed

gmail/src/models/lead.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { postJsonRpc } from "../utils/http";
2-
import { isTrue } from "../utils/format";
32
import { URLS } from "../const";
43
import { getAccessToken } from "src/services/odoo_auth";
54
import { _t } from "../services/translation";
@@ -11,10 +10,6 @@ import { Partner } from "./partner";
1110
export class Lead {
1211
id: number;
1312
name: string;
14-
expectedRevenue: string;
15-
probability: number;
16-
recurringRevenue: string;
17-
recurringPlan: string;
1813
revenuesDescription: string;
1914

2015
/**
@@ -58,10 +53,6 @@ export class Lead {
5853
const lead = new Lead();
5954
lead.id = values.id;
6055
lead.name = values.name;
61-
lead.expectedRevenue = values.expectedRevenue;
62-
lead.probability = values.probability;
63-
lead.recurringRevenue = values.recurringRevenue;
64-
lead.recurringPlan = values.recurringPlan;
6556
lead.revenuesDescription = values.revenuesDescription;
6657
return lead;
6758
}
@@ -73,33 +64,7 @@ export class Lead {
7364
const lead = new Lead();
7465
lead.id = values.id;
7566
lead.name = values.name;
76-
lead.expectedRevenue = values.expected_revenue;
77-
lead.probability = values.probability;
78-
79-
if (isTrue(values.recurring_revenue) && isTrue(values.recurring_plan)) {
80-
lead.recurringRevenue = values.recurring_revenue;
81-
lead.recurringPlan = values.recurring_plan;
82-
}
83-
lead.revenuesDescription = this._revenuesDescription(values);
84-
67+
lead.revenuesDescription = values.revenues_description;
8568
return lead;
8669
}
87-
88-
static _revenuesDescription(values) {
89-
if (values.recurringRevenue) {
90-
return _t(
91-
"%(expected_revenue)s + %(recurring_revenue)s %(recurring_plan)s at %(probability)s%",
92-
{
93-
expected_revenue: values.expectedRevenue,
94-
probability: values.probability,
95-
recurring_revenue: values.recurringRevenue,
96-
recurring_plan: values.recurringPlan,
97-
},
98-
);
99-
}
100-
return _t("%(expected_revenue)s at %(probability)s%", {
101-
expected_revenue: values.expectedRevenue,
102-
probability: values.probability,
103-
});
104-
}
10570
}

gmail/src/models/state.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isTrue } from "../utils/format";
21
import { Email } from "./email";
32
import { Partner } from "./partner";
43
import { Project } from "./project";
@@ -9,7 +8,7 @@ import { getOdooServerUrl } from "src/services/app_properties";
98
/**
109
* Object which contains all data for the application.
1110
*
12-
* In App-Script, all event handler are function and not method. We can only pass string
11+
* In App-Script, all event handlers are function and not method. We can only pass string
1312
* as arguments. So this object is serialized, then given to the event handler and then
1413
* unserialize to retrieve the original object.
1514
*
@@ -91,7 +90,7 @@ export class State {
9190
*/
9291
static get accessToken() {
9392
const accessToken = getAccessToken();
94-
return isTrue(accessToken);
93+
return accessToken?.length && accessToken;
9594
}
9695

9796
static get isLogged(): boolean {
@@ -103,16 +102,7 @@ export class State {
103102
*/
104103
static get odooLoginUrl(): string {
105104
const loginUrl = getOdooAuthUrl();
106-
return isTrue(loginUrl);
107-
}
108-
/**
109-
* Return the shared secret between the add-on and IAP
110-
* (which is used to authenticate the add-on to IAP).
111-
*/
112-
static get odooSharedSecret(): string {
113-
const scriptProperties = PropertiesService.getScriptProperties();
114-
const sharedSecret = scriptProperties.getProperty("ODOO_SHARED_SECRET");
115-
return isTrue(sharedSecret);
105+
return loginUrl?.length && loginUrl;
116106
}
117107

118108
/**

gmail/src/services/translation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getAccessToken } from "./odoo_auth";
44
import { getOdooServerUrl } from "./app_properties";
55

66
/**
7-
* Object which fetchs the translations on the Odoo database, puts them in cache.
7+
* Object which fetch the translations on the Odoo database, puts them in cache.
88
*
99
* Done in a class and not in a simple function so we read only once the cache for all
1010
* translations.
@@ -32,7 +32,7 @@ export class Translate {
3232
);
3333

3434
if (this.translations) {
35-
// Put in the cacher for 6 hours (maximum cache life time)
35+
// Put in the cache for 6 hours (maximum cache lifetime)
3636
cache.put(cacheKey, JSON.stringify(this.translations), 21600);
3737
}
3838
}

gmail/src/utils/format.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,6 @@ export function formatUrl(url: string): string {
1313
return url.replace(/\/+$/, "");
1414
}
1515

16-
/**
17-
* Return the given string only if it's not null and not empty.
18-
*/
19-
export function isTrue(value: any): string {
20-
if (value && value.length) {
21-
return value;
22-
}
23-
}
24-
25-
/**
26-
* Return the first element of an array if the array is not null and not empty.
27-
*/
28-
export function first(value: any[]): any {
29-
if (value && value.length) {
30-
return value[0];
31-
}
32-
}
33-
34-
/**
35-
* Repeat the given string "n" times.
36-
*/
37-
export function repeat(str: string, n: number) {
38-
let result = "";
39-
while (n > 0) {
40-
result += str;
41-
n--;
42-
}
43-
return result;
44-
}
45-
4616
/**
4717
* Truncate the given text to not exceed the given length.
4818
*/

0 commit comments

Comments
 (0)