19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:27 +01:00
parent d1963a3c3a
commit 2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 1,007 B

Before After
Before After

View file

@ -1,35 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 70 70">
<defs>
<mask id="mask" x="0" y="0" width="70" height="70" maskUnits="userSpaceOnUse">
<g id="b">
<path id="a" d="M4,0H65c4,0,5,1,5,5V65c0,4-1,5-5,5H4c-3,0-4-1-4-5V5C0,1,1,0,4,0Z" fill="#fff" fill-rule="evenodd"/>
</g>
</mask>
<linearGradient id="linear-gradient" x1="-1438.5" y1="477.94" x2="-1439.5" y2="476.94" gradientTransform="matrix(70, 0, 0, -70, 100764.99, 33455.73)" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#cd7690"/>
<stop offset="1" stop-color="#ca5377"/>
</linearGradient>
</defs>
<g mask="url(#mask)">
<g>
<path d="M0,0H70V70H0Z" fill-rule="evenodd" fill="url(#linear-gradient)"/>
<path d="M4,1H65c2.67,0,4.33.67,5,2V0H0V3C.67,1.67,2,1,4,1Z" fill="#fff" fill-opacity="0.38" fill-rule="evenodd"/>
<path d="M34.48,69H4c-2,0-4-.15-4-4.08V41.77L16.94,24.83l6.56-2.94,15-15,.71,2.26,11.87-.16-3.77,7.15L40,23.42v1.49l3-3h3c3.89-.06,8.64,27,8.64,27Z" fill="#393939" fill-rule="evenodd" opacity="0.32" style="isolation: isolate"/>
<path d="M4,69H65c2.67,0,4.33-1,5-3v4H0V66A3.92,3.92,0,0,0,4,69Z" fill-opacity="0.38" fill-rule="evenodd"/>
<g>
<g opacity="0.4">
<path d="M36.52,36.47A1.5,1.5,0,0,1,35,35V10.37a1.5,1.5,0,1,1,3,0V35A1.5,1.5,0,0,1,36.52,36.47Z"/>
<path d="M44.45,18.62H36.52V10.37H48.17a1,1,0,0,1,.88,1.56l-3.72,6.19A1,1,0,0,1,44.45,18.62Z" fill-rule="evenodd"/>
<path d="M33,63.89a1.51,1.51,0,0,1-1.5-1.5V49.92a1.5,1.5,0,0,1,3,0V62.39A1.5,1.5,0,0,1,33,63.89Z"/>
<path d="M45.57,23.91H41V35a4.5,4.5,0,0,1-9,0V23.91H20.11a7.3,7.3,0,0,0-7.19,7.4v19a1,1,0,0,0,1,1H51.78a1,1,0,0,0,1-1v-19A7.31,7.31,0,0,0,45.57,23.91ZM26.65,49.32H14.92v-18a5.32,5.32,0,0,1,4.92-5.39,6.68,6.68,0,0,1,6.81,6.39Z" fill-rule="evenodd"/>
</g>
<g>
<path d="M38.54,34.45A1.5,1.5,0,0,1,37,33V8.34a1.5,1.5,0,1,1,3,0V33A1.5,1.5,0,0,1,38.54,34.45Z" fill="#fff"/>
<path d="M46.47,16.59H38.54V8.34H50.19a1,1,0,0,1,.88,1.57l-3.72,6.18A1,1,0,0,1,46.47,16.59Z" fill="#fff" fill-rule="evenodd"/>
<path d="M35,61.86a1.5,1.5,0,0,1-1.5-1.5V47.89a1.5,1.5,0,0,1,3,0V60.36A1.5,1.5,0,0,1,35,61.86Z" fill="#fff"/>
<path d="M47.59,21.89H43V33a4.5,4.5,0,0,1-9,0V21.89H22.14a7.31,7.31,0,0,0-7.2,7.4v19a1,1,0,0,0,1,1H53.8a1,1,0,0,0,1-1v-19A7.31,7.31,0,0,0,47.59,21.89ZM28.67,47.3H16.94v-18a5.31,5.31,0,0,1,4.92-5.39,6.66,6.66,0,0,1,6.81,6.39Z" fill="#fff" fill-rule="evenodd"/>
</g>
</g>
</g>
</g>
</svg>
<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><path d="M0 42V8l25 17L0 42Z" fill="#F9464C"/><path d="M25 25 0 8h50L25 25Z" fill="#FC868B"/><path d="M50 8 0 42h46a4 4 0 0 0 4-4V8Z" fill="#962B48"/></svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 240 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-inherit="mail.NotificationGroup" t-inherit-mode="extension">
<xpath expr="//*[hasclass('o_NotificationGroup_inlineText')]" position="inside">
<t t-if="notificationGroupView.notificationGroup.notification_type === 'snail'">
An error occurred when sending a letter with Snailmail.
</t>
</xpath>
</t>
</templates>

View file

@ -1,31 +0,0 @@
/** @odoo-module **/
import { useComponentToModel } from '@mail/component_hooks/use_component_to_model';
import { registerMessagingComponent } from '@mail/utils/messaging_component';
const { Component } = owl;
export class SnailmailError extends Component {
/**
* @override
*/
setup() {
useComponentToModel({ fieldName: 'component' });
}
/**
* @returns {SnailmailErrorView}
*/
get snailmailErrorView() {
return this.props.record;
}
}
Object.assign(SnailmailError, {
props: { record: Object },
template: 'snailmail.SnailmailError',
});
registerMessagingComponent(SnailmailError);

