Skip to content

Commit

Permalink
[Solution] 2.2 Add some buttons for quick navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
fdardenne authored and ged-odoo committed Nov 14, 2022
1 parent a24c571 commit bc95e11
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 32 additions & 0 deletions awesome_tshirt/static/src/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { getDefaultConfig } from "@web/views/view";
import { useService } from "@web/core/utils/hooks";
import { Domain } from "@web/core/domain";

const { Component, useSubEnv } = owl;

Expand All @@ -17,6 +19,36 @@ class AwesomeDashboard extends Component {
this.display = {
controlPanel: { "top-right": false, "bottom-right": false },
};

this.action = useService("action");
}

openCustomerView() {
this.action.doAction("base.action_partner_form");
}

openOrders(title, domain) {
this.action.doAction({
type: "ir.actions.act_window",
name: title,
res_model: "awesome_tshirt.order",
domain: new Domain(domain).toList(),
views: [
[false, "list"],
[false, "form"],
],
});
}
openLast7DaysOrders() {
const domain =
"[('create_date','>=', (context_today() - datetime.timedelta(days=7)).strftime('%Y-%m-%d'))]";
this.openOrders("Last 7 days orders", domain);
}

openLast7DaysCancelledOrders() {
const domain =
"[('create_date','>=', (context_today() - datetime.timedelta(days=7)).strftime('%Y-%m-%d')), ('state','=', 'cancelled')]";
this.openOrders("Last 7 days cancelled orders", domain);
}
}

Expand Down
4 changes: 3 additions & 1 deletion awesome_tshirt/static/src/dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<t t-name="awesome_tshirt.clientaction" owl="1">
<Layout display="display">
<t t-set-slot="control-panel-bottom-left">
Hello owl
<button class="btn btn-primary" t-on-click="openCustomerView"> Customers </button>
<button class="btn btn-primary" t-on-click="openLast7DaysOrders"> New Orders </button>
<button class="btn btn-primary" t-on-click="openLast7DaysCancelledOrders"> Cancelled Orders </button>
</t>
</Layout>
</t>
Expand Down

0 comments on commit bc95e11

Please sign in to comment.