Skip to content

Commit 7f10b04

Browse files
committed
[IMP] company
1 parent 28aba8b commit 7f10b04

File tree

14 files changed

+60
-103
lines changed

14 files changed

+60
-103
lines changed

gmail/appsscript.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -104,33 +104,33 @@
104104
"https://db5c147150f5.ngrok-free.app/web/login",
105105
"https://db5c147150f5.ngrok-free.app/mail_plugin/auth",
106106
"https://db5c147150f5.ngrok-free.app/mail_plugin/auth/access_token",
107-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/get_translations",
108-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/activity/get",
109-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/activity/done",
110-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/activity/cancel",
111-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/activity/edit",
112-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/partner/get",
113-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/log_mail_content",
114-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/search_records/res.partner",
115-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/redirect_to_record/res.partner",
116-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/partner/create",
117-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/partner/enrich_and_create_company",
118-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/search_records/crm.lead",
119-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/redirect_to_record/crm.lead",
120-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/partner/enrich_and_update_company",
121-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/search_records/helpdesk.ticket",
122-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/redirect_to_record/helpdesk.ticket",
123-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/lead/create",
124-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/ticket/create",
125-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/search_records/project.task",
126-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/redirect_to_record/project.task",
127-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/search_records/project.project",
128-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/redirect_to_record/project.project",
129-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/project/create",
130-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/task/create",
131-
"https://90234751-master-all.runbot140.odoo.com/web/login",
132-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/auth",
133-
"https://90234751-master-all.runbot140.odoo.com/mail_plugin/auth/access_token"
107+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/get_translations",
108+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/activity/get",
109+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/activity/done",
110+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/activity/cancel",
111+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/activity/edit",
112+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/partner/get",
113+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/log_mail_content",
114+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/search_records/res.partner",
115+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/redirect_to_record/res.partner",
116+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/partner/create",
117+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/partner/enrich_and_create_company",
118+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/search_records/crm.lead",
119+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/redirect_to_record/crm.lead",
120+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/partner/enrich_and_update_company",
121+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/search_records/helpdesk.ticket",
122+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/redirect_to_record/helpdesk.ticket",
123+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/lead/create",
124+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/ticket/create",
125+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/search_records/project.task",
126+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/redirect_to_record/project.task",
127+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/search_records/project.project",
128+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/redirect_to_record/project.project",
129+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/project/create",
130+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/task/create",
131+
"https://90381416-master-all.runbot109.odoo.com/web/login",
132+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/auth",
133+
"https://90381416-master-all.runbot109.odoo.com/mail_plugin/auth/access_token"
134134
],
135135
"runtimeVersion": "V8"
136136
}

gmail/src/main.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,17 @@ function onGmailMessageOpen(event) {
3838
searchedPartners.push(Partner.fromJson({ name: contact.name, email: contact.email }));
3939
}
4040

41-
state = new State(null, false, currentEmail, [], searchedPartners, null, false);
41+
state = new State(null, false, currentEmail, searchedPartners, null, false);
4242
} else {
43-
const [partner, odooUserCompanies, canCreatePartner, canCreateProject, error] =
44-
Partner.getPartner(currentEmail.contacts[0].name, currentEmail.contacts[0].email);
43+
const [partner, canCreatePartner, canCreateProject, error] = Partner.getPartner(
44+
currentEmail.contacts[0].name,
45+
currentEmail.contacts[0].email,
46+
);
4547
if (error.code) {
4648
return buildLoginMainView();
4749
}
4850

49-
state = new State(
50-
partner,
51-
canCreatePartner,
52-
currentEmail,
53-
odooUserCompanies,
54-
null,
55-
null,
56-
canCreateProject,
57-
);
51+
state = new State(partner, canCreatePartner, currentEmail, null, null, canCreateProject);
5852
}
5953

6054
return [buildView(state)];

