You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.1 KiB

  1. odoo.define('base_custom_info.relational_fields', function (require) {
  2. "use strict";
  3. var CustomInfoRenderer = require('base_custom_info.CustomInfoRenderer');
  4. var relational_fields = require('web.relational_fields');
  5. var fieldUtils = require('web.field_utils');
  6. relational_fields.FieldOne2Many.include({
  7. _getRenderer: function () {
  8. if (this.view.arch.tag === 'custom_info') {
  9. return CustomInfoRenderer;
  10. }
  11. return this._super.apply(this, arguments);
  12. },
  13. _updateCustomInfoItem : function (data) {
  14. var result = {
  15. value_float: data.value_float,
  16. value_str: data.value_str,
  17. value_int: data.value_int,
  18. value_bool: data.value_bool,
  19. value_date: data.value_date,
  20. };
  21. if (data.value_id.res_id !== undefined)
  22. result['value_id'] = {id: data.value_id.res_id};
  23. return result;
  24. },
  25. _saveCustomInfo: function () {
  26. var self = this;
  27. _.each(this.renderer.recordWidgets, function (widget) {
  28. self._setValue({
  29. operation: 'UPDATE',
  30. id: widget.dataPointID,
  31. data: self._updateCustomInfoItem(widget.recordData),
  32. });
  33. });
  34. },
  35. commitChanges: function () {
  36. if (this.renderer &&
  37. this.renderer.viewType === "custom_info"
  38. ) {
  39. var self = this;
  40. this.renderer.commitChanges().then(function () {
  41. return self._saveCustomInfo();
  42. });
  43. }
  44. return this._super.apply(this, arguments);
  45. },
  46. activate: function (options) {
  47. var result = this._super.apply(this, arguments);
  48. if (result && this.renderer.viewType === 'custom_info') {
  49. if (this.renderer.recordWidgets.length > 0) {
  50. this.renderer.recordWidgets[0].$input.focus();
  51. }
  52. }
  53. return result;
  54. },
  55. });
  56. });