Skip to content
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

T1690 interaction resume buttons #1945

Merged
merged 9 commits into from
Aug 15, 2024
2 changes: 1 addition & 1 deletion child_compassion/models/child_compassion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##############################################################################
import logging
import traceback
from datetime import date, datetime
from datetime import date

from dateutil.relativedelta import relativedelta

Expand Down
4 changes: 4 additions & 0 deletions interaction_resume/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"views/partner_log_other_interaction_wizard_view.xml",
"views/res_partner_view.xml",
"views/interaction_resume.xml",
"static/src/xml/assets.xml",
],
"qweb": [
"static/src/xml/tree_button.xml",
],
"external_dependencies": {
"python": [],
Expand Down
100 changes: 100 additions & 0 deletions interaction_resume/static/src/js/tree_button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
odoo.define("interaction_resume.tree_button", function (require) {
"use strict";

var ListController = require("web.ListController");
var ListView = require("web.ListView");
var viewRegistry = require("web.view_registry");
var rpc = require("web.rpc");

var TreeButton = ListController.extend({
buttons_template: "button_near_create.buttons",

events: _.extend({}, ListController.prototype.events, {
"click .btn-refresh": "_onRefresh",
"click .btn-fetch-more": "_onFetchMore",
"click .btn-log-interaction": "_onLogInteraction",
}),

_onRefresh: function () {
var self = this;
var res_ids = this.model.get(this.handle).res_ids;
if (!res_ids.length) {
console.log("No records to refresh");
return;
}

rpc
.query({
model: "interaction.resume",
method: "refresh",
args: [res_ids[0]],
})
.then(function () {
self.reload();
})
.catch(function () {
console.log("Error refreshing record");
});
},

_onFetchMore: function () {
var self = this;
var res_ids = this.model.get(this.handle).res_ids;
if (!res_ids.length) {
console.log("No records to fetch more");
return;
}

rpc
.query({
model: "interaction.resume",
method: "fetch_more",
args: [res_ids[0]],
})
.then(function () {
self.reload();
})
.catch(function () {
console.log("Error fetching more records");
});
},

_onLogInteraction: function () {
var self = this;
var context = this.model.get(this.handle).data[0].context;

if (!context) {
console.log("No context to log interaction");
return;
}

this.do_action(
{
type: "ir.actions.act_window",
res_model: "partner.log.other.interaction.wizard",
views: [[false, "form"]],
target: "new",
context: context,
},
{
on_close: function () {
self.reload();
},
}
)
.then(function (result) {
console.log("Action executed:", result);
})
.catch(function (error) {
console.error("Error executing action:", error);
});
},
});

var ExtendedListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: TreeButton,
}),
});
viewRegistry.add("button_in_tree", ExtendedListView);
});
11 changes: 11 additions & 0 deletions interaction_resume/static/src/xml/assets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/interaction_resume/static/src/js/tree_button.js"
/>
</xpath>
</template>
</odoo>
22 changes: 22 additions & 0 deletions interaction_resume/static/src/xml/tree_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<template id="template" xml:space="preserve">
<t t-extend="ListView.buttons" t-name="button_near_create.buttons">
<t t-jquery="div.o_list_buttons" t-operation="prepend">
<button
class="btn btn-primary btn-refresh"
type="object"
icon="fa-refresh"
>Refresh</button>
<button
class="btn btn-primary btn-fetch-more"
type="object"
icon="fa-plus"
>Fetch more...</button>
<button
class="btn btn-primary btn-log-interaction"
type="action"
icon="fa-plus"
>Log interaction</button>
</t>
</t>
</template>
21 changes: 1 addition & 20 deletions interaction_resume/views/interaction_resume.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<field name="model">interaction.resume</field>
<field name="arch" type="xml">
<tree
js_class="button_in_tree"
decoration-muted="communication_type == 'Mass'"
decoration-info="communication_type in ['Phone', 'SMS']"
decoration-danger="direction == 'in' and communication_type not in ['Mass', 'Phone', 'SMS']"
Expand All @@ -14,26 +15,6 @@
delete="0"
limit="1000"
>
<header>
<button
name="refresh"
string="Refresh"
type="object"
icon="fa-refresh"
/>
<button
name="fetch_more"
string="Fetch more..."
type="object"
icon="fa-plus"
/>
<button
name="%(action_log_other_interaction)d"
string="Log interaction"
type="action"
icon="fa-plus"
/>
</header>
<button
name="out"
icon="fa-arrow-up"
Expand Down
Loading