View file

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="snailmail.SnailmailError" owl="1">
<t t-if="snailmailErrorView">
<div class="o_SnailmailError card bg-white" t-attf-class="{{ className }}" t-ref="root">
<h4 class="m-3">Failed letter</h4>
<hr class="mt-0 mb-3"/>
<t t-if="snailmailErrorView.notification.failure_type === 'sn_credit'">
<p class="o_SnailmailError_contentCredit mx-3 mb-3">
The letter could not be sent due to insufficient credits on your IAP account.
</p>
<t t-if="messaging.snailmail_credits_url">
<div class="text-end mx-3 mb-3">
<a class="btn btn-link" t-att-href="messaging.snailmail_credits_url" target="_blank">
<i class="fa fa-arrow-right"/> Buy credits
</a>
</div>
</t>
</t>
<t t-elif="snailmailErrorView.notification.failure_type === 'sn_trial'">
<p class="o_SnailmailError_contentTrial mx-3 mb-3">
You need credits on your IAP account to send a letter.
</p>
<t t-if="messaging.snailmail_credits_url_trial">
<div class="text-end mx-3 mb-3">
<a class="btn btn-link" t-att-href="messaging.snailmail_credits_url_trial">
<i class="fa fa-arrow-right"/> Buy credits
</a>
</div>
</t>
</t>
<t t-elif="snailmailErrorView.notification.failure_type === 'sn_price'">
<p class="o_SnailmailError_contentPrice mx-3 mb-3">
The country to which you want to send the letter is not supported by our service.
</p>
</t>
<t t-elif="snailmailErrorView.notification.failure_type === 'sn_error'">
<p class="o_SnailmailError_contentError mx-3 mb-3">
An unknown error occurred. Please contact our <a href="https://www.odoo.com/help" target="new">support</a> for further assistance.
</p>
</t>
<hr class="mt-0 mb-3"/>
<div class="o_SnailmailError_buttons mx-3 mb-3">
<t t-if="snailmailErrorView.hasCreditsError">
<button class="o_SnailmailError_resendLetterButton btn btn-primary me-2" t-on-click="snailmailErrorView.onClickResendLetter">Re-send letter</button>
</t>
<button class="o_SnailmailError_cancelLetterButton btn me-2"
t-att-class="{
'btn-primary': !snailmailErrorView.hasCreditsError,
'btn-secondary': snailmailErrorView.hasCreditsError,
}"
t-on-click="snailmailErrorView.onClickCancelLetter"
>
Cancel letter
</button>
<button class="o_SnailmailError_closeButton btn btn-secondary me-2" t-on-click="snailmailErrorView.onClickClose">Close</button>
</div>
</div>
</t>
</t>
</templates>

View file

@ -1,24 +0,0 @@
/** @odoo-module **/
import { registerMessagingComponent } from '@mail/utils/messaging_component';
const { Component } = owl;
export class SnailmailNotificationPopoverContentView extends Component {
/**
* @returns {SnailmailNotificationPopoverContentView}
*/
get snailmailNotificationPopoverContentView() {
return this.props.record;
}
}
Object.assign(SnailmailNotificationPopoverContentView, {
props: { record: Object },
template: 'snailmail.SnailmailNotificationPopoverContentView',
});
registerMessagingComponent(SnailmailNotificationPopoverContentView);

View file

@ -1,7 +0,0 @@
// -----------------------------------------------------------------------------
// Layout
// -----------------------------------------------------------------------------
.o_SnailmailNotificationPopoverContentView_icon {
margin-inline-end: map-get($spacers, 2);
}

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="snailmail.SnailmailNotificationPopoverContentView" owl="1">
<div class="o_SnailmailNotificationPopoverContentView m-2" t-attf-class="{{ className }}" t-ref="root">
<i class="o_SnailmailNotificationPopoverContentView_icon" t-att-class="snailmailNotificationPopoverContentView.iconClass" role="img"/>
<span t-esc="snailmailNotificationPopoverContentView.iconTitle"/>
</div>
</t>
</templates>

View file

@ -0,0 +1,24 @@
import { Failure } from "@mail/core/common/failure_model";
import { _t } from "@web/core/l10n/translation";
import { patch } from "@web/core/utils/patch";
patch(Failure.prototype, {
get iconSrc() {
if (this.type === "snail") {
return "/snailmail/static/img/snailmail_failure.png";
}
return super.iconSrc;
},
get body() {
if (this.type === "snail") {
if (this.notifications.length === 1 && this.lastMessage?.thread) {
return _t(
"An error occurred when sending a letter with Snailmail on “%(record_name)s”",
{ record_name: this.lastMessage.thread.display_name }
);
}
return _t("An error occurred when sending a letter with Snailmail.");
}
return super.body;
},
});

View file

@ -0,0 +1,63 @@
import { Notification } from "@mail/core/common/notification_model";
import { patch } from "@web/core/utils/patch";
import { _t } from "@web/core/l10n/translation";
/** @type {import("models").Notification} */
const notificationPatch = {
get icon() {
if (this.notification_type === "snail") {
return "fa fa-paper-plane";
}
return super.icon;
},
get statusIcon() {
if (this.notification_type === "snail") {
switch (this.notification_status) {
case "sent":
return "fa fa-check";
case "ready":
return "fa fa-clock-o";
case "canceled":
return "fa fa-trash-o";
default:
return "fa fa-exclamation text-danger";
}
}
return super.statusIcon;
},
get failureMessage() {
switch (this.failure_type) {
case "sn_credit":
return _t("Insufficient Credits");
case "sn_trial":
return _t("No IAP Credits");
case "sn_price":
return _t("Country Not Supported");
case "sn_fields":
return _t("Missing Required Fields");
case "sn_format":
return _t("Format Error");
case "sn_error":
return _t("Unknown Error");
default:
return super.failureMessage;
}
},
get statusTitle() {
if (this.notification_type === "snail") {
switch (this.notification_status) {
case "sent":
return _t("Sent");
case "ready":
return _t("Awaiting Dispatch");
case "canceled":
return _t("Cancelled");
default:
return _t("Error");
}
}
return super.statusTitle;
},
};
patch(Notification.prototype, notificationPatch);

View file

@ -0,0 +1,8 @@
import { Message } from "@mail/core/common/message";
import { SnailmailNotificationPopover } from "./snailmail_notification_popover";
Message.components = {
...Message.components,
Popover: SnailmailNotificationPopover,
};

View file

