customer_counter.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. function customer_counter (widget) {
  2. "use strict";
  3. widget.CustomerCounterWidget = widget.Base.extend({
  4. template: 'CustomerCounterTmpl',
  5. events: {
  6. 'click a': 'showCustomers'
  7. },
  8. customers: [],
  9. fields: ['name'],
  10. domain: [['customer', '=', true], ['active', '=', true]],
  11. init: function (parent) {
  12. this._super(parent, { width: 3, height: 2 });
  13. },
  14. start: function () {
  15. var self = this;
  16. this.getCustomers().then(function (customers) {
  17. self.customers = customers;
  18. self.renderWidget();
  19. });
  20. },
  21. getCustomers: function () {
  22. var Customer = new instance.web.Model('res.partner');
  23. return Customer.query(this.fields).filter(this.domain).order_by(['id']).all();
  24. },
  25. renderWidget: function () {
  26. console.log(this.customers);
  27. },
  28. showCustomers: function (e) {
  29. this.do_action({
  30. type: 'ir.actions.act_window',
  31. res_model: "res.partner",
  32. views: [[false, 'list']],
  33. target: 'new',
  34. domain: [['customer', '=', true]],
  35. context: {},
  36. });
  37. }
  38. });
  39. }