From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../static/src/js/account_dashboard_setup_bar.js | 0 .../account/static/src/js/account_payment_field.js | 156 +++++++++++++++++++ .../static/src/js/account_portal_sidebar.js | 73 +++++++++ .../static/src/js/account_resequence_field.js | 32 ++++ addons/account/static/src/js/account_selection.js | 80 ++++++++++ addons/account/static/src/js/bank_statement.js | 21 +++ addons/account/static/src/js/bills_tree_upload.js | 127 +++++++++++++++ .../account/static/src/js/grouped_view_widget.js | 40 +++++ addons/account/static/src/js/mail_activity.js | 69 +++++++++ .../src/js/section_and_note_fields_backend.js | 106 +++++++++++++ addons/account/static/src/js/tax_group.js | 171 +++++++++++++++++++++ addons/account/static/src/js/tours/account.js | 93 +++++++++++ 12 files changed, 968 insertions(+) create mode 100644 addons/account/static/src/js/account_dashboard_setup_bar.js create mode 100644 addons/account/static/src/js/account_payment_field.js create mode 100644 addons/account/static/src/js/account_portal_sidebar.js create mode 100644 addons/account/static/src/js/account_resequence_field.js create mode 100644 addons/account/static/src/js/account_selection.js create mode 100644 addons/account/static/src/js/bank_statement.js create mode 100644 addons/account/static/src/js/bills_tree_upload.js create mode 100644 addons/account/static/src/js/grouped_view_widget.js create mode 100644 addons/account/static/src/js/mail_activity.js create mode 100644 addons/account/static/src/js/section_and_note_fields_backend.js create mode 100644 addons/account/static/src/js/tax_group.js create mode 100644 addons/account/static/src/js/tours/account.js (limited to 'addons/account/static/src/js') diff --git a/addons/account/static/src/js/account_dashboard_setup_bar.js b/addons/account/static/src/js/account_dashboard_setup_bar.js new file mode 100644 index 00000000..e69de29b diff --git a/addons/account/static/src/js/account_payment_field.js b/addons/account/static/src/js/account_payment_field.js new file mode 100644 index 00000000..fa56d1a1 --- /dev/null +++ b/addons/account/static/src/js/account_payment_field.js @@ -0,0 +1,156 @@ +odoo.define('account.payment', function (require) { +"use strict"; + +var AbstractField = require('web.AbstractField'); +var core = require('web.core'); +var field_registry = require('web.field_registry'); +var field_utils = require('web.field_utils'); + +var QWeb = core.qweb; +var _t = core._t; + +var ShowPaymentLineWidget = AbstractField.extend({ + events: _.extend({ + 'click .outstanding_credit_assign': '_onOutstandingCreditAssign', + }, AbstractField.prototype.events), + supportedFieldTypes: ['char'], + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * @override + * @returns {boolean} + */ + isSet: function() { + return true; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + * @override + */ + _render: function() { + var self = this; + var info = JSON.parse(this.value); + if (!info) { + this.$el.html(''); + return; + } + _.each(info.content, function (k, v){ + k.index = v; + k.amount = field_utils.format.float(k.amount, {digits: k.digits}); + if (k.date){ + k.date = field_utils.format.date(field_utils.parse.date(k.date, {}, {isUTC: true})); + } + }); + this.$el.html(QWeb.render('ShowPaymentInfo', { + lines: info.content, + outstanding: info.outstanding, + title: info.title + })); + _.each(this.$('.js_payment_info'), function (k, v){ + var isRTL = _t.database.parameters.direction === "rtl"; + var content = info.content[v]; + var options = { + content: function () { + var $content = $(QWeb.render('PaymentPopOver', content)); + var unreconcile_button = $content.filter('.js_unreconcile_payment').on('click', self._onRemoveMoveReconcile.bind(self)); + + $content.filter('.js_open_payment').on('click', self._onOpenPayment.bind(self)); + return $content; + }, + html: true, + placement: isRTL ? 'bottom' : 'left', + title: 'Payment Information', + trigger: 'focus', + delay: { "show": 0, "hide": 100 }, + container: $(k).parent(), // FIXME Ugly, should use the default body container but system & tests to adapt to properly destroy the popover + }; + $(k).popover(options); + }); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + * @override + * @param {MouseEvent} event + */ + _onOpenPayment: function (event) { + var paymentId = parseInt($(event.target).attr('payment-id')); + var moveId = parseInt($(event.target).attr('move-id')); + var res_model; + var id; + if (paymentId !== undefined && !isNaN(paymentId)){ + res_model = "account.payment"; + id = paymentId; + } else if (moveId !== undefined && !isNaN(moveId)){ + res_model = "account.move"; + id = moveId; + } + //Open form view of account.move with id = move_id + if (res_model && id) { + this.do_action({ + type: 'ir.actions.act_window', + res_model: res_model, + res_id: id, + views: [[false, 'form']], + target: 'current' + }); + } + }, + /** + * @private + * @override + * @param {MouseEvent} event + */ + _onOutstandingCreditAssign: function (event) { + event.stopPropagation(); + event.preventDefault(); + var self = this; + var id = $(event.target).data('id') || false; + this._rpc({ + model: 'account.move', + method: 'js_assign_outstanding_line', + args: [JSON.parse(this.value).move_id, id], + }).then(function () { + self.trigger_up('reload'); + }); + }, + /** + * @private + * @override + * @param {MouseEvent} event + */ + _onRemoveMoveReconcile: function (event) { + var self = this; + var moveId = parseInt($(event.target).attr('move-id')); + var partialId = parseInt($(event.target).attr('partial-id')); + if (partialId !== undefined && !isNaN(partialId)){ + this._rpc({ + model: 'account.move', + method: 'js_remove_outstanding_partial', + args: [moveId, partialId], + }).then(function () { + self.trigger_up('reload'); + }); + } + }, +}); + +field_registry.add('payment', ShowPaymentLineWidget); + +return { + ShowPaymentLineWidget: ShowPaymentLineWidget +}; + +}); diff --git a/addons/account/static/src/js/account_portal_sidebar.js b/addons/account/static/src/js/account_portal_sidebar.js new file mode 100644 index 00000000..58114e00 --- /dev/null +++ b/addons/account/static/src/js/account_portal_sidebar.js @@ -0,0 +1,73 @@ +odoo.define('account.AccountPortalSidebar', function (require) { +'use strict'; + +const dom = require('web.dom'); +var publicWidget = require('web.public.widget'); +var PortalSidebar = require('portal.PortalSidebar'); +var utils = require('web.utils'); + +publicWidget.registry.AccountPortalSidebar = PortalSidebar.extend({ + selector: '.o_portal_invoice_sidebar', + events: { + 'click .o_portal_invoice_print': '_onPrintInvoice', + }, + + /** + * @override + */ + start: function () { + var def = this._super.apply(this, arguments); + + var $invoiceHtml = this.$el.find('iframe#invoice_html'); + var updateIframeSize = this._updateIframeSize.bind(this, $invoiceHtml); + + $(window).on('resize', updateIframeSize); + + var iframeDoc = $invoiceHtml[0].contentDocument || $invoiceHtml[0].contentWindow.document; + if (iframeDoc.readyState === 'complete') { + updateIframeSize(); + } else { + $invoiceHtml.on('load', updateIframeSize); + } + + return def; + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Called when the iframe is loaded or the window is resized on customer portal. + * The goal is to expand the iframe height to display the full report without scrollbar. + * + * @private + * @param {object} $el: the iframe + */ + _updateIframeSize: function ($el) { + var $wrapwrap = $el.contents().find('div#wrapwrap'); + // Set it to 0 first to handle the case where scrollHeight is too big for its content. + $el.height(0); + $el.height($wrapwrap[0].scrollHeight); + + // scroll to the right place after iframe resize + if (!utils.isValidAnchor(window.location.hash)) { + return; + } + var $target = $(window.location.hash); + if (!$target.length) { + return; + } + dom.scrollTo($target[0], {duration: 0}); + }, + /** + * @private + * @param {MouseEvent} ev + */ + _onPrintInvoice: function (ev) { + ev.preventDefault(); + var href = $(ev.currentTarget).attr('href'); + this._printIframeContent(href); + }, +}); +}); diff --git a/addons/account/static/src/js/account_resequence_field.js b/addons/account/static/src/js/account_resequence_field.js new file mode 100644 index 00000000..57b57bfe --- /dev/null +++ b/addons/account/static/src/js/account_resequence_field.js @@ -0,0 +1,32 @@ +odoo.define('account.ShowResequenceRenderer', function (require) { +"use strict"; + +const { Component } = owl; +const { useState } = owl.hooks; +const AbstractFieldOwl = require('web.AbstractFieldOwl'); +const field_registry = require('web.field_registry_owl'); + +class ChangeLine extends Component { } +ChangeLine.template = 'account.ResequenceChangeLine'; +ChangeLine.props = ["changeLine", 'ordering']; + + +class ShowResequenceRenderer extends AbstractFieldOwl { + constructor(...args) { + super(...args); + this.data = this.value ? JSON.parse(this.value) : { + changeLines: [], + ordering: 'date', + }; + } + async willUpdateProps(nextProps) { + await super.willUpdateProps(nextProps); + Object.assign(this.data, JSON.parse(this.value)); + } +} +ShowResequenceRenderer.template = 'account.ResequenceRenderer'; +ShowResequenceRenderer.components = { ChangeLine } + +field_registry.add('account_resequence_widget', ShowResequenceRenderer); +return ShowResequenceRenderer; +}); diff --git a/addons/account/static/src/js/account_selection.js b/addons/account/static/src/js/account_selection.js new file mode 100644 index 00000000..feee1c17 --- /dev/null +++ b/addons/account/static/src/js/account_selection.js @@ -0,0 +1,80 @@ +odoo.define('account.hierarchy.selection', function (require) { +"use strict"; + + var core = require('web.core'); + var relational_fields = require('web.relational_fields'); + var _t = core._t; + var registry = require('web.field_registry'); + + + var FieldSelection = relational_fields.FieldSelection; + + var qweb = core.qweb; + + var HierarchySelection = FieldSelection.extend({ + _renderEdit: function () { + var self = this; + var prom = Promise.resolve() + if (!self.hierarchy_groups) { + prom = this._rpc({ + model: 'account.account.type', + method: 'search_read', + kwargs: { + domain: [], + fields: ['id', 'internal_group', 'display_name'], + }, + }).then(function(arg) { + self.values = _.map(arg, v => [v['id'], v['display_name']]) + self.hierarchy_groups = [ + { + 'name': _t('Balance Sheet'), + 'children': [ + {'name': _t('Assets'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'asset'), v => v['id'])}, + {'name': _t('Liabilities'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'liability'), v => v['id'])}, + {'name': _t('Equity'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'equity'), v => v['id'])}, + ], + }, + { + 'name': _t('Profit & Loss'), + 'children': [ + {'name': _t('Income'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'income'), v => v['id'])}, + {'name': _t('Expense'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'expense'), v => v['id'])}, + ], + }, + {'name': _t('Other'), 'ids': _.map(_.filter(arg, v => !['asset', 'liability', 'equity', 'income', 'expense'].includes(v['internal_group'])), v => v['id'])}, + ] + }); + } + + Promise.resolve(prom).then(function() { + self.$el.empty(); + self._addHierarchy(self.$el, self.hierarchy_groups, 0); + var value = self.value; + if (self.field.type === 'many2one' && value) { + value = value.data.id; + } + self.$el.val(JSON.stringify(value)); + }); + }, + _addHierarchy: function(el, group, level) { + var self = this; + _.each(group, function(item) { + var optgroup = $('').attr(({ + 'label': $('
').html(' '.repeat(6 * level) + item['name']).text(), + })) + _.each(item['ids'], function(id) { + var value = _.find(self.values, v => v[0] == id) + optgroup.append($('