@ -0,0 +1,6 @@
import { Component } from "@odoo/owl";
export class SnailmailNotificationPopover extends Component {
static template = "snailmail.SnailmailNotificationPopover";
static props = ["message", "close?"];
}

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="snailmail.SnailmailNotificationPopover" t-inherit="mail.MessageNotificationPopover" t-inherit-mode="primary">
<xpath expr="//div[hasclass('o-mail-MessageNotificationPopover')]" position="replace">
<t t-if="props.message.message_type === 'snailmail'">
<div class="o-snailmail-SnailmailNotificationPopover m-2" t-attf-class="{{ className }}">
<i class="me-2 fa-fw" t-att-class="props.message.notification_ids[0].statusIcon" role="img"/>
<span t-esc="props.message.notification_ids[0].statusTitle"/>
<span t-if="props.message.notification_ids[0].isFailure">(<t t-out="props.message.notification_ids[0].failureMessage"/>)</span>
</div>
</t>
<t t-else="">$0</t>
</xpath>
</t>
</templates>

View file

@ -1,12 +0,0 @@
// Change address font-size if needed
document.addEventListener('DOMContentLoaded', function (evt) {
var recipientAddress = document.querySelector(".address.row > div[name='address'] > address");
let baseSize = 120;
if (!recipientAddress) {
recipientAddress = document.querySelector("div .row.fallback_header > div.col-5.offset-7 > div:first-child");
}
var style = window.getComputedStyle(recipientAddress, null);
var height = parseFloat(style.getPropertyValue('height'));
var fontSize = parseFloat(style.getPropertyValue('font-size'));
recipientAddress.style.fontSize = (baseSize / (height / fontSize)) + 'px';
});

View file

@ -0,0 +1,31 @@
import { MessagingMenu } from "@mail/core/public_web/messaging_menu";
import { _t } from "@web/core/l10n/translation";
import { patch } from "@web/core/utils/patch";
patch(MessagingMenu.prototype, {
openFailureView(failure) {
if (failure.type !== "snail") {
return super.openFailureView(failure);
}
this.env.services.action.doAction({
name: _t("Snailmail Failures"),
type: "ir.actions.act_window",
view_mode: "kanban,list,form",
views: [
[false, "kanban"],
[false, "list"],
[false, "form"],
],
target: "current",
res_model: failure.resModel,
domain: [["message_ids.snailmail_error", "=", true]],
});
this.dropdown.close();
},
getFailureNotificationName(failure) {
if (failure.type === "snail") {
return _t("Snailmail Failure: %(modelName)s", { modelName: failure.modelName });
}
return super.getFailureNotificationName(...arguments);
},
});

View file

@ -1,48 +0,0 @@
/** @odoo-module **/
import { registerPatch } from '@mail/model/model_core';
import { one } from '@mail/model/model_field';
import { clear } from '@mail/model/model_field_command';
registerPatch({
name: 'Dialog',
fields: {
componentClassName: {
compute() {
if (this.snailmailErrorView) {
return 'o_Dialog_componentMediumSize align-self-start mt-5';
}
return this._super();
},
},
componentName: {
compute() {
if (this.snailmailErrorView) {
return 'SnailmailError';
}
return this._super();
},
},
messageViewOwnerAsSnailmailError: one('MessageView', {
identifying: true,
inverse: 'snailmailErrorDialog',
}),
record: {
compute() {
if (this.snailmailErrorView) {
return this.snailmailErrorView;
}
return this._super();
},
},
snailmailErrorView: one('SnailmailErrorView', {
compute() {
if (this.messageViewOwnerAsSnailmailError) {
return {};
}
return clear();
},
inverse: 'dialogOwner',
}),
},
});

View file

@ -1,64 +0,0 @@
/** @odoo-module **/
import { registerPatch } from '@mail/model/model_core';
registerPatch({
name: 'Message',
recordMethods: {
/**
* Cancels the 'snailmail.letter' corresponding to this message.
*
* @returns {Deferred}
*/
async cancelLetter() {
// the result will come from the bus: message_notification_update
await this.messaging.rpc({
model: 'mail.message',
method: 'cancel_letter',
args: [[this.id]],
});
},
/**
* Opens the action about 'snailmail.letter' format error.
*/
openFormatLetterAction() {
this.env.services.action.doAction(
'snailmail.snailmail_letter_format_error_action',
{
additionalContext: {
message_id: this.id,
},
},
);
},
/**
* Opens the action about 'snailmail.letter' missing fields.
*/
async openMissingFieldsLetterAction() {
const letterIds = await this.messaging.rpc({
model: 'snailmail.letter',
method: 'search',
args: [[['message_id', '=', this.id]]],
});
this.env.services.action.doAction(
'snailmail.snailmail_letter_missing_required_fields_action',
{
additionalContext: {
default_letter_id: letterIds[0],
},
}
);
},
/**
* Retries to send the 'snailmail.letter' corresponding to this message.
*/
async resendLetter() {
// the result will come from the bus: message_notification_update
await this.messaging.rpc({
model: 'mail.message',
method: 'send_letter',
args: [[this.id]],
});
},
},
});

View file

