Friday, September 22, 2023
7 changes · master
Code cleanup and technical improvements
The Discuss messaging system now uses clearer model relationships to manage messages, threads, attachments, live chat, and related records. This is an internal improvement that reduces complexity, helps prevent data cleanup bugs when records are deleted, and should make future messaging and live chat changes faster and safer to build.
Original PR description
Before these commits, discuss relations were difficult to maintain: relations are named by local ids and ids of record, and we must juggle all the time between these local ids and the records. Also…
Before these commits, discuss relations were difficult to maintain: relations are named by local ids and ids of record, and we must juggle all the time between these local ids and the records. Also when the record is deleted, we must add lots of code to properly delete all relations on this record. Some dedicated services that manage relations on models had complicated data-structures, such as `messageIdsByChannelId` in `message_pin` service for something equivalent to `channel.pinnedMessages`.
This commit improves the readability and maintainability of relations in discuss models:
Can define a "one" relation on a discuss model:
```js
class Message extends Record {
author = Record.one("Persona");
}
```
Relational fields can be used to uniquely identify records:
```js
class ChatWindow extends Record {
static id = "thread";
thread = Record.one("Thread");
}
```
There's also support for many relations:
```js
class Thread extends Record {
messages = Record.many("Messages");
}
// ...
thread.messages = messages;
thread.messages.push(message);
thread.messages[0];
thread.messages.filter((msg) => !msg.isEmpty);
```
And support for patching models to add relations:
```js
patch(Thread.prototype, {
setup() {
this.pinnedMessages = Record.many("Messages");
},
});
```
Typing of models and their patches is managed in a `@types/models.d.ts` file:
```ts
declare module "models" {
export interface Thread {
pinnedMessages: Message[],
}
}
```
When a record is deleted, it is automatically removed to all its inverse relations:
```js
thread.messages = [message];
message.delete();
thread.messages; // []
```
Introducing relational fields is a key step to reduce complexity of discuss code in the models, making code less prone to bugs, and simplify development of new features that require using a lot of relations on models.
https://github.com/odoo/enterprise/pull/47745This update modernizes automated tests across Odoo's messaging-related areas by replacing older test matching patterns. It helps keep the test suite reliable and easier to maintain without changing how users interact with the product.
Original PR description
* = web, sms
This update reorganizes and renames internal messaging data structures to make Discuss-related code easier to maintain and extend. It prepares the messaging, live chat, calendar, and HR areas for future improvements without changing expected user-facing behavior.
Original PR description
https://github.com/odoo/enterprise/pull/45090
The mail and live chat discuss components were reorganized to manage internal records more consistently. This prepares the messaging system for safer cleanup of deleted records, improving maintainability without introducing a direct user-facing workflow change.
Original PR description
1. Introduce `static id` to all models, to uniquely identify a record in a model. This allows normalizing discuss store for all models, which helps as preparation for managing record deletion. Can…
1. Introduce `static id` to all models, to uniquely identify
a record in a model. This allows normalizing discuss store
for all models, which helps as preparation for managing
record deletion. Can also be combined
```js
class Message {
static id = "id";
id;
}
class Thread {
static id = AND("model", "id");
}
```
2. Introduce `Model.get()` to easily get a record of model
from data that can identify the record. This prevent leaking
the way the record are stored in `records`, as now all records
are indexed by localId, and localId is technical detail.
```js
Message.get(messageId);
Thread.get({ model: "discuss.channel", id: 1 });
```
3. Introduce `record.delete()` to easily delete a record from
from the `static records` object.
```js
// before
delete this.store.Model.records[record.localId];
// after
record.delete();
```
4. Introduce `Record.one()` relational field on model.
This allow storing only the local id internally, and there are
automatic `get`/`set` to get the related record. This prepares
support of record deletion that would automatically delete
all relational fields, in a follow-up PR.
Relational fields can be used to uniquely identify records.
```js
class Message {
author = one();
}
class ChatWindow {
static id = "thread";
thread = one();
}
```This internal refactoring simplifies how Discuss-related data structures are defined and stored in Odoo. It reduces duplicate code across mail, live chat, and calendar integrations, making future messaging improvements easier and less error-prone without changing day-to-day user workflows.
Original PR description
https://github.com/odoo/enterprise/pull/46170 Discuss models are hard to use in discuss code: they need to define a model define a `insert()` function in a service, and define a store entry. For…
https://github.com/odoo/enterprise/pull/46170
Discuss models are hard to use in discuss code: they need to define a model define a `insert()` function in a service, and define a store entry. For example, with threads:
```js
// thread_model.js
class Thread {}
// store_service.js
threads: {},
// thread_service.js
class ThreadService {
insert(data) {}
}
```
This commit eases defining a Model by just adding code in the model file:
```js
class Thread extends Record {}
discussModelRegistry.add(Thread.name, Thread)
```
This will automatically add a store entry named with the ModelName, e.g. `this.store.Thread`. This is the shape of this store entry:
```
store: {
[ModelName]: {
records: {}
insert(data) {}
findById(data) {}
}
}
```
Records in a model must be uniquely identified. Fields that uniquely define a record in a model is defined in the class of model:
```js
class Thread extends Record {
static id = ["model", "id"];
}
```This update removes older test utilities used for file handling and moves tests to the newer shared approach. It helps keep the codebase easier to maintain and reduces duplicated testing infrastructure, with no expected direct impact on users.
Original PR description
\* = mrp https://github.com/odoo/enterprise/pull/47716
This update cleans up internal automated tests for Belgian payroll accounting and documents by replacing older testing utilities. It helps keep quality checks reliable and easier to maintain without changing day-to-day product behavior.
Original PR description
https://github.com/odoo/odoo/pull/136141