diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/account/static/src/js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/account/static/src/js')
| -rw-r--r-- | addons/account/static/src/js/account_dashboard_setup_bar.js | 0 | ||||
| -rw-r--r-- | addons/account/static/src/js/account_payment_field.js | 156 | ||||
| -rw-r--r-- | addons/account/static/src/js/account_portal_sidebar.js | 73 | ||||
| -rw-r--r-- | addons/account/static/src/js/account_resequence_field.js | 32 | ||||
| -rw-r--r-- | addons/account/static/src/js/account_selection.js | 80 | ||||
| -rw-r--r-- | addons/account/static/src/js/bank_statement.js | 21 | ||||
| -rw-r--r-- | addons/account/static/src/js/bills_tree_upload.js | 127 | ||||
| -rw-r--r-- | addons/account/static/src/js/grouped_view_widget.js | 40 | ||||
| -rw-r--r-- | addons/account/static/src/js/mail_activity.js | 69 | ||||
| -rw-r--r-- | addons/account/static/src/js/section_and_note_fields_backend.js | 106 | ||||
| -rw-r--r-- | addons/account/static/src/js/tax_group.js | 171 | ||||
| -rw-r--r-- | addons/account/static/src/js/tours/account.js | 93 |
12 files changed, 968 insertions, 0 deletions
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 --- /dev/null +++ b/addons/account/static/src/js/account_dashboard_setup_bar.js 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 = $('<optgroup/>').attr(({ + 'label': $('<div/>').html(' '.repeat(6 * level) + item['name']).text(), + })) + _.each(item['ids'], function(id) { + var value = _.find(self.values, v => v[0] == id) + optgroup.append($('<option/>', { + value: JSON.stringify(value[0]), + text: value[1], + })); + }) + el.append(optgroup) + if (item['children']) { + self._addHierarchy(el, item['children'], level + 1); + } + }) + } + }); + registry.add("account_hierarchy_selection", HierarchySelection); +}); diff --git a/addons/account/static/src/js/bank_statement.js b/addons/account/static/src/js/bank_statement.js new file mode 100644 index 00000000..3ab8d935 --- /dev/null +++ b/addons/account/static/src/js/bank_statement.js @@ -0,0 +1,21 @@ +odoo.define('account.bank_statement', function(require) { + "use strict"; + + var KanbanController = require("web.KanbanController"); + var ListController = require("web.ListController"); + + var includeDict = { + renderButtons: function () { + this._super.apply(this, arguments); + if (this.modelName === "account.bank.statement") { + var data = this.model.get(this.handle); + if (data.context.journal_type !== 'cash') { + this.$buttons.find('button.o_button_import').hide(); + } + } + } + }; + + KanbanController.include(includeDict); + ListController.include(includeDict); +});
\ No newline at end of file diff --git a/addons/account/static/src/js/bills_tree_upload.js b/addons/account/static/src/js/bills_tree_upload.js new file mode 100644 index 00000000..2894b868 --- /dev/null +++ b/addons/account/static/src/js/bills_tree_upload.js @@ -0,0 +1,127 @@ +odoo.define('account.upload.bill.mixin', function (require) { +"use strict"; + + var core = require('web.core'); + var _t = core._t; + + var qweb = core.qweb; + + var UploadBillMixin = { + + start: function () { + // define a unique uploadId and a callback method + this.fileUploadID = _.uniqueId('account_bill_file_upload'); + $(window).on(this.fileUploadID, this._onFileUploaded.bind(this)); + return this._super.apply(this, arguments); + }, + + _onAddAttachment: function (ev) { + // Auto submit form once we've selected an attachment + var $input = $(ev.currentTarget).find('input.o_input_file'); + if ($input.val() !== '') { + var $binaryForm = this.$('.o_vendor_bill_upload form.o_form_binary_form'); + $binaryForm.submit(); + } + }, + + _onFileUploaded: function () { + // Callback once attachment have been created, create a bill with attachment ids + var self = this; + var attachments = Array.prototype.slice.call(arguments, 1); + // Get id from result + var attachent_ids = attachments.reduce(function(filtered, record) { + if (record.id) { + filtered.push(record.id); + } + return filtered; + }, []); + return this._rpc({ + model: 'account.journal', + method: 'create_invoice_from_attachment', + args: ["", attachent_ids], + context: this.initialState.context, + }).then(function(result) { + self.do_action(result); + }); + }, + + _onUpload: function (event) { + var self = this; + // If hidden upload form don't exists, create it + var $formContainer = this.$('.o_content').find('.o_vendor_bill_upload'); + if (!$formContainer.length) { + $formContainer = $(qweb.render('account.BillsHiddenUploadForm', {widget: this})); + $formContainer.appendTo(this.$('.o_content')); + } + // Trigger the input to select a file + this.$('.o_vendor_bill_upload .o_input_file').click(); + }, + } + return UploadBillMixin; +}); + + +odoo.define('account.bills.tree', function (require) { +"use strict"; + var core = require('web.core'); + var ListController = require('web.ListController'); + var ListView = require('web.ListView'); + var UploadBillMixin = require('account.upload.bill.mixin'); + var viewRegistry = require('web.view_registry'); + + var BillsListController = ListController.extend(UploadBillMixin, { + buttons_template: 'BillsListView.buttons', + events: _.extend({}, ListController.prototype.events, { + 'click .o_button_upload_bill': '_onUpload', + 'change .o_vendor_bill_upload .o_form_binary_form': '_onAddAttachment', + }), + }); + + var BillsListView = ListView.extend({ + config: _.extend({}, ListView.prototype.config, { + Controller: BillsListController, + }), + }); + + viewRegistry.add('account_tree', BillsListView); +}); + +odoo.define('account.dashboard.kanban', function (require) { +"use strict"; + var core = require('web.core'); + var KanbanController = require('web.KanbanController'); + var KanbanView = require('web.KanbanView'); + var UploadBillMixin = require('account.upload.bill.mixin'); + var viewRegistry = require('web.view_registry'); + + var DashboardKanbanController = KanbanController.extend(UploadBillMixin, { + events: _.extend({}, KanbanController.prototype.events, { + 'click .o_button_upload_bill': '_onUpload', + 'change .o_vendor_bill_upload .o_form_binary_form': '_onAddAttachment', + }), + /** + * We override _onUpload (from the upload bill mixin) to pass default_journal_id + * and default_move_type in context. + * + * @override + */ + _onUpload: function (event) { + var kanbanRecord = $(event.currentTarget).closest('.o_kanban_record').data('record'); + this.initialState.context['default_journal_id'] = kanbanRecord.id; + if ($(event.currentTarget).attr('journal_type') == 'sale') { + this.initialState.context['default_move_type'] = 'out_invoice' + } else if ($(event.currentTarget).attr('journal_type') == 'purchase') { + this.initialState.context['default_move_type'] = 'in_invoice' + } + UploadBillMixin._onUpload.apply(this, arguments); + } + }); + + var DashboardKanbanView = KanbanView.extend({ + config: _.extend({}, KanbanView.prototype.config, { + Controller: DashboardKanbanController, + }), + }); + + viewRegistry.add('account_dashboard_kanban', DashboardKanbanView); +}); diff --git a/addons/account/static/src/js/grouped_view_widget.js b/addons/account/static/src/js/grouped_view_widget.js new file mode 100644 index 00000000..e1df30cf --- /dev/null +++ b/addons/account/static/src/js/grouped_view_widget.js @@ -0,0 +1,40 @@ +odoo.define('account.ShowGroupedList', 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 ListItem extends Component { } +ListItem.template = 'account.GroupedItemTemplate'; +ListItem.props = ["item_vals", "options"]; + +class ListGroup extends Component { } +ListGroup.template = 'account.GroupedItemsTemplate'; +ListGroup.components = { ListItem } +ListGroup.props = ["group_vals", "options"]; + + +class ShowGroupedList extends AbstractFieldOwl { + constructor(...args) { + super(...args); + this.data = this.value ? JSON.parse(this.value) : { + groups_vals: [], + options: { + discarded_number: '', + columns: [], + }, + }; + } + async willUpdateProps(nextProps) { + await super.willUpdateProps(nextProps); + Object.assign(this.data, JSON.parse(this.value)); + } +} +ShowGroupedList.template = 'account.GroupedListTemplate'; +ShowGroupedList.components = { ListGroup } + +field_registry.add('grouped_view_widget', ShowGroupedList); +return ShowGroupedList; +}); diff --git a/addons/account/static/src/js/mail_activity.js b/addons/account/static/src/js/mail_activity.js new file mode 100644 index 00000000..8b84afda --- /dev/null +++ b/addons/account/static/src/js/mail_activity.js @@ -0,0 +1,69 @@ +odoo.define('account.activity', function (require) { +"use strict"; + +var AbstractField = require('web.AbstractField'); +var core = require('web.core'); +var field_registry = require('web.field_registry'); + +var QWeb = core.qweb; +var _t = core._t; + +var VatActivity = AbstractField.extend({ + className: 'o_journal_activity_kanban', + events: { + 'click .see_all_activities': '_onOpenAll', + 'click .see_activity': '_onOpenActivity', + }, + init: function () { + this.MAX_ACTIVITY_DISPLAY = 5; + this._super.apply(this, arguments); + }, + //------------------------------------------------------------ + // Private + //------------------------------------------------------------ + _render: function () { + var self = this; + var info = JSON.parse(this.value); + if (!info) { + this.$el.html(''); + return; + } + info.more_activities = false; + if (info.activities.length > this.MAX_ACTIVITY_DISPLAY) { + info.more_activities = true; + info.activities = info.activities.slice(0, this.MAX_ACTIVITY_DISPLAY); + } + this.$el.html(QWeb.render('accountJournalDashboardActivity', info)); + }, + + _onOpenActivity: function(e) { + e.preventDefault(); + var self = this; + self.do_action({ + type: 'ir.actions.act_window', + name: _t('Journal Entry'), + target: 'current', + res_id: $(e.target).data('resId'), + res_model: 'account.move', + views: [[false, 'form']], + }); + }, + + _onOpenAll: function(e) { + e.preventDefault(); + var self = this; + self.do_action({ + type: 'ir.actions.act_window', + name: _t('Journal Entries'), + res_model: 'account.move', + views: [[false, 'kanban'], [false, 'form']], + search_view_id: [false], + domain: [['journal_id', '=', self.res_id], ['activity_ids', '!=', false]], + }); + } +}) + +field_registry.add('kanban_vat_activity', VatActivity); + +return VatActivity; +}); diff --git a/addons/account/static/src/js/section_and_note_fields_backend.js b/addons/account/static/src/js/section_and_note_fields_backend.js new file mode 100644 index 00000000..749d29fc --- /dev/null +++ b/addons/account/static/src/js/section_and_note_fields_backend.js @@ -0,0 +1,106 @@ + +odoo.define('account.section_and_note_backend', function (require) { +// The goal of this file is to contain JS hacks related to allowing +// section and note on sale order and invoice. + +// [UPDATED] now also allows configuring products on sale order. + +"use strict"; +var FieldChar = require('web.basic_fields').FieldChar; +var FieldOne2Many = require('web.relational_fields').FieldOne2Many; +var fieldRegistry = require('web.field_registry'); +var ListFieldText = require('web.basic_fields').ListFieldText; +var ListRenderer = require('web.ListRenderer'); + +var SectionAndNoteListRenderer = ListRenderer.extend({ + /** + * We want section and note to take the whole line (except handle and trash) + * to look better and to hide the unnecessary fields. + * + * @override + */ + _renderBodyCell: function (record, node, index, options) { + var $cell = this._super.apply(this, arguments); + + var isSection = record.data.display_type === 'line_section'; + var isNote = record.data.display_type === 'line_note'; + + if (isSection || isNote) { + if (node.attrs.widget === "handle") { + return $cell; + } else if (node.attrs.name === "name") { + var nbrColumns = this._getNumberOfCols(); + if (this.handleField) { + nbrColumns--; + } + if (this.addTrashIcon) { + nbrColumns--; + } + $cell.attr('colspan', nbrColumns); + } else { + $cell.removeClass('o_invisible_modifier'); + return $cell.addClass('o_hidden'); + } + } + + return $cell; + }, + /** + * We add the o_is_{display_type} class to allow custom behaviour both in JS and CSS. + * + * @override + */ + _renderRow: function (record, index) { + var $row = this._super.apply(this, arguments); + + if (record.data.display_type) { + $row.addClass('o_is_' + record.data.display_type); + } + + return $row; + }, + /** + * We want to add .o_section_and_note_list_view on the table to have stronger CSS. + * + * @override + * @private + */ + _renderView: function () { + var self = this; + return this._super.apply(this, arguments).then(function () { + self.$('.o_list_table').addClass('o_section_and_note_list_view'); + }); + } +}); + +// We create a custom widget because this is the cleanest way to do it: +// to be sure this custom code will only impact selected fields having the widget +// and not applied to any other existing ListRenderer. +var SectionAndNoteFieldOne2Many = FieldOne2Many.extend({ + /** + * We want to use our custom renderer for the list. + * + * @override + */ + _getRenderer: function () { + if (this.view.arch.tag === 'tree') { + return SectionAndNoteListRenderer; + } + return this._super.apply(this, arguments); + }, +}); + +// This is a merge between a FieldText and a FieldChar. +// We want a FieldChar for section, +// and a FieldText for the rest (product and note). +var SectionAndNoteFieldText = function (parent, name, record, options) { + var isSection = record.data.display_type === 'line_section'; + var Constructor = isSection ? FieldChar : ListFieldText; + return new Constructor(parent, name, record, options); +}; + +fieldRegistry.add('section_and_note_one2many', SectionAndNoteFieldOne2Many); +fieldRegistry.add('section_and_note_text', SectionAndNoteFieldText); + +return SectionAndNoteListRenderer; +}); diff --git a/addons/account/static/src/js/tax_group.js b/addons/account/static/src/js/tax_group.js new file mode 100644 index 00000000..a9de7f9f --- /dev/null +++ b/addons/account/static/src/js/tax_group.js @@ -0,0 +1,171 @@ +odoo.define('account.tax_group', function (require) { + "use strict"; + + var core = require('web.core'); + var session = require('web.session'); + var fieldRegistry = require('web.field_registry'); + var AbstractField = require('web.AbstractField'); + var fieldUtils = require('web.field_utils'); + var QWeb = core.qweb; + + var TaxGroupCustomField = AbstractField.extend({ + events: { + 'click .tax_group_edit': '_onClick', + 'keydown .oe_tax_group_editable .tax_group_edit_input input': '_onKeydown', + 'blur .oe_tax_group_editable .tax_group_edit_input input': '_onBlur', + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * This method is called by "_setTaxGroups". It is + * responsible for calculating taxes based on + * tax groups and triggering an event to + * notify the ORM of a change. + * + * @param {Id} taxGroupId + * @param {Float} deltaAmount + */ + _changeTaxValueByTaxGroup: function (taxGroupId, deltaAmount) { + var self = this; + // Search for the first tax line with the same tax group and modify its value + var line_id = self.record.data.line_ids.data.find(elem => elem.data.tax_group_id && elem.data.tax_group_id.data.id === taxGroupId); + + var debitAmount = 0; + var creditAmount = 0; + var amount_currency = 0; + if (line_id.data.currency_id) { // If multi currency enable + if (this.record.data.move_type === "in_invoice") { + amount_currency = line_id.data.amount_currency - deltaAmount; + } else { + amount_currency = line_id.data.amount_currency + deltaAmount; + } + } else { + var balance = line_id.data.price_subtotal; + balance -= deltaAmount; + if (this.record.data.move_type === "in_invoice") { // For vendor bill + if (balance > 0) { + debitAmount = balance; + } else if (balance < 0) { + creditAmount = -balance; + } + } else { // For refund + if (balance > 0) { + creditAmount = balance; + } else if (balance < 0) { + debitAmount = -balance; + } + } + } + // Trigger ORM + self.trigger_up('field_changed', { + dataPointID: self.record.id, + changes: { line_ids: { operation: "UPDATE", id: line_id.id, data: { amount_currency: amount_currency, debit: debitAmount, credit: creditAmount } } }, // account.move change + initialEvent: { dataPointID: line_id.id, changes: { amount_currency: amount_currency, debit: debitAmount, credit: creditAmount }, }, // account.move.line change + }); + }, + + /** + * This method checks that the document where the widget + * is located is of the "in_invoice" or "in_refund" type. + * This makes it possible to know if it is a purchase + * document. + * + * @returns boolean (true if the invoice is a purchase document) + */ + _isPurchaseDocument: function () { + return this.record.data.move_type === "in_invoice" || this.record.data.move_type === 'in_refund'; + }, + + /** + * This method is part of the widget life cycle and allows you to render + * the widget. + * + * @private + * @override + */ + _render: function () { + var self = this; + // Display the pencil and allow the event to click and edit only on purchase that are not posted and in edit mode. + // since the field is readonly its mode will always be readonly. Therefore we have to use a trick by checking the + // formRenderer (the parent) and check if it is in edit in order to know the correct mode. + var displayEditWidget = self._isPurchaseDocument() && this.record.data.state === 'draft' && this.getParent().mode === 'edit'; + this.$el.html($(QWeb.render('AccountTaxGroupTemplate', { + lines: self.value, + displayEditWidget: displayEditWidget, + }))); + }, + + //-------------------------------------------------------------------------- + // Handler + //-------------------------------------------------------------------------- + + /** + * This method is called when the user is in edit mode and + * leaves the <input> field. Then, we execute the code that + * modifies the information. + * + * @param {event} ev + */ + _onBlur: function (ev) { + ev.preventDefault(); + var $input = $(ev.target); + var newValue = $input.val(); + var currency = session.get_currency(this.record.data.currency_id.data.id); + try { + newValue = fieldUtils.parse.float(newValue); // Need a float for format the value. + newValue = fieldUtils.format.float(newValue, null, {digits: currency.digits}); // return a string rounded to currency precision + newValue = fieldUtils.parse.float(newValue); // convert back to Float to compare with oldValue to know if value has changed + } catch (err) { + $input.addClass('o_field_invalid'); + return; + } + var oldValue = $input.data('originalValue'); + if (newValue === oldValue || newValue === 0) { + return this._render(); + } + var taxGroupId = $input.parents('.oe_tax_group_editable').data('taxGroupId'); + this._changeTaxValueByTaxGroup(taxGroupId, oldValue-newValue); + }, + + /** + * This method is called when the user clicks on a specific <td>. + * it will hide the edit button and display the field to be edited. + * + * @param {event} ev + */ + _onClick: function (ev) { + ev.preventDefault(); + var $taxGroupElement = $(ev.target).parents('.oe_tax_group_editable'); + // Show input and hide previous element + $taxGroupElement.find('.tax_group_edit').addClass('d-none'); + $taxGroupElement.find('.tax_group_edit_input').removeClass('d-none'); + var $input = $taxGroupElement.find('.tax_group_edit_input input'); + // Get original value and display it in user locale in the input + var formatedOriginalValue = fieldUtils.format.float($input.data('originalValue'), {}, {}); + $input.focus(); // Focus the input + $input.val(formatedOriginalValue); //add value in user locale to the input + }, + + /** + * This method is called when the user is in edit mode and pressing + * a key on his keyboard. If this key corresponds to ENTER or TAB, + * the code that modifies the information is executed. + * + * @param {event} ev + */ + _onKeydown: function (ev) { + switch (ev.which) { + // Trigger only if the user clicks on ENTER or on TAB. + case $.ui.keyCode.ENTER: + case $.ui.keyCode.TAB: + // trigger blur to prevent the code being executed twice + $(ev.target).blur(); + } + }, + + }); + fieldRegistry.add('tax-group-custom-field', TaxGroupCustomField) +}); diff --git a/addons/account/static/src/js/tours/account.js b/addons/account/static/src/js/tours/account.js new file mode 100644 index 00000000..e854f1c3 --- /dev/null +++ b/addons/account/static/src/js/tours/account.js @@ -0,0 +1,93 @@ +odoo.define('account.tour', function(require) { +"use strict"; + +var core = require('web.core'); +var tour = require('web_tour.tour'); + +var _t = core._t; + +tour.register('account_tour', { + url: "/web", + sequence: 60, +}, [ + ...tour.stepUtils.goToAppSteps('account.menu_finance', _t('Send invoices to your customers in no time with the <b>Invoicing app</b>.')), + { + trigger: "a.o_onboarding_step_action[data-method=action_open_base_onboarding_company]", + content: _t("Start by checking your company's data."), + position: "bottom", + }, { + trigger: "button[name=action_save_onboarding_company_step]", + extra_trigger: "a.o_onboarding_step_action[data-method=action_open_base_onboarding_company]", + content: _t("Looks good. Let's continue."), + position: "left", + }, { + trigger: "a.o_onboarding_step_action[data-method=action_open_base_document_layout]", + content: _t("Customize your layout."), + position: "bottom", + }, { + trigger: "button[name=document_layout_save]", + extra_trigger: "a.o_onboarding_step_action[data-method=action_open_base_document_layout]", + content: _t("Once everything is as you want it, validate."), + position: "left", + }, { + trigger: "a.o_onboarding_step_action[data-method=action_open_account_onboarding_create_invoice]", + content: _t("Now, we'll create your first invoice."), + position: "bottom", + }, { + trigger: "div[name=partner_id] input", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Write a company name to <b>create one</b> or <b>see suggestions</b>."), + position: "bottom", + }, { + trigger: ".o_m2o_dropdown_option a:contains('Create')", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Select first partner"), + auto: true, + }, { + trigger: ".modal-content button.btn-primary", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Once everything is set, you are good to continue. You will be able to edit this later in the <b>Customers</b> menu."), + auto: true, + }, { + trigger: "div[name=invoice_line_ids] .o_field_x2many_list_row_add a:not([data-context])", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Add a line to your invoice"), + }, { + trigger: "div[name=invoice_line_ids] textarea[name=name]", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Fill in the details of the line."), + position: "bottom", + }, { + trigger: "div[name=invoice_line_ids] input[name=price_unit]", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Set a price"), + position: "bottom", + run: 'text 100', + }, { + trigger: "button[name=action_post]", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Once your invoice is ready, press CONFIRM."), + }, { + trigger: "button[name=action_invoice_sent]", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Send the invoice and check what the customer will receive."), + }, { + trigger: "input[name=email]", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Write here <b>your own email address</b> to test the flow."), + run: 'text customer@example.com', + auto: true, + }, { + trigger: ".modal-content button.btn-primary", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Validate."), + auto: true, + }, { + trigger: "button[name=send_and_print_action]", + extra_trigger: "[name=move_type][raw-value=out_invoice]", + content: _t("Let's send the invoice."), + position: "left" + } +]); + +}); |