gmail/src/models/partner.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Partner {
2929
tasks: Task[];
3030
taskCount: number;
3131

32-
isWriteable: boolean;
32+
isWritable: boolean;
3333

3434
/**
3535
* Return the image to show in the interface for the current partner.
@@ -61,7 +61,7 @@ export class Partner {
6161
partner.ticketCount = values.ticketCount;
6262
partner.taskCount = values.taskCount;
6363

64-
partner.isWriteable = values.isWriteable;
64+
partner.isWritable = values.isWritable;
6565

6666
partner.leads = values.leads
6767
? values.leads.map((leadValues: any) => Lead.fromJson(leadValues))
@@ -94,7 +94,7 @@ export class Partner {
9494

9595
partner.phone = values.phone;
9696
partner.mobile = values.mobile;
97-
partner.isWriteable = values.can_write_on_partner;
97+
partner.isWritable = values.can_write_on_partner;
9898

9999
return partner;
100100
}
@@ -139,14 +139,14 @@ export class Partner {
139139
name: string,
140140
email: string,
141141
partnerId: number = null,
142-
): [Partner, number[], boolean, boolean, ErrorMessage] {
142+
): [Partner, boolean, boolean, ErrorMessage] {
143143
const odooServerUrl = getOdooServerUrl();
144144
const odooAccessToken = getAccessToken();
145145

146146
if (!odooServerUrl || !odooAccessToken) {
147147
const error = new ErrorMessage("http_error_odoo");
148148
const partner = Partner.fromJson({ name, email });
149-
return [partner, null, false, false, error];
149+
return [partner, false, false, error];
150150
}
151151

152152
const url =
@@ -161,13 +161,13 @@ export class Partner {
161161
if (response && response.error) {
162162
const error = new ErrorMessage("odoo", response.error);
163163
const partner = Partner.fromJson({ name, email });
164-
return [partner, null, false, false, error];
164+
return [partner, false, false, error];
165165
}
166166

167167
if (!response || !response.partner) {
168168
const error = new ErrorMessage("http_error_odoo");
169169
const partner = Partner.fromJson({ name, email });
170-
return [partner, null, false, false, error];
170+
return [partner, false, false, error];
171171
}
172172

173173
const error = new ErrorMessage();
@@ -200,11 +200,10 @@ export class Partner {
200200
}
201201
const canCreateProject = response.can_create_project !== false;
202202

203-
const odooUserCompanies = response.user_companies || null;
204203
// undefined must be considered as true
205204
const canCreatePartner = response.can_create_partner !== false;
206205

207-
return [partner, odooUserCompanies, canCreatePartner, canCreateProject, error];
206+
return [partner, canCreatePartner, canCreateProject, error];
208207
}
209208

210209
/**

gmail/src/models/state.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ export class State {
2323
canCreatePartner: boolean;
2424
// Opened email with headers
2525
email: Email;
26-
// ID list of the Odoo user companies
27-
odooUserCompanies: number[];
2826
// Searched partners in the search view
2927
searchedPartners: Partner[];
3028
// Searched projects in the search view
@@ -35,15 +33,13 @@ export class State {
3533
partner: Partner,
3634
canCreatePartner: boolean,
3735
email: Email,
38-
odooUserCompanies: number[],
3936
partners: Partner[],
4037
searchedProjects: Project[],
4138
canCreateProject: boolean,
4239
) {
4340
this.partner = partner;
4441
this.canCreatePartner = canCreatePartner;
4542
this.email = email;
46-
this.odooUserCompanies = odooUserCompanies;
4743
this.searchedPartners = partners;
4844
this.searchedProjects = searchedProjects;
4945
this.canCreateProject = canCreateProject;
@@ -70,7 +66,6 @@ export class State {
7066
const partner = Partner.fromJson(partnerValues);
7167
const email = Email.fromJson(emailValues);
7268
const error = ErrorMessage.fromJson(errorValues);
73-
const odooUserCompanies = values.odooUserCompanies;
7469
const searchedPartners = partnersValues
7570
? partnersValues.map((partnerValues: any) => Partner.fromJson(partnerValues))
7671
: null;
@@ -82,28 +77,12 @@ export class State {
8277
partner,
8378
canCreatePartner,
8479
email,
85-
odooUserCompanies,
8680
searchedPartners,
8781
searchedProjects,
8882
canCreateProject,
8983
);
9084
}
9185

92-
/**
93-
* Return the companies of the Odoo user as a GET parameter to add in a URL or an
94-
* empty string if the information is missing.
95-
*
96-
* e.g.
97-
* &cids=1,3,7
98-
*/
99-
get odooCompaniesParameter(): string {
100-
if (this.odooUserCompanies && this.odooUserCompanies.length) {
101-
const cids = this.odooUserCompanies.sort().join(",");
102-
return `&cids=${cids}`;
103-
}
104-
return "";
105-
}
106-
10786
/**
10887
* Cache / user properties management.
10988
*
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { getOdooServerUrl } from "./app_properties";
22

3-
export function getOdooRecordURL(model, record_id, cids = "") {
4-
return (
5-
getOdooServerUrl() +
6-
`/mail_plugin/redirect_to_record/${model}/?${cids}&record_id=${record_id}`
7-
);
3+
export function getOdooRecordURL(model, record_id) {
4+
return getOdooServerUrl() + `/mail_plugin/redirect_to_record/${model}/?record_id=${record_id}`;
85
}

gmail/src/views/activities.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export function buildActivitiesView(
8686
.setOpenLink(CardService.newOpenLink().setUrl(link));
8787
}
8888

89-
// TODO: company
9089
section.addWidget(
9190
createKeyValueWidget(
9291
activity.resName,

gmail/src/views/create_task.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ function onSelectProject(state: State, parameters: any) {
5656
state.partner.tasks.push(task);
5757
state.partner.taskCount += 1;
5858

59-
const cids = state.odooCompaniesParameter;
60-
const taskUrl = getOdooRecordURL("project.task", task.id, cids);
59+
const taskUrl = getOdooRecordURL("project.task", task.id);
6160
return pushToRoot(buildView(state));
6261
}
6362

gmail/src/views/leads.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ export function buildLeadsView(state: State, card: Card) {
6767

6868
const leadsSection = CardService.newCardSection();
6969

70-
const cids = state.odooCompaniesParameter;
71-
7270
const searchButton = CardService.newImageButton()
7371
.setAltText(_t("Search Opportunities"))
7472
.setIconUrl(UI_ICONS.search)
@@ -112,7 +110,7 @@ export function buildLeadsView(state: State, card: Card) {
112110
null,
113111
lead.revenuesDescription,
114112
leadButton,
115-
getOdooRecordURL("crm.lead", lead.id, state.odooCompaniesParameter),
113+
getOdooRecordURL("crm.lead", lead.id),
116114
),
117115
);
118116
}

gmail/src/views/partner.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export function buildPartnerView(state: State, card: Card) {
2323
.filter((x) => x)
2424
.map((x) => `<font color="#777777">${x}</font>`)
2525
.join("<br>");
26-
const cids = state.odooCompaniesParameter;
2726
if (!partner.id) {
2827
partnerContent = _t("New Person");
2928
}

gmail/src/views/partner_actions.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function onSavePartner(state: State) {
3131
const partner = Partner.savePartner(state.partner);
3232
if (partner) {
3333
state.partner = partner;
34-
state.partner.isWriteable = true;
34+
state.partner.isWritable = true;
3535
state.searchedPartners = null;
3636
return updateCard(buildView(state));
3737
}
@@ -50,11 +50,10 @@ function onSearchPartner(state: State) {
5050
export function onReloadPartner(state: State) {
5151
const values = Partner.getPartner(state.partner.name, state.partner.email, state.partner.id);
5252

53-
[state.partner, state.odooUserCompanies, state.canCreatePartner, state.canCreateProject] =
54-
values;
53+
[state.partner, state.canCreatePartner, state.canCreateProject] = values;
5554

56-
if (values[4].code) {
57-
return notify(values[4].message);
55+
if (values[3].code) {
56+
return notify(values[3].message);
5857
}
5958

6059
return updateCard(buildView(state));
@@ -82,16 +81,12 @@ export function buildPartnerActionView(state: State, partnerSection: CardSection
8281
.setBackgroundColor("#875a7b")
8382
.setOpenLink(
8483
CardService.newOpenLink().setUrl(
85-
getOdooRecordURL(
86-
"res.partner",
87-
state.partner.id,
88-
state.odooCompaniesParameter,
89-
),
84+
getOdooRecordURL("res.partner", state.partner.id),
9085
),
9186
),
9287
);
9388
}
94-
if (state.partner.id && !isEmailLogged && state.partner.isWriteable) {
89+
if (state.partner.id && !isEmailLogged && state.partner.isWritable) {
9590
actionButtonSet.addButton(
9691
CardService.newImageButton()
9792
.setAltText(_t("Log email"))

0 commit comments

Comments
 (0)