From 4c2dde8c97ecb47e9b889bb64cabff9322719918 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Wed, 9 Oct 2019 15:24:56 +0200 Subject: [PATCH] [12.0] base_transaction_id: Fix migration Module is broken since its migration as the hooks used for reconciliation are not used anymore in Odoo 12.0. Therefore transaction_ref is dropped from account.move.line and transaction_id is now written into account.move.ref at invoice validation to allow the use of standard Odoo mechanism in the reconciliation process. As Odoo defined invoice_payment_ref on account.move in v13.0, avoiding extra fields in v12.0 is already a step in the right direction. --- base_transaction_id/__manifest__.py | 5 -- base_transaction_id/models/__init__.py | 2 - .../models/account_bank_statement_line.py | 27 ----------- base_transaction_id/models/account_move.py | 46 ------------------- base_transaction_id/models/invoice.py | 19 ++------ .../static/src/xml/account_reconciliation.xml | 11 ----- .../views/account_move_line.xml | 13 ------ 7 files changed, 5 insertions(+), 118 deletions(-) delete mode 100644 base_transaction_id/models/account_bank_statement_line.py delete mode 100644 base_transaction_id/models/account_move.py delete mode 100644 base_transaction_id/static/src/xml/account_reconciliation.xml delete mode 100644 base_transaction_id/views/account_move_line.xml diff --git a/base_transaction_id/__manifest__.py b/base_transaction_id/__manifest__.py index 81d94ef8..a5b7c4bc 100644 --- a/base_transaction_id/__manifest__.py +++ b/base_transaction_id/__manifest__.py @@ -1,6 +1,5 @@ # Copyright 2019 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) - { "name": "Base transaction ID for financial institutes", "version": "12.0.1.0.0", @@ -14,10 +13,6 @@ "data": [ "views/invoice.xml", "views/sale.xml", - "views/account_move_line.xml", - ], - "qweb": [ - "static/src/xml/account_reconciliation.xml", ], "installable": True, "license": "AGPL-3", diff --git a/base_transaction_id/models/__init__.py b/base_transaction_id/models/__init__.py index 9ddf32e7..4fc3dbe3 100644 --- a/base_transaction_id/models/__init__.py +++ b/base_transaction_id/models/__init__.py @@ -1,4 +1,2 @@ from . import invoice from . import sale -from . import account_move -from . import account_bank_statement_line diff --git a/base_transaction_id/models/account_bank_statement_line.py b/base_transaction_id/models/account_bank_statement_line.py deleted file mode 100644 index 15256cc7..00000000 --- a/base_transaction_id/models/account_bank_statement_line.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2019 Camptocamp SA -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) - - -from odoo import api, models - - -class AccountBankStatementLine(models.Model): - - _inherit = 'account.bank.statement.line' - - @api.multi - def get_reconciliation_proposition(self, excluded_ids=None): - """Look for transaction_ref to give them as proposition move line.""" - self.ensure_one() - if self.name: - # If the transaction has no partner, look for match in payable and - # receivable account anyway - overlook_partner = not self.partner_id - domain = [('transaction_ref', 'ilike', self.name)] - match_recs = self.get_move_lines_for_reconciliation( - excluded_ids=excluded_ids, limit=2, additional_domain=domain, - overlook_partner=overlook_partner) - if match_recs and len(match_recs) == 1: - return match_recs - _super = super() - return _super.get_reconciliation_proposition(excluded_ids=excluded_ids) diff --git a/base_transaction_id/models/account_move.py b/base_transaction_id/models/account_move.py deleted file mode 100644 index 651edfbe..00000000 --- a/base_transaction_id/models/account_move.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2019 Camptocamp SA -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) - - -from odoo import models, fields, api -from odoo.osv import expression - - -class AccountMoveLine(models.Model): - _inherit = 'account.move.line' - - transaction_ref = fields.Char( - 'Transaction Ref.', - index=True, - copy=False - ) - - @api.multi - def prepare_move_lines_for_reconciliation_widget(self, - target_currency=False, - target_date=False): - prepared_lines = [] - for line in self: - _super = super(AccountMoveLine, line) - # The super method loop over the lines and returns a list of - # prepared lines. Here we'll have 1 line per call to super. - # If we called super on the whole list, we would need to - # browse again the lines, or match the 'lines' vs - # 'prepared_lines' to update the transaction_ref. - vals = _super.prepare_move_lines_for_reconciliation_widget( - target_currency=target_currency, - target_date=target_date)[0] - vals['transaction_ref'] = line.transaction_ref - prepared_lines.append(vals) - return prepared_lines - - @api.model - def domain_move_lines_for_reconciliation(self, str=False): - """Add transaction_ref in search of move lines.""" - _super = super() - _get_domain = _super.domain_move_lines_for_reconciliation - domain = _get_domain(str=str) - if not str and str != '/': - return domain - domain_trans_ref = [('transaction_ref', 'ilike', str)] - return expression.OR([domain, domain_trans_ref]) diff --git a/base_transaction_id/models/invoice.py b/base_transaction_id/models/invoice.py index 6d481fcb..d7aae172 100644 --- a/base_transaction_id/models/invoice.py +++ b/base_transaction_id/models/invoice.py @@ -15,19 +15,10 @@ class AccountInvoice(models.Model): "financial institute") @api.multi - def finalize_invoice_move_lines(self, move_lines): - """Propagate the transaction_id from the invoice to the move lines. - - The transaction ID is written on the move lines only if the account is - the same than the invoice's one. - """ - move_lines = super().finalize_invoice_move_lines( - move_lines) + def action_move_create(self): + """Propagate the transaction_id from the invoice to the move ref.""" + res = super().action_move_create() for invoice in self: if invoice.transaction_id: - invoice_account_id = invoice.account_id.id - for line in move_lines: - # line is a tuple (0, 0, {values}) - if invoice_account_id == line[2]['account_id']: - line[2]['transaction_ref'] = invoice.transaction_id - return move_lines + invoice.move_id.ref = invoice.transaction_id + return res diff --git a/base_transaction_id/static/src/xml/account_reconciliation.xml b/base_transaction_id/static/src/xml/account_reconciliation.xml deleted file mode 100644 index 9f320b98..00000000 --- a/base_transaction_id/static/src/xml/account_reconciliation.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - () - - - - diff --git a/base_transaction_id/views/account_move_line.xml b/base_transaction_id/views/account_move_line.xml deleted file mode 100644 index 632153ca..00000000 --- a/base_transaction_id/views/account_move_line.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - account.move.line.form - account.move.line - - - - - - - -