10000 [IMP] mail: remove the use of read in activity _to_store by phenix-factory · Pull Request #189598 · odoo/odoo · GitHub
[go: up one dir, main page]

Skip to content

[IMP] mail: remove the use of read in activity _to_store #189598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions addons/calendar/models/mail_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from odoo import models, fields, tools, _
from odoo.tools import is_html_empty
from odoo.addons.mail.tools.discuss import Store


class MailActivity(models.Model):
Expand Down Expand Up @@ -48,3 +49,6 @@ def unlink_w_meeting(self):
res = self.unlink()
events.unlink()
return res

def _to_store_defaults(self):
return super()._to_store_defaults() + [Store.One("calendar_event_id", [])]
5 changes: 5 additions & 0 deletions addons/calendar/static/src/activity/@types/models.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "models" {
interface Activity {
calendar_event_id: Number
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Activity } from "@mail/core/web/activity_model";
import { Activity } from "@mail/core/common/activity_model";
import { assignIn } from "@mail/utils/common/misc";
import { patch } from "@web/core/utils/patch";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ export class MailActivity extends mailModels.MailActivity {
this.env["calendar.event"].unlink(eventIds);
return res;
}

/** @param {number[]} ids */
_to_store(ids, store) {
super._to_store(...arguments);
for (const activity of this.browse(ids)) {
if (activity.calendar_event_id) {
store.add(this.browse(activity.id), {
calendar_event_id: activity.calendar_event_id,
});
}
}
}
}
22 changes: 14 additions & 8 deletions addons/mail/models/mail_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,20 @@ def activity_format(self):

def _to_store_defaults(self):
return [
"all",
"activity_category",
"activity_type_id",
"can_write",
"chaining_type",
"create_date",
"create_uid",
"date_deadline",
"date_done",
"icon",
"note",
"res_id",
"res_model",
"state",
"summary",
Store.Many("attachment_ids", ["name"]),
Store.Attr(
"mail_template_ids",
Expand All @@ -597,13 +610,6 @@ def _to_store_defaults(self):
Store.One("persona", value=lambda activity: activity.user_id.partner_id),
]

def _to_store(self, store: Store, fields):
if "all" in fields:
fields.remove("all")
for activity in self:
store.add(activity, activity.read()[0])
store.add_records_fields(self, fields)

@api.readonly
@api.model
def get_activity_data(self, res_model, domain, limit=None, offset=0, fetch_done=False):
Expand Down
3 changes: 3 additions & 0 deletions addons/mail/static/src/core/common/@types/models.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare module "models" {
import { Activity as ActivityClass } from "@mail/core/common/activity_model";
import { Attachment as AttachmentClass } from "@mail/core/common/attachment_model";
import { CannedResponse as CannedResponseClass } from "@mail/core/common/canned_response_model";
import { ChatHub as ChatHubClass } from "@mail/core/common/chat_hub_model";
Expand All @@ -19,6 +20,7 @@ declare module "models" {
import { Volume as VolumeClass } from "@mail/core/common/volume_model";

// define interfaces for jsdoc, including with patches
export interface Activity extends ActivityClass {}
export interface Attachment extends AttachmentClass {}
export interface CannedResponse extends CannedResponseClass {}
export interface ChatHub extends ChatHubClass {}
Expand All @@ -45,6 +47,7 @@ declare module "models" {
"Composer": Composer,
"Failure": Failure,
"ir.attachment": Attachment,
"mail.activity": Activity,
"mail.canned.response": CannedResponse,
"mail.followers": Follower,
"mail.link.preview": LinkPreview,
Expand Down
108 changes: 108 additions & 0 deletions addons/mail/static/src/core/common/activity_model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { Record } from "@mail/core/common/record";
import { assignDefined } from "@mail/utils/common/misc";

export class Activity extends Record {
static name = "mail.activity";
static id = "id";
/** @type {Object.<number, import("models").Activity>} */
static records = {};
/** @returns {import("models").Activity} */
static get(data) {
return super.get(data);
}
/**
* @template T
* @param {T} data
* @param {Object} [param1]
* @param {boolean} param1.broadcast
* @returns {T extends any[] ? import("models").Activity[] : import("models").Activity}
*/
static insert(data, { broadcast = true } = {}) {
return super.insert(...arguments);
}
/**
* @param {Object} data
* @param {Object} [param1]
* @param {boolean} param1.broadcast
* @returns {import("models").Activity}
*/
static _insert(data, { broadcast = true } = {}) {
/** @type {import("models").Activity} */
const activity = this.preinsert(data);
assignDefined(activity, data);
if (broadcast) {
this.store.activityBroadcastChannel?.postMessage({
type: "INSERT",
payload: activity.serialize(),
});
}
return activity;
}

/** @type {number} */
id;
/** @type {boolean} */
active;
/** @type {string} */
activity_category;
/** @type {[number, string]} */
activity_type_id;
/** @type {string|false} */
activity_decoration;
/** @type {Object[]} */
attachment_ids;
/** @type {boolean} */
can_write;
/** @type {'suggest'|'trigger'} */
chaining_type;
/** @type {luxon.DateTime} */
create_date = Record.attr(undefined, { type: "datetime" });
/** @type {[number, string]} */
create_uid;
/** @type {luxon.DateTime} */
date_deadline = Record.attr(undefined, { type: "date" });
/** @type {luxon.DateTime} */
date_done = Record.attr(undefined, { type: "date" });
/** @type {string} */
display_name;
/** @type {boolean} */
has_recommended_activities;
/** @type {string} */
feedback;
/** @type {string} */
icon = "fa-tasks";
/** @type {Object[]} */
mail_template_ids;
note = Record.attr("", { html: true });
persona = Record.one("Persona");
/** @type {number|false} */
previous_activity_type_id;
/** @type {number|false} */
recommended_activity_type_id;
/** @type {string} */
res_model;
/** @type {[number, string]} */
res_model_id;
/** @type {number} */
res_id;
/** @type {string} */
res_name;
/** @type {number|false} */
request_partner_id;
/** @type {'overdue'|'planned'|'today'} */
state;
/** @type {string} */
summary;
/** @type {[number, string]} */
user_id;
/** @type {string} */
write_date;
/** @type {[number, string]} */
write_uid;

serialize() {
return JSON.parse(JSON.stringify(this.toData()));
}
}

Activity.register();
2 changes: 1 addition & 1 deletion addons/mail/static/src/core/common/store_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Store extends BaseStore {
Failure;
/** @type {typeof import("@mail/core/common/attachment_model").Attachment} */
["ir.attachment"];
/** @type {typeof import("@mail/core/web/activity_model").Activity} */
/** @type {typeof import("@mail/core/common/activity_model").Activity} */
["mail.activity"];
/** @type {typeof import("@mail/core/common/canned_response_model").CannedResponse} */
["mail.canned.response"];
Expand Down
7 changes: 0 additions & 7 deletions addons/mail/static/src/core/web/@types/models.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
declare module "models" {
import { Activity as ActivityClass } from "@mail/core/web/activity_model";

export interface Activity extends ActivityClass {}
export interface Discuss {
inbox: Thread,
stared: Thread,
Expand All @@ -15,8 +12,4 @@ declare module "models" {
export interface Thread {
recipients: Follower[],
}

export interface Models {
"mail.activity": Activity,
}
}
Loading
0