@ -1,84 +0,0 @@
/** @odoo-module **/
import { registerPatch } from '@mail/model/model_core';
import { one } from '@mail/model/model_field';
import { clear } from '@mail/model/model_field_command';
registerPatch({
name: 'MessageView',
recordMethods: {
/**
* @override
*/
onClickFailure() {
if (this.message.message_type === 'snailmail') {
/**
* Messages from snailmail are considered to have at most one
* notification. The failure type of the whole message is considered
* to be the same as the one from that first notification, and the
* click action will depend on it.
*/
switch (this.message.notifications[0].failure_type) {
case 'sn_credit':
// URL only used in this component, not received at init
this.messaging.fetchSnailmailCreditsUrl();
this.update({ snailmailErrorDialog: {} });
break;
case 'sn_error':
this.update({ snailmailErrorDialog: {} });
break;
case 'sn_fields':
this.message.openMissingFieldsLetterAction();
break;
case 'sn_format':
this.message.openFormatLetterAction();
break;
case 'sn_price':
this.update({ snailmailErrorDialog: {} });
break;
case 'sn_trial':
// URL only used in this component, not received at init
this.messaging.fetchSnailmailCreditsUrlTrial();
this.update({ snailmailErrorDialog: {} });
break;
}
} else {
this._super(...arguments);
}
},
/**
* @override
*/
onClickNotificationIcon() {
if (this.message && this.message.message_type === 'snailmail') {
this.update({ snailmailNotificationPopoverView: this.snailmailNotificationPopoverView ? clear() : {} });
return;
}
return this._super();
},
},
fields: {
failureNotificationIconClassName: {
compute() {
if (this.message && this.message.message_type === 'snailmail') {
return 'fa fa-paper-plane';
}
return this._super();
},
},
notificationIconClassName: {
compute() {
if (this.message && this.message.message_type === 'snailmail') {
return 'fa fa-paper-plane';
}
return this._super();
},
},
snailmailErrorDialog: one('Dialog', {
inverse: 'messageViewOwnerAsSnailmailError',
}),
snailmailNotificationPopoverView: one('PopoverView', {
inverse: 'messageViewOwnerAsSnailmailNotificationContent',
}),
},
});

View file

@ -1,40 +0,0 @@
/** @odoo-module **/
import { registerPatch } from '@mail/model/model_core';
import { attr } from '@mail/model/model_field';
registerPatch({
name: 'Messaging',
recordMethods: {
async fetchSnailmailCreditsUrl() {
const snailmail_credits_url = await this.messaging.rpc({
model: 'iap.account',
method: 'get_credits_url',
args: ['snailmail'],
});
if (!this.exists()) {
return;
}
this.update({
snailmail_credits_url,
});
},
async fetchSnailmailCreditsUrlTrial() {
const snailmail_credits_url_trial = await this.messaging.rpc({
model: 'iap.account',
method: 'get_credits_url',
args: ['snailmail', '', 0, true],
});
if (!this.exists()) {
return;
}
this.update({
snailmail_credits_url_trial,
});
},
},
fields: {
snailmail_credits_url: attr(),
snailmail_credits_url_trial: attr(),
},
});

View file

@ -1,31 +0,0 @@
/** @odoo-module **/
import { registerPatch } from '@mail/model/model_core';
registerPatch({
name: 'NotificationGroup',
recordMethods: {
/**
* @override
*/
_openDocuments() {
if (this.notification_type !== 'snail') {
return this._super(...arguments);
}
this.env.services.action.doAction({
name: this.env._t("Snailmail Failures"),
type: 'ir.actions.act_window',
view_mode: 'kanban,list,form',
views: [[false, 'kanban'], [false, 'list'], [false, 'form']],
target: 'current',
res_model: this.res_model,
domain: [['message_ids.snailmail_error', '=', true]],
});
if (this.messaging.device.isSmall) {
// messaging menu has a higher z-index than views so it must
// be closed to ensure the visibility of the view
this.messaging.messagingMenu.close();
}
},
},
});

View file

@ -1,17 +0,0 @@
/** @odoo-module **/
import { registerPatch } from '@mail/model/model_core';
registerPatch({
name: 'NotificationGroupView',
fields: {
imageSrc: {
compute() {
if (this.notificationGroup.notification_type === 'snail') {
return '/snailmail/static/img/snailmail_failure.png';
}
return this._super();
},
},
},
});

View file

@ -1,48 +0,0 @@
/** @odoo-module **/
import { registerPatch } from '@mail/model/model_core';
import { one } from '@mail/model/model_field';
import { clear } from '@mail/model/model_field_command';
registerPatch({
name: 'PopoverView',
fields: {
anchorRef: {
compute() {
if (this.messageViewOwnerAsSnailmailNotificationContent) {
return this.messageViewOwnerAsSnailmailNotificationContent.notificationIconRef;
}
return this._super();
},
},
content: {
compute() {
if (this.snailmailNotificationPopoverContentView) {
return this.snailmailNotificationPopoverContentView;
}
return this._super();
},
},
contentComponentName: {
compute() {
if (this.snailmailNotificationPopoverContentView) {
return 'SnailmailNotificationPopoverContentView';
}
return this._super();
},
},
messageViewOwnerAsSnailmailNotificationContent: one('MessageView', {
identifying: true,
inverse: 'snailmailNotificationPopoverView',
}),
snailmailNotificationPopoverContentView: one('SnailmailNotificationPopoverContentView', {
compute() {
if (this.messageViewOwnerAsSnailmailNotificationContent) {
return {};
}
return clear();
},
inverse: 'popoverViewOwner',
}),
},
});

View file

@ -1,63 +0,0 @@
/** @odoo-module **/
import { registerModel } from '@mail/model/model_core';
import { attr, one } from '@mail/model/model_field';
registerModel({
name: 'SnailmailErrorView',
recordMethods: {
/**
* Returns whether the given html element is inside this snailmail error view.
*
* @param {Element} element
* @returns {boolean}
*/
containsElement(element) {
return Boolean(this.component && this.component.root.el && this.component.root.el.contains(element));
},
onClickCancelLetter() {
this.message.cancelLetter();
this.dialogOwner.delete();
},
onClickClose() {
this.dialogOwner.delete();
},
onClickResendLetter() {
this.message.resendLetter();
this.dialogOwner.delete();
},
},
fields: {
component: attr(),
dialogOwner: one('Dialog', {
identifying: true,
inverse: 'snailmailErrorView',
}),
hasCreditsError: attr({
compute() {
return Boolean(
this.notification &&
(
this.notification.failure_type === 'sn_credit' ||
this.notification.failure_type === 'sn_trial'
)
);
},
}),
message: one('Message', {
compute() {
return this.dialogOwner.messageViewOwnerAsSnailmailError.message;
},
required: true,
}),
/**
* Messages from snailmail are considered to have at most one notification.
*/
notification: one('Notification', {
compute() {
return this.message.notifications[0];
},
required: true,
}),
},
});

