From 7f6d1a2ec6d0361479a53d03676208c197458a9c Mon Sep 17 00:00:00 2001 From: kelvzxu Date: Wed, 26 Jan 2022 16:59:11 +0700 Subject: [PATCH] [15.0][MIG] account_reconciliation_widget:Migration to 15.0 --- account_reconciliation_widget/__manifest__.py | 18 ++-- .../models/account_bank_statement.py | 74 ++++++----------- .../models/reconciliation_widget.py | 25 +++--- .../static/description/index.html | 9 +- .../js/reconciliation/reconciliation_model.js | 30 +++---- .../static/src/xml/account_reconciliation.xml | 22 ++--- .../tests/account_reconciliation_tests.js | 32 +++++--- .../views/account_bank_statement_view.xml | 40 +++++---- .../views/account_journal_dashboard_view.xml | 82 +++++++++---------- .../views/account_view.xml | 46 +++++------ .../views/assets.xml | 42 ---------- 11 files changed, 183 insertions(+), 237 deletions(-) delete mode 100644 account_reconciliation_widget/views/assets.xml diff --git a/account_reconciliation_widget/__manifest__.py b/account_reconciliation_widget/__manifest__.py index 33bf216c..b2384249 100644 --- a/account_reconciliation_widget/__manifest__.py +++ b/account_reconciliation_widget/__manifest__.py @@ -3,7 +3,7 @@ { "name": "account_reconciliation_widget", - "version": "14.0.1.2.0", + "version": "15.0.1.1.1", "category": "Accounting", "license": "AGPL-3", "summary": "Account reconciliation widget", @@ -12,13 +12,21 @@ "depends": ["account"], "data": [ "security/ir.model.access.csv", - "views/assets.xml", "views/account_view.xml", "views/account_bank_statement_view.xml", "views/account_journal_dashboard_view.xml", ], - "qweb": [ - "static/src/xml/account_reconciliation.xml", - ], + "assets": { + "web.assets_backend": [ + "account_reconciliation_widget/static/src/scss/account_reconciliation.scss", + "account_reconciliation_widget/static/src/js/reconciliation**/*", + ], + "web.qunit_suite_tests": [ + "account_reconciliation_widget/static/tests/**/*", + ], + "web.assets_qweb": [ + "account_reconciliation_widget/static/src/xml/account_reconciliation.xml", + ], + }, "installable": True, } diff --git a/account_reconciliation_widget/models/account_bank_statement.py b/account_reconciliation_widget/models/account_bank_statement.py index 1a942e12..e27203dc 100644 --- a/account_reconciliation_widget/models/account_bank_statement.py +++ b/account_reconciliation_widget/models/account_bank_statement.py @@ -7,7 +7,7 @@ class AccountBankStatement(models.Model): _inherit = "account.bank.statement" accounting_date = fields.Date( - string="Accounting Date", + string="Financial Date", help="If set, the accounting entries created during the bank statement " "reconciliation process will be created at this date.\n" "This is useful if the accounting period in which the entries should " @@ -33,15 +33,14 @@ class AccountBankStatementLine(models.Model): _inherit = "account.bank.statement.line" - # FIXME: is this necessary now? move_name = fields.Char( string="Journal Entry Name", readonly=True, default=False, copy=False, - help="Technical field holding the number given to the journal entry, " - "automatically set when the statement line is reconciled then " - "stored to set the same number again if the line is cancelled, " + help="Technical field holding the number given to the journal entry," + "automatically set when the statement line is reconciled then stored" + "to set the same number again if the line is cancelled," "set to draft and re-processed again.", ) @@ -130,27 +129,9 @@ class AccountBankStatementLine(models.Model): and user_type_id not in account_types ): account_types |= user_type_id - # FIXME: review - # if suspense_moves_mode: - # if any(not line.journal_entry_ids for line in self): - # raise UserError( - # _( - # "Some selected statement line were not already " - # "reconciled with an account move." - # ) - # ) - # else: - # if any(line.journal_entry_ids for line in self): - # raise UserError( - # _( - # "A selected statement line was already reconciled with " - # "an account move." - # ) - # ) - # Fully reconciled moves are just linked to the bank statement total = self.amount - currency = self.foreign_currency_id or statement_currency + currency = self.currency_id or statement_currency for aml_rec in payment_aml_rec: balance = ( aml_rec.amount_currency if aml_rec.currency_id else aml_rec.balance @@ -163,11 +144,8 @@ class AccountBankStatementLine(models.Model): {"statement_line_id": self.id} ) counterpart_moves = counterpart_moves | aml_rec.move_id - if ( - aml_rec.journal_id.post_at == "bank_rec" - and aml_rec.payment_id - and aml_rec.move_id.state == "draft" - ): + # Update + if aml_rec.payment_id and aml_rec.move_id.state == "draft": # In case the journal is set to only post payments when # performing bank reconciliation, we modify its date and post # it. @@ -180,8 +158,8 @@ class AccountBankStatementLine(models.Model): self._check_invoice_state(invoice) # Create move line(s). Either matching an existing journal entry - # (eg. invoice), in which case we reconcile the existing and the new - # move lines together, or being a write-off. + # (eg. invoice), in which case we reconcile the existing and the + # new move lines together, or being a write-off. if counterpart_aml_dicts or new_aml_dicts: counterpart_moves = self._create_counterpart_and_new_aml( counterpart_moves, counterpart_aml_dicts, new_aml_dicts @@ -200,9 +178,9 @@ class AccountBankStatementLine(models.Model): ) # create the res.partner.bank if needed - if self.account_number and self.partner_id and not self.partner_bank_id: - # Search bank account without partner to handle the case the - # res.partner.bank already exists but is set on a different partner. + if self.account_number and self.partner_id and not self.bank_account_id: + # Search bank account without partner to handle the case the res.partner.bank + # already exists but is set on a different partner. self.partner_bank_id = self._find_or_create_bank_account() counterpart_moves._check_balanced() @@ -252,7 +230,7 @@ class AccountBankStatementLine(models.Model): aml_to_reconcile.append((new_aml, counterpart_move_line)) # Post to allow reconcile - if self.move_id.state != "posted": + if self.move_id.state == "draft": self.move_id.with_context( skip_account_move_synchronization=True ).action_post() @@ -264,7 +242,10 @@ class AccountBankStatementLine(models.Model): self._check_invoice_state(counterpart_move_line.move_id) # Needs to be called manually as lines were created 1 by 1 - self.move_id.update_lines_tax_exigibility() + if self.move_id.state == "draft": + self.move_id.with_context( + skip_account_move_synchronization=True + ).action_post() # record the move name on the statement line to be able to retrieve # it in case of unreconciliation self.write({"move_name": self.move_id.name}) @@ -275,9 +256,9 @@ class AccountBankStatementLine(models.Model): self.ensure_one() company_currency = self.journal_id.company_id.currency_id statement_currency = self.journal_id.currency_id or company_currency - st_line_currency = self.foreign_currency_id or statement_currency + st_line_currency = self.currency_id or statement_currency st_line_currency_rate = ( - self.foreign_currency_id and (self.amount_currency / self.amount) or False + self.currency_id and (self.amount_currency / self.amount) or False ) company = self.company_id @@ -285,21 +266,19 @@ class AccountBankStatementLine(models.Model): aml_dict["amount_currency"] = aml_dict["debit"] - aml_dict["credit"] aml_dict["currency_id"] = st_line_currency.id if ( - self.foreign_currency_id + self.currency_id and statement_currency.id == company_currency.id and st_line_currency_rate ): - # Statement is in company currency but the transaction is in - # foreign currency + # Statement is in company currency but the transaction is in foreign currency aml_dict["debit"] = company_currency.round( aml_dict["debit"] / st_line_currency_rate ) aml_dict["credit"] = company_currency.round( aml_dict["credit"] / st_line_currency_rate ) - elif self.foreign_currency_id and st_line_currency_rate: - # Statement is in foreign currency and the transaction is in - # another one + elif self.currency_id and st_line_currency_rate: + # Statement is in foreign currency and the transaction is in another one aml_dict["debit"] = statement_currency._convert( aml_dict["debit"] / st_line_currency_rate, company_currency, @@ -313,8 +292,8 @@ class AccountBankStatementLine(models.Model): date, ) else: - # Statement is in foreign currency and no extra currency is - # given for the transaction + # Statement is in foreign currency and no extra currency is given + # for the transaction aml_dict["debit"] = st_line_currency._convert( aml_dict["debit"], company_currency, company, date ) @@ -322,8 +301,7 @@ class AccountBankStatementLine(models.Model): aml_dict["credit"], company_currency, company, date ) elif statement_currency.id != company_currency.id: - # Statement is in foreign currency but the transaction is in company - # currency + # Statement is in foreign currency but the transaction is in company currency prorata_factor = ( aml_dict["debit"] - aml_dict["credit"] ) / self.amount_currency diff --git a/account_reconciliation_widget/models/reconciliation_widget.py b/account_reconciliation_widget/models/reconciliation_widget.py index 105de0ea..c049934b 100644 --- a/account_reconciliation_widget/models/reconciliation_widget.py +++ b/account_reconciliation_widget/models/reconciliation_widget.py @@ -1,4 +1,5 @@ import copy +import logging from psycopg2 import sql @@ -7,6 +8,8 @@ from odoo.exceptions import UserError from odoo.osv import expression from odoo.tools.misc import format_date, formatLang, parse_date +_logger = logging.getLogger(__name__) + class AccountReconciliation(models.AbstractModel): _name = "account.reconciliation.widget" @@ -46,7 +49,7 @@ class AccountReconciliation(models.AbstractModel): st_line.write({"partner_id": datum["partner_id"]}) ctx["default_to_check"] = datum.get("to_check") - moves = st_line.with_context(ctx).process_reconciliation( + moves = st_line.with_context(**ctx).process_reconciliation( datum.get("counterpart_aml_dicts", []), payment_aml_rec, datum.get("new_aml_dicts", []), @@ -135,7 +138,7 @@ class AccountReconciliation(models.AbstractModel): recs_count = 0 aml_recs = self.env["account.move.line"].browse([i[0] for i in res]) target_currency = ( - st_line.foreign_currency_id + st_line.currency_id or st_line.journal_id.currency_id or st_line.journal_id.company_id.currency_id ) @@ -157,9 +160,7 @@ class AccountReconciliation(models.AbstractModel): self.env["res.partner.bank"]._apply_ir_rules(ir_rules_query, "read") from_clause, where_clause, where_clause_params = ir_rules_query.get_sql() if where_clause: - where_bank = ("AND %s" % where_clause).replace( - '"res_partner_bank"', '"bank"' - ) + where_bank = ("AND %s" % where_clause).replace("res_partner_bank", "bank") params += where_clause_params else: where_bank = "" @@ -171,7 +172,7 @@ class AccountReconciliation(models.AbstractModel): self.env["res.partner"]._apply_ir_rules(ir_rules_query, "read") from_clause, where_clause, where_clause_params = ir_rules_query.get_sql() if where_clause: - where_partner = ("AND %s" % where_clause).replace('"res_partner"', '"p3"') + where_partner = ("AND %s" % where_clause).replace("res_partner", "p3") params += where_clause_params else: where_partner = "" @@ -257,7 +258,7 @@ class AccountReconciliation(models.AbstractModel): aml_ids = matching_amls[line.id]["aml_ids"] bank_statements_left += line.statement_id target_currency = ( - line.foreign_currency_id + line.currency_id or line.journal_id.currency_id or line.journal_id.company_id.currency_id ) @@ -710,7 +711,7 @@ class AccountReconciliation(models.AbstractModel): ] str_domain = expression.OR([str_domain, amount_domain]) except Exception: - pass + _logger.warning(Exception) else: try: amount = float(search_str) @@ -735,7 +736,7 @@ class AccountReconciliation(models.AbstractModel): ] str_domain = expression.OR([str_domain, amount_domain]) except Exception: - pass + _logger.warning(Exception) return str_domain @api.model @@ -1021,7 +1022,7 @@ class AccountReconciliation(models.AbstractModel): statement_currency = ( st_line.journal_id.currency_id or st_line.journal_id.company_id.currency_id ) - if st_line.amount_currency and st_line.foreign_currency_id: + if st_line.amount_currency and st_line.currency_id: amount = st_line.amount_currency amount_currency = st_line.amount amount_currency_str = formatLang( @@ -1034,7 +1035,7 @@ class AccountReconciliation(models.AbstractModel): amount_str = formatLang( self.env, abs(amount), - currency_obj=st_line.foreign_currency_id or statement_currency, + currency_obj=st_line.currency_id or statement_currency, ) data = { @@ -1046,7 +1047,7 @@ class AccountReconciliation(models.AbstractModel): "date": format_date(self.env, st_line.date), "amount": amount, "amount_str": amount_str, # Amount in the statement line currency - "currency_id": st_line.foreign_currency_id.id or statement_currency.id, + "currency_id": st_line.currency_id.id or statement_currency.id, "partner_id": st_line.partner_id.id, "journal_id": st_line.journal_id.id, "statement_id": st_line.statement_id.id, diff --git a/account_reconciliation_widget/static/description/index.html b/account_reconciliation_widget/static/description/index.html index 3668040e..585dbd33 100644 --- a/account_reconciliation_widget/static/description/index.html +++ b/account_reconciliation_widget/static/description/index.html @@ -367,8 +367,8 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/account-reconcile Translate me on Weblate Try me on Runbot

-

This module restores account reconciliation widget moved from Odoo community to enterpise in V. 14.0 +

Beta License: AGPL-3 OCA/account-reconcile Translate me on Weblate Try me on Runbot

+

This module restores account reconciliation widget moved from Odoo community to enterpise in V. 15.0 Provides two widgets designed to reconcile move lines in a easy way: one focused on bank statements and another for generic use.

Table of contents

@@ -396,7 +396,7 @@ Provides two widgets designed to reconcile move lines in a easy way: one focused

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -412,6 +412,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Contributors

@@ -421,7 +422,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/account-reconcile project on GitHub.

+

This module is part of the OCA/account-reconcile project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/account_reconciliation_widget/static/src/js/reconciliation/reconciliation_model.js b/account_reconciliation_widget/static/src/js/reconciliation/reconciliation_model.js index 23c96fad..5e670574 100644 --- a/account_reconciliation_widget/static/src/js/reconciliation/reconciliation_model.js +++ b/account_reconciliation_widget/static/src/js/reconciliation/reconciliation_model.js @@ -144,7 +144,7 @@ odoo.define("account.ReconciliationModel", function (require) { this._addProposition(line, prop); line["mv_lines_" + line.mode] = _.filter( line["mv_lines_" + line.mode], - (l) => l.id != mv_line_id + (l) => l.id !== mv_line_id ); // Remove all non valid lines @@ -159,7 +159,7 @@ odoo.define("account.ReconciliationModel", function (require) { if ( !line.st_line.partner_id && line.reconciliation_proposition && - line.reconciliation_proposition.length == 1 && + line.reconciliation_proposition.length === 1 && prop.partner_id && line.type === undefined ) { @@ -175,12 +175,12 @@ odoo.define("account.ReconciliationModel", function (require) { this._performMoveLine( handle, "match_rp", - line.mode == "match_rp" ? 1 : 0 + line.mode === "match_rp" ? 1 : 0 ), this._performMoveLine( handle, "match_other", - line.mode == "match_other" ? 1 : 0 + line.mode === "match_other" ? 1 : 0 ), ]); }, @@ -282,7 +282,7 @@ odoo.define("account.ReconciliationModel", function (require) { .then(function () { if (line.st_line.partner_id) { _.each(line.reconciliation_proposition, function (prop) { - if (prop.partner_id != line.st_line.partner_id) { + if (prop.partner_id !== line.st_line.partner_id) { line.reconciliation_proposition = []; return false; } @@ -728,7 +728,7 @@ odoo.define("account.ReconciliationModel", function (require) { // No proposition left and then, reset the st_line partner. if ( - line.reconciliation_proposition.length == 0 && + line.reconciliation_proposition.length === 0 && line.st_line.has_no_partner ) defs.push(self.changePartner(line.handle)); @@ -1009,7 +1009,7 @@ odoo.define("account.ReconciliationModel", function (require) { ); _.each(self.lines, function (other_line) { - if (other_line != line) { + if (other_line !== line) { var filtered_prop = other_line.reconciliation_proposition.filter( (p) => @@ -1018,7 +1018,7 @@ odoo.define("account.ReconciliationModel", function (require) { .includes(p.id) ); if ( - filtered_prop.length != + filtered_prop.length !== other_line.reconciliation_proposition.length ) { other_line.need_update = true; @@ -1305,7 +1305,7 @@ odoo.define("account.ReconciliationModel", function (require) { : false, account_code: self.accounts[line.st_line.open_balance_account_id], }; - line.balance.show_balance = line.balance.amount_currency != 0; + line.balance.show_balance = line.balance.amount_currency !== 0; line.balance.type = line.balance.amount_currency ? line.st_line.partner_id ? 0 @@ -1427,7 +1427,7 @@ odoo.define("account.ReconciliationModel", function (require) { var hasDifferentPartners = function (prop) { return ( !prop.partner_id || - prop.partner_id != + prop.partner_id !== line.reconciliation_proposition[0] .partner_id ); @@ -1517,13 +1517,13 @@ odoo.define("account.ReconciliationModel", function (require) { ); if (mv_lines[0]) { line["remaining_" + mode] = mv_lines[0].recs_count - mv_lines.length; - } else if (line["mv_lines_" + mode].lenght == 0) { + } else if (line["mv_lines_" + mode].lenght === 0) { line["remaining_" + mode] = 0; } this._formatLineProposition(line, mv_lines); if ( - (line.mode == "match_other" || line.mode == "match_rp") && + (line.mode === "match_other" || line.mode === "match_rp") && !line["mv_lines_" + mode].length && !line["filter_" + mode].length ) { @@ -1598,10 +1598,10 @@ odoo.define("account.ReconciliationModel", function (require) { amount = (line.balance.amount * values.amount) / 100; break; case "regex": - var matching = line.st_line.payment_ref.match( + var matching = line.st_line.name.match( new RegExp(values.amount_string) ); - if (matching && matching.length == 2) { + if (matching && matching.length === 2) { matching = matching[1].replace( new RegExp("\\D" + reconcileModel.decimal_separator, "g"), "" @@ -2158,7 +2158,7 @@ odoo.define("account.ReconciliationModel", function (require) { // No proposition left and then, reset the st_line partner. if ( - line.reconciliation_proposition.length == 0 && + line.reconciliation_proposition.length === 0 && line.st_line.has_no_partner ) defs.push(self.changePartner(line.handle)); diff --git a/account_reconciliation_widget/static/src/xml/account_reconciliation.xml b/account_reconciliation_widget/static/src/xml/account_reconciliation.xml index 668421af..96a7c82e 100644 --- a/account_reconciliation_widget/static/src/xml/account_reconciliation.xml +++ b/account_reconciliation_widget/static/src/xml/account_reconciliation.xml @@ -155,10 +155,10 @@ t-esc="state.st_line.amount_currency_str" />) @@ -290,7 +290,7 @@ t-att-data-content="state.balance.amount_currency_str" t-att-aria-label="state.balance.amount_currency_str" t-att-title="state.balance.amount_currency_str" - /> + /> + /> @@ -463,7 +463,7 @@ t-if="line.partial_amount && line.partial_amount != line.amount" class="strike_amount text-muted" > - +
@@ -472,10 +472,10 @@
- + @@ -532,17 +532,17 @@ /> Date Due Date - Journal + Journal Partner Label Ref - AmountAmount () Residual - ( () @@ -563,7 +563,7 @@ t-esc="state.st_line.ref" /> Description - AmountAmount () Account - - - account.bank.statement.inherit.view.form - account.bank.statement - - - - - - - - -
- -
- - - -
+ + + account.journal.inherit.dashboard.kanban + account.journal + + + + + + + + + +
+ - - - - - +
+ + + +
+
+
+
+
+
diff --git a/account_reconciliation_widget/views/account_view.xml b/account_reconciliation_widget/views/account_view.xml index 2b1f8dab..e1f7e177 100644 --- a/account_reconciliation_widget/views/account_view.xml +++ b/account_reconciliation_widget/views/account_view.xml @@ -1,30 +1,28 @@ - - - Reconciliation on Bank Statements - account.bank.statement.line - bank_statement_reconciliation_view - + + Reconciliation on Bank Statements + account.bank.statement.line + bank_statement_reconciliation_view + - - Reconcile - manual_reconciliation_view - - action - list - + + Reconcile + manual_reconciliation_view + + action + list + - - Reconciliation - manual_reconciliation_view - + + Reconciliation + manual_reconciliation_view + - - + diff --git a/account_reconciliation_widget/views/assets.xml b/account_reconciliation_widget/views/assets.xml deleted file mode 100644 index 453a0d3b..00000000 --- a/account_reconciliation_widget/views/assets.xml +++ /dev/null @@ -1,42 +0,0 @@ - - -