From b0ee5be6762ce9b3e24660f81bae5a314fbde17f Mon Sep 17 00:00:00 2001 From: "Habib (ayh)" Date: Tue, 19 Jul 2022 13:45:24 +0000 Subject: [PATCH] [IMP] account: account_payment_field wowl migration Part-of: odoo/odoo#96672 --- addons/account/__manifest__.py | 1 + addons/account/models/account_move.py | 8 +- .../static/src/js/account_payment_field.js | 216 +++++++----------- .../src/js/legacy_account_payment_field.js | 149 ++++++++++++ .../static/src/xml/account_payment.xml | 94 ++++---- .../static/src/xml/legacy_account_payment.xml | 109 +++++++++ 6 files changed, 385 insertions(+), 192 deletions(-) create mode 100644 addons/account/static/src/js/legacy_account_payment_field.js create mode 100644 addons/account/static/src/xml/legacy_account_payment.xml diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py index 1e1a6be8b80..2dfa849907f 100644 --- a/addons/account/__manifest__.py +++ b/addons/account/__manifest__.py @@ -97,6 +97,7 @@ You could use this simplified accounting in case you work with an (external) acc 'account/static/src/scss/bills_upload.scss', 'account/static/src/scss/group_view_widget.scss', 'account/static/src/js/account_payment_field.js', + 'account/static/src/js/legacy_account_payment_field.js', 'account/static/src/js/account_resequence_field.js', 'account/static/src/js/grouped_view_widget.js', 'account/static/src/js/mail_activity.js', diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index e05946459d5..04b15ec062e 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1069,11 +1069,9 @@ class AccountMove(models.Model): payments_widget_vals['content'].append({ 'journal_name': line.ref or line.move_id.name, 'amount': amount, - 'currency': move.currency_id.symbol, + 'currency_id': move.currency_id.id, 'id': line.id, 'move_id': line.move_id.id, - 'position': move.currency_id.position, - 'digits': [69, move.currency_id.decimal_places], 'date': fields.Date.to_string(line.date), 'account_payment_id': line.payment_id.id, }) @@ -1103,9 +1101,7 @@ class AccountMove(models.Model): 'name': counterpart_line.name, 'journal_name': counterpart_line.journal_id.name, 'amount': reconciled_partial['amount'], - 'currency': reconciled_partial['currency'].symbol, - 'digits': [69, reconciled_partial['currency'].decimal_places], - 'position': reconciled_partial['currency'].position, + 'currency_id': reconciled_partial['currency'].id, 'date': counterpart_line.date, 'partial_id': reconciled_partial['partial_id'], 'account_payment_id': counterpart_line.payment_id.id, diff --git a/addons/account/static/src/js/account_payment_field.js b/addons/account/static/src/js/account_payment_field.js index c807b45a4a3..ed5a177f5de 100644 --- a/addons/account/static/src/js/account_payment_field.js +++ b/addons/account/static/src/js/account_payment_field.js @@ -1,149 +1,93 @@ -odoo.define('account.payment', function (require) { -"use strict"; +/** @odoo-module **/ -var AbstractField = require('web.AbstractField'); -var core = require('web.core'); -var field_registry = require('web.field_registry'); -var field_utils = require('web.field_utils'); +import { registry } from "@web/core/registry"; +import { usePopover } from "@web/core/popover/popover_hook"; +import { useService } from "@web/core/utils/hooks"; +import { localization } from "@web/core/l10n/localization"; +import { parseDate, formatDate } from "@web/core/l10n/dates"; -var QWeb = core.qweb; -var _t = core._t; +import { formatMonetary } from "@web/views/fields/formatters"; -var ShowPaymentLineWidget = AbstractField.extend({ - events: _.extend({ - 'click .outstanding_credit_assign': '_onOutstandingCreditAssign', - 'click .open_account_move': '_onOpenPaymentOrMove', - }, AbstractField.prototype.events), - supportedFieldTypes: ['char'], +const { Component, onWillUpdateProps } = owl; - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- +class AccountPaymentPopOver extends Component {} +AccountPaymentPopOver.template = "account.AccountPaymentPopOver"; - /** - * @override - * @returns {boolean} - */ - isSet: function() { - return true; - }, +export class AccountPaymentField extends Component { + setup() { + this.popover = usePopover(); + this.orm = useService("orm"); + this.action = useService("action"); - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- + this.formatData(this.props); + onWillUpdateProps((nextProps) => this.formatData(nextProps)); + } - /** - * @private - * @override - */ - _render: function() { - this.viewAlreadyOpened = false; - var self = this; - var info = 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})); + formatData(props) { + const info = props.value || { + content: [], + outstanding: false, + title: "", + move_id: this.props.record.data.id, + }; + for (let [key, value] of Object.entries(info.content)) { + value.index = key; + value.amount_formatted = formatMonetary(value.amount, { currencyId: value.currency_id }); + if (value.date) { + // value.date is a string, parse to date and format to the users date format + value.date = formatDate(parseDate(value.date)); } - }); - 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)); - $content.filter('.js_unreconcile_payment').on('click', self._onRemoveMoveReconcile.bind(self)); - - $content.filter('.js_open_payment').on('click', self._onOpenPaymentOrMove.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 - */ - _onOpenPaymentOrMove: function (event) { - var moveId = parseInt($(event.target).attr('move-id')); - if (!this.viewAlreadyOpened && moveId !== undefined && !isNaN(moveId)) { - this.viewAlreadyOpened = true; - var self = this; - this._rpc({ - model: 'account.move', - method: 'open_move', - args: [moveId], - }).then(function (actionData) { - return self.do_action(actionData); - }); } - }, - /** - * @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: [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'); - }); + this.lines = info.content; + this.outstanding = info.outstanding; + this.title = info.title; + this.move_id = info.move_id; + } + + onInfoClick(ev, idx) { + if (this.popoverCloseFn) { + this.closePopover(); } - }, -}); + this.popoverCloseFn = this.popover.add( + ev.currentTarget, + AccountPaymentPopOver, + { + title: this.env._t("Journal Entry Info"), + ...this.lines[idx], + _onRemoveMoveReconcile: this.removeMoveReconcile.bind(this), + _onOpenMove: this.openMove.bind(this), + onClose: this.closePopover, + }, + { + position: localization.direction === "rtl" ? "bottom" : "left", + }, + ); + } -field_registry.add('payment', ShowPaymentLineWidget); + closePopover() { + this.popoverCloseFn(); + this.popoverCloseFn = null; + } -return { - ShowPaymentLineWidget: ShowPaymentLineWidget -}; + async assignOutstandingCredit(id) { + await this.orm.call(this.props.record.resModel, 'js_assign_outstanding_line', [this.move_id, id], {}); + await this.props.record.model.root.load(); + this.props.record.model.notify(); + } -}); + async removeMoveReconcile(moveId, partialId) { + this.closePopover(); + await this.orm.call(this.props.record.resModel, 'js_remove_outstanding_partial', [moveId, partialId], {}); + await this.props.record.model.root.load(); + this.props.record.model.notify(); + } + + async openMove(moveId) { + const action = await this.orm.call(this.props.record.resModel, 'open_move', [moveId], {}); + this.action.doAction(action); + } +} +AccountPaymentField.template = "account.AccountPaymentField"; +AccountPaymentField.supportedTypes = ["char"]; + +registry.category("fields").add("payment", AccountPaymentField); diff --git a/addons/account/static/src/js/legacy_account_payment_field.js b/addons/account/static/src/js/legacy_account_payment_field.js new file mode 100644 index 00000000000..d130ced6837 --- /dev/null +++ b/addons/account/static/src/js/legacy_account_payment_field.js @@ -0,0 +1,149 @@ +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', + 'click .open_account_move': '_onOpenPaymentOrMove', + }, AbstractField.prototype.events), + supportedFieldTypes: ['char'], + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * @override + * @returns {boolean} + */ + isSet: function() { + return true; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + * @override + */ + _render: function() { + this.viewAlreadyOpened = false; + var self = this; + var info = 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)); + $content.filter('.js_unreconcile_payment').on('click', self._onRemoveMoveReconcile.bind(self)); + + $content.filter('.js_open_payment').on('click', self._onOpenPaymentOrMove.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 + */ + _onOpenPaymentOrMove: function (event) { + var moveId = parseInt($(event.target).attr('move-id')); + if (!this.viewAlreadyOpened && moveId !== undefined && !isNaN(moveId)) { + this.viewAlreadyOpened = true; + var self = this; + this._rpc({ + model: 'account.move', + method: 'open_move', + args: [moveId], + }).then(function (actionData) { + return self.do_action(actionData); + }); + } + }, + /** + * @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: [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/xml/account_payment.xml b/addons/account/static/src/xml/account_payment.xml index 182068e121f..617825b79d2 100644 --- a/addons/account/static/src/xml/account_payment.xml +++ b/addons/account/static/src/xml/account_payment.xml @@ -2,7 +2,7 @@ - +
@@ -10,7 +10,7 @@
- + @@ -72,38 +61,43 @@ - -
-
@@ -20,7 +20,8 @@ t-att-data-id="line.id" style="margin-right: 0px; padding-left: 5px; padding-right: 5px;" href="#" - data-bs-toggle="tooltip">Add + data-bs-toggle="tooltip" + t-on-click.prevent="() => this.assignOutstandingCredit(line.id)">Add - + Paid on @@ -43,27 +44,15 @@ - - - - - - - + - Exchange Difference + Exchange Difference - - - - - - - +
- - - - - - - - - - - - - - - - -
Amount: - - - ( ) - -
Memo: -
- -
-
Date:
Journal: ()
+ + - - diff --git a/addons/account/static/src/xml/legacy_account_payment.xml b/addons/account/static/src/xml/legacy_account_payment.xml new file mode 100644 index 00000000000..182068e121f --- /dev/null +++ b/addons/account/static/src/xml/legacy_account_payment.xml @@ -0,0 +1,109 @@ + + + + + +
+ +
+ +
+
+ + + + + + + + + + + + + + + +
+ Add + + + + + Paid on + + + + + + + + + + + + Exchange Difference + + + + + + + + + + + +
+
+
+ + +
+ + + + + + + + + + + + + + + + + +
Amount: + + + ( ) + +
Memo: +
+ +
+
Date:
Journal: ()
+
+ + +
+ +