View file

@ -1,65 +0,0 @@
/** @odoo-module **/
import { registerModel } from '@mail/model/model_core';
import { attr, one } from '@mail/model/model_field';
import { clear } from '@mail/model/model_field_command';
registerModel({
name: 'SnailmailNotificationPopoverContentView',
fields: {
iconClass: attr({
compute() {
if (!this.notification) {
return clear();
}
switch (this.notification.notification_status) {
case 'sent':
return 'fa fa-check';
case 'ready':
return 'fa fa-clock-o';
case 'canceled':
return 'fa fa-trash-o';
default:
return 'fa fa-exclamation text-danger';
}
},
default: '',
}),
iconTitle: attr({
compute() {
if (!this.notification) {
return clear();
}
switch (this.notification.notification_status) {
case 'sent':
return this.env._t("Sent");
case 'ready':
return this.env._t("Awaiting Dispatch");
case 'canceled':
return this.env._t("Canceled");
default:
return this.env._t("Error");
}
},
default: '',
}),
message: one('Message', {
compute() {
return this.popoverViewOwner.messageViewOwnerAsSnailmailNotificationContent.message;
},
}),
notification: one('Notification', {
compute() {
if (!this.message) {
return clear();
}
// Messages from snailmail are considered to have at most one notification.
return this.message.notifications[0];
},
}),
popoverViewOwner: one('PopoverView', {
identifying: true,
inverse: 'snailmailNotificationPopoverContentView',
}),
},
});

View file

@ -1,64 +0,0 @@
/*Modifications for the Standard and Boxed document layouts */
.article.o_report_layout_standard.o_company_1_layout, .article.o_report_layout_boxed.o_company_1_layout {
> .pt-5 {
padding-top: 0 !important;
> .address.row {
width: 117% !important;
height: 68mm !important;
margin-top: -4mm !important;
line-height: 1.1em;
}
}
}
/*Modifications for Bold and Striped document layouts*/
.article.o_report_layout_bold.o_company_1_layout, .article.o_report_layout_striped.o_company_1_layout {
> .address.row {
width: 117% !important;
height: 68mm !important;
margin-top: -4mm !important;
line-height: 1.1em;
}
}
/* Modifications for all layouts */
div .address.row > div[name="address"] {
position: relative !important;
margin-left: 47.5% !important;
background-color: #ffffff;
> address {
width: 100% !important;
position: absolute !important;
bottom: 0 !important;
padding-left: 5mm;
padding-top: 3mm;
height: 33mm;
max-height: 33mm;
}
}
div .header.o_company_1_layout > div[class$="_header"] {
overflow: hidden !important;
max-height: 150px;
}
/* Follow-up Letters */
div .row.fallback_header {
margin-top: -4mm !important;
height: 68mm !important;
width: 117% !important;
> div.col-5.offset-7 {
background-color: #ffffff;
margin-left: 47.5% !important;
position: relative !important;
> div:first-child {
width: 100%;
padding-left: 6mm !important;
height: 33mm;
max-height: 33mm !important;
line-height: 1.1em;
position: absolute;
bottom: 0;
}
}
}

View file

@ -1,58 +0,0 @@
/** @odoo-module **/
import '@mail/../tests/helpers/mock_server'; // ensure mail overrides are applied first
import { patch } from "@web/core/utils/patch";
import { MockServer } from "@web/../tests/helpers/mock_server";
patch(MockServer.prototype, 'snailmail', {
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @override
*/
async performRPC(route, args) {
if (args.model === 'mail.message' && args.method === 'cancel_letter') {
const ids = args.args[0];
return this._mockMailMessageCancelLetter(ids);
}
if (args.model === 'mail.message' && args.method === 'send_letter') {
const ids = args.args[0];
return this._mockMailMessageSendLetter(ids);
}
if (args.method === 'get_credits_url') {
// random value returned in order for the mock server to know that this route is implemented.
return true;
}
return this._super(...arguments);
},
//--------------------------------------------------------------------------
// Private Mocked Methods
//--------------------------------------------------------------------------
/**
* Simulates `cancel_letter` on `mail.message`.
*
* @private
* @param {integer[]} ids
*/
_mockMailMessageCancelLetter(ids) {
// TODO implement this mock and improve related tests (task-2300496)
// random value returned in order for the mock server to know that this route is implemented.
return true;
},
/**
* Simulates `send_letter` on `mail.message`.
*
* @private
* @param {integer[]} ids
*/
_mockMailMessageSendLetter(ids) {
// TODO implement this mock and improve related tests (task-2300496)
// random value returned in order for the mock server to know that this route is implemented.
return true;
},
});

View file

@ -1,5 +0,0 @@
/** @odoo-module **/
import { addModelNamesToFetch } from '@bus/../tests/helpers/model_definitions_helpers';
addModelNamesToFetch(['snailmail.letter']);

View file

@ -0,0 +1,218 @@
import {
click,
contains,
openFormView,
start,
startServer,
} from "@mail/../tests/mail_test_helpers";
import { describe, test } from "@odoo/hoot";
import { defineSnailmailModels } from "../snailmail_test_helpers";
describe.current.tags("desktop");
defineSnailmailModels();
test("Sent", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const messageId = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: partnerId,
});
pyEnv["mail.notification"].create({
mail_message_id: messageId,
notification_status: "sent",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover i.fa-check");
await contains(".o-snailmail-SnailmailNotificationPopover", { text: "Sent" });
});
test("Cancelled", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const messageId = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: partnerId,
});
pyEnv["mail.notification"].create({
mail_message_id: messageId,
notification_status: "canceled",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover i.fa-trash-o");
await contains(".o-snailmail-SnailmailNotificationPopover", { text: "Cancelled" });
});
test("Pending", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const messageId = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: partnerId,
});
pyEnv["mail.notification"].create({
mail_message_id: messageId,
notification_status: "ready",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover i.fa-clock-o");
await contains(".o-snailmail-SnailmailNotificationPopover", { text: "Awaiting Dispatch" });
});
test("No Price Available", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const messageId = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: partnerId,
});
pyEnv["mail.notification"].create({
failure_type: "sn_price",
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(Country Not Supported)",
});
});
test("Credit Error", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const messageId = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: partnerId,
});
pyEnv["mail.notification"].create({
failure_type: "sn_credit",
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(Insufficient Credits)",
});
});
test("Trial Error", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const messageId = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: partnerId,
});
pyEnv["mail.notification"].create({
failure_type: "sn_trial",
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(No IAP Credits)",
});
});
test("Format Error", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const messageId = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: partnerId,
});
pyEnv["mail.notification"].create({
failure_type: "sn_format",
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(Format Error)",
});
});
test("Missing Required Fields", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
const messageId = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
res_id: partnerId,
model: "res.partner",
});
pyEnv["mail.notification"].create({
failure_type: "sn_fields",
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(Missing Required Fields)",
});
});

View file

@ -0,0 +1,150 @@
import {
click,
contains,
start,
startServer,
triggerEvents,
} from "@mail/../tests/mail_test_helpers";
import { describe, expect, test } from "@odoo/hoot";
import { defineSnailmailModels } from "@snailmail/../tests/snailmail_test_helpers";
import { asyncStep, mockService, serverState, waitForSteps } from "@web/../tests/web_test_helpers";
describe.current.tags("desktop");
defineSnailmailModels();
test("mark as read", async () => {
const pyEnv = await startServer();
const messageId = pyEnv["mail.message"].create({
message_type: "snailmail",
model: "res.partner",
res_id: serverState.partnerId,
});
pyEnv["mail.notification"].create({
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
});
await start();
await click(".o_menu_systray i[aria-label='Messages']");
await contains(".o-mail-NotificationItem");
await triggerEvents(".o-mail-NotificationItem", ["mouseenter"]);
await contains(".o-mail-NotificationItem-text", {
text: "An error occurred when sending a letter with Snailmail on “Mitchell Admin”",
});
await click(".o-mail-NotificationItem [title='Mark As Read']");
await contains(".o-mail-NotificationItem", { count: 0 });
});
test("notifications grouped by notification_type", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
const [messageId_1, messageId_2] = pyEnv["mail.message"].create([
{
message_type: "snailmail",
model: "res.partner",
res_id: partnerId,
},
{
message_type: "email",
model: "res.partner",
res_id: partnerId,
},
]);
pyEnv["mail.notification"].create([
{
mail_message_id: messageId_1,
notification_status: "exception",
notification_type: "snail",
},
{
mail_message_id: messageId_1,
notification_status: "exception",
notification_type: "snail",
},
{
mail_message_id: messageId_2,
notification_status: "exception",
notification_type: "email",
},
{
mail_message_id: messageId_2,
notification_status: "exception",
notification_type: "email",
},
]);
await start();
await click(".o_menu_systray i[aria-label='Messages']");
await contains(".o-mail-NotificationItem", { count: 2 });
await contains(":nth-child(1 of .o-mail-NotificationItem)", {
contains: [
[".o-mail-NotificationItem-name", { text: "Email Failure: Contact" }],
[".o-mail-NotificationItem-counter", { text: "2" }],
[".o-mail-NotificationItem-text", { text: "An error occurred when sending an email" }],
],
});
await contains(":nth-child(2 of .o-mail-NotificationItem)", {
contains: [
[".o-mail-NotificationItem-name", { text: "Snailmail Failure: Contact" }],
[".o-mail-NotificationItem-counter", { text: "2" }],
[
".o-mail-NotificationItem-text",
{ text: "An error occurred when sending a letter with Snailmail." },
],
],
});
});
test("grouped notifications by document model", async (assert) => {
const pyEnv = await startServer();
const [partnerId_1, partnerId_2] = pyEnv["res.partner"].create([{}, {}]);
const [messageId_1, messageId_2] = pyEnv["mail.message"].create([
{
message_type: "snailmail",
model: "res.partner",
res_id: partnerId_1,
},
{
message_type: "snailmail",
model: "res.partner",
res_id: partnerId_2,
},
]);
pyEnv["mail.notification"].create([
{
mail_message_id: messageId_1,
notification_status: "exception",
notification_type: "snail",
},
{
mail_message_id: messageId_2,
notification_status: "exception",
notification_type: "snail",
},
]);
mockService("action", {
doAction(action) {
asyncStep("do_action");
expect(action.name).toBe("Snailmail Failures");
expect(action.type).toBe("ir.actions.act_window");
expect(action.view_mode).toBe("kanban,list,form");
expect(JSON.stringify(action.views)).toBe(
JSON.stringify([
[false, "kanban"],
[false, "list"],
[false, "form"],
])
);
expect(action.target).toBe("current");
expect(action.res_model).toBe("res.partner");
expect(JSON.stringify(action.domain)).toBe(
JSON.stringify([["message_ids.snailmail_error", "=", true]])
);
},
});
await start();
await click(".o_menu_systray i[aria-label='Messages']");
await contains(".o-mail-NotificationItem", { text: "Snailmail Failure: Contact" });
await contains(".o-mail-NotificationItem-counter", { text: "2" });
await click(".o-mail-NotificationItem");
await waitForSteps(["do_action"]);
});

View file

@ -0,0 +1,9 @@
import { models } from "@web/../tests/web_test_helpers";
export class IapAccount extends models.ServerModel {
_name = "iap.account";
get_credits_url() {
return true;
}
}

View file

@ -0,0 +1,5 @@
import { models } from "@web/../tests/web_test_helpers";
export class SnailmailLetter extends models.ServerModel {
_name = "snailmail.letter";
}

View file

@ -1,349 +0,0 @@
/* @odoo-module */
import { startServer } from "@bus/../tests/helpers/mock_python_environment";
import { start } from "@mail/../tests/helpers/test_utils";
import { makeDeferred } from "@mail/utils/deferred";
import { patchWithCleanup } from "@web/../tests/helpers/utils";
import { click, contains } from "@web/../tests/utils";
QUnit.module("snailmail", {}, function () {
QUnit.module("components", {}, async function () {
QUnit.module("message_tests.js");
QUnit.test("Sent", async function () {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
mail_message_id: mailMessageId1,
notification_status: "sent",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const { openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailNotificationPopoverContentView", { text: "Sent" });
await contains(".o_SnailmailNotificationPopoverContentView_icon.fa-check");
});
QUnit.test("Canceled", async function () {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
mail_message_id: mailMessageId1,
notification_status: "canceled",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const { openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailNotificationPopoverContentView", { text: "Canceled" });
await contains(".o_SnailmailNotificationPopoverContentView_icon.fa-trash-o");
});
QUnit.test("Pending", async function () {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
mail_message_id: mailMessageId1,
notification_status: "ready",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const { openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailNotificationPopoverContentView", {
text: "Awaiting Dispatch",
});
await contains(".o_SnailmailNotificationPopoverContentView_icon.fa-clock-o");
});
QUnit.test("No Price Available", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
failure_type: "sn_price",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const def = makeDeferred();
const { openFormView } = await start({
async mockRPC(route, args) {
if (
args.method === "cancel_letter" &&
args.model === "mail.message" &&
args.args[0][0] === mailMessageId1
) {
assert.step(args.method);
def.resolve();
}
},
});
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailError");
await contains(".o_SnailmailError_contentPrice");
await click(".o_SnailmailError_cancelLetterButton");
await contains(".o_SnailmailError", { count: 0 });
await def;
assert.verifySteps(["cancel_letter"], "should have made a RPC call to 'cancel_letter'");
});
QUnit.test("Credit Error", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
failure_type: "sn_credit",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const def = makeDeferred();
const { openFormView } = await start({
async mockRPC(route, args) {
if (
args.method === "send_letter" &&
args.model === "mail.message" &&
args.args[0][0] === mailMessageId1
) {
assert.step(args.method);
def.resolve();
}
},
});
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailError");
await contains(".o_SnailmailError_contentCredit");
await contains(".o_SnailmailError_cancelLetterButton");
await click(".o_SnailmailError_resendLetterButton");
await contains(".o_SnailmailError", { count: 0 });
await def;
assert.verifySteps(["send_letter"], "should have made a RPC call to 'send_letter'");
});
QUnit.test("Trial Error", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
failure_type: "sn_trial",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const def = makeDeferred();
const { openFormView } = await start({
async mockRPC(route, args) {
if (
args.method === "send_letter" &&
args.model === "mail.message" &&
args.args[0][0] === mailMessageId1
) {
assert.step(args.method);
def.resolve();
}
},
});
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailError");
await contains(".o_SnailmailError_contentTrial");
await contains(".o_SnailmailError_cancelLetterButton");
await click(".o_SnailmailError_resendLetterButton");
await contains(".o_SnailmailError", { count: 0 });
await def;
assert.verifySteps(["send_letter"], "should have made a RPC call to 'send_letter'");
});
QUnit.test("Format Error", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
failure_type: "sn_format",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const { env, openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
const def = makeDeferred();
patchWithCleanup(env.services.action, {
doAction(action, options) {
assert.step("do_action");
assert.strictEqual(
action,
"snailmail.snailmail_letter_format_error_action",
"action should be the one for format error"
);
assert.strictEqual(
options.additionalContext.message_id,
mailMessageId1,
"action should have correct message id"
);
def.resolve();
},
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await def;
assert.verifySteps(["do_action"], "should do an action to display the format error dialog");
});
QUnit.test("Missing Required Fields", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
res_id: resPartnerId1, // non 0 id, necessary to fetch failure at init
model: "res.partner", // not mail.compose.message, necessary to fetch failure at init
});
pyEnv["mail.notification"].create({
failure_type: "sn_fields",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
});
const snailMailLetterId1 = pyEnv["snailmail.letter"].create({
message_id: mailMessageId1,
});
const { env, openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
const def = makeDeferred();
patchWithCleanup(env.services.action, {
doAction(action, options) {
assert.step("do_action");
assert.strictEqual(
action,
"snailmail.snailmail_letter_missing_required_fields_action",
"action should be the one for missing fields"
);
assert.strictEqual(
options.additionalContext.default_letter_id,
snailMailLetterId1,
"action should have correct letter id"
);
def.resolve();
},
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await def;
assert.verifySteps(
["do_action"],
"an action should be done to display the missing fields dialog"
);
});
});
});

View file

@ -1,259 +0,0 @@
/** @odoo-module **/
import { start, startServer } from '@mail/../tests/helpers/test_utils';
import { patchWithCleanup } from '@web/../tests/helpers/utils';
QUnit.module('snailmail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('notification_list_notification_group_tests.js');
QUnit.test('mark as read', async function (assert) {
assert.expect(2);
// Note: The server code is too complex to be rewritten in javascript.
// Actually, the server rely on the model "snailmail.letter" to identify the notification to cancel
// The following code simulates the cancel of the notification without using "snailmail.letter" model
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({});
// message that is expected to have a failure
const mailMessageId1 = pyEnv['mail.message'].create({
author_id: pyEnv.currentPartnerId,
message_type: 'snailmail',
model: 'mail.channel',
res_id: mailChannelId1,
});
// failure that is expected to be used in the test
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1, // id of the related message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail',
});
const { afterNextRender, click } = await start();
await click('.o_MessagingMenu_toggler');
assert.containsOnce(
document.body,
'.o_NotificationGroup_markAsRead',
"should have 1 mark as read button"
);
await afterNextRender(() => {
document.querySelector('.o_NotificationGroup_markAsRead').click();
});
assert.containsNone(
document.body,
'.o_NotificationGroup',
"should have no notification group"
);
});
QUnit.test('notifications grouped by notification_type', async function (assert) {
assert.expect(11);
const pyEnv = await startServer();
const resPartnerId1 = await pyEnv['res.partner'].create({});
const [mailMessageId1, mailMessageId2] = pyEnv['mail.message'].create([
// first message that is expected to have a failure
{
message_type: 'snailmail', // different type from second message
model: 'res.partner', // same model as second message (and not `mail.channel`)
res_id: resPartnerId1, // same res_id as second message
res_model_name: "Partner", // random related model name
},
// second message that is expected to have a failure
{
message_type: 'email', // different type from first message
model: 'res.partner', // same model as first message (and not `mail.channel`)
res_id: resPartnerId1, // same res_id as first message
res_model_name: "Partner", // same related model name for consistency
},
]);
pyEnv['mail.notification'].create([
{
mail_message_id: mailMessageId1, // id of the related first message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail', // different type from second failure
},
{
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'snail',
},
{
mail_message_id: mailMessageId2, // id of the related second message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'email', // different type from first failure
},
{
mail_message_id: mailMessageId2,
notification_status: 'exception',
notification_type: 'email',
},
]);
const { click } = await start();
await click('.o_MessagingMenu_toggler');
assert.containsN(
document.body,
'.o_NotificationGroup',
2,
"should have 2 notifications group"
);
const groups = document.querySelectorAll('.o_NotificationGroup');
assert.containsOnce(
groups[0],
'.o_NotificationGroup_name',
"should have 1 group name in first group"
);
assert.strictEqual(
groups[0].querySelector('.o_NotificationGroup_name').textContent,
"Partner",
"should have model name as group name"
);
assert.containsOnce(
groups[0],
'.o_NotificationGroup_counter',
"should have 1 group counter in first group"
);
assert.strictEqual(
groups[0].querySelector('.o_NotificationGroup_counter').textContent.trim(),
"(2)",
"should have 2 notifications in first group"
);
assert.strictEqual(
groups[0].querySelector('.o_NotificationGroup_inlineText').textContent.trim(),
"An error occurred when sending an email.",
"should have the group text corresponding to email"
);
assert.containsOnce(
groups[1],
'.o_NotificationGroup_name',
"should have 1 group name in second group"
);
assert.strictEqual(
groups[1].querySelector('.o_NotificationGroup_name').textContent,
"Partner",
"should have second model name as group name"
);
assert.containsOnce(
groups[1],
'.o_NotificationGroup_counter',
"should have 1 group counter in second group"
);
assert.strictEqual(
groups[1].querySelector('.o_NotificationGroup_counter').textContent.trim(),
"(2)",
"should have 2 notifications in second group"
);
assert.strictEqual(
groups[1].querySelector('.o_NotificationGroup_inlineText').textContent.trim(),
"An error occurred when sending a letter with Snailmail.",
"should have the group text corresponding to snailmail"
);
});
QUnit.test('grouped notifications by document model', async function (assert) {
// If all failures linked to a document model refers to different documents,
// a single notification should group all failures that are linked to this
// document model.
assert.expect(12);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = await pyEnv['res.partner'].create([{}, {}]);
const [mailMessageId1, mailMessageId2] = pyEnv['mail.message'].create([
{
message_type: 'snailmail', // message must be snailmail (goal of the test)
model: 'res.partner', // same model as second message (and not `mail.channel`)
res_id: resPartnerId1, // same res_id as second message
res_model_name: "Partner", // random related model name
},
{
message_type: 'snailmail', // message must be snailmail (goal of the test)
model: 'res.partner', // same model as first message (and not `mail.channel`)
res_id: resPartnerId2, // different res_id from first message
res_model_name: "Partner", // same related model name for consistency
},
]);
pyEnv['mail.notification'].create([
// first failure that is expected to be used in the test
{
mail_message_id: mailMessageId1, // id of the related first message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail', // expected failure type for snailmail message
},
// second failure that is expected to be used in the test
{
mail_message_id: mailMessageId2, // id of the related second message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail', // expected failure type for snailmail message
},
]);
const { click, env } = await start();
patchWithCleanup(env.services.action, {
doAction(action) {
assert.step('do_action');
assert.strictEqual(
action.name,
"Snailmail Failures",
"action should have 'Snailmail Failures' as name",
);
assert.strictEqual(
action.type,
'ir.actions.act_window',
"action should have the type act_window"
);
assert.strictEqual(
action.view_mode,
'kanban,list,form',
"action should have 'kanban,list,form' as view_mode"
);
assert.strictEqual(
JSON.stringify(action.views),
JSON.stringify([[false, 'kanban'], [false, 'list'], [false, 'form']]),
"action should have correct views"
);
assert.strictEqual(
action.target,
'current',
"action should have 'current' as target"
);
assert.strictEqual(
action.res_model,
'res.partner',
"action should have the group model as res_model"
);
assert.strictEqual(
JSON.stringify(action.domain),
JSON.stringify([['message_ids.snailmail_error', '=', true]]),
"action should have 'message_has_sms_error' as domain"
);
},
});
await click('.o_MessagingMenu_toggler');
assert.containsOnce(
document.body,
'.o_NotificationGroup',
"should have 1 notification group"
);
assert.containsOnce(
document.body,
'.o_NotificationGroup_counter',
"should have 1 group counter"
);
assert.strictEqual(
document.querySelector('.o_NotificationGroup_counter').textContent.trim(),
"(2)",
"should have 2 notifications in the group"
);
document.querySelector('.o_NotificationGroup').click();
assert.verifySteps(
['do_action'],
"should do an action to display the related records"
);
});
});
});

View file

@ -0,0 +1,10 @@
import { defineModels } from "@web/../tests/web_test_helpers";
import { mailModels } from "@mail/../tests/mail_test_helpers";
import { IapAccount } from "@snailmail/../tests/mock_server/mock_model/iap_account";
import { SnailmailLetter } from "@snailmail/../tests/mock_server/mock_model/snailmail_letter";
export function defineSnailmailModels() {
return defineModels(snailmailModels);
}
export const snailmailModels = { ...mailModels, IapAccount, SnailmailLetter };