[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.
pull/524/head
Akim Juillerat 2019-10-09 15:24:56 +02:00 committed by Dũng (Trần Đình)
parent aa7cad8a0a
commit 4c2dde8c97
7 changed files with 5 additions and 118 deletions

View File

@ -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",

View File

@ -1,4 +1,2 @@
from . import invoice
from . import sale
from . import account_move
from . import account_bank_statement_line

View File

@ -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)

View File

@ -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])

View File

@ -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

View File

@ -1,11 +0,0 @@
<?xml version="1.0"?>
<templates xml:space="preserve">
<t t-extend="reconciliation.line.mv_line">
<t t-jquery=".cell_label" t-operation="append">
<t t-if="line.transaction_ref"> (<t t-esc="line.transaction_ref"/>)</t>
</t>
</t>
</templates>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_move_line_form" model="ir.ui.view">
<field name="name">account.move.line.form</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='full_reconcile_id']/.." position="after">
<field name="transaction_ref"/>
</xpath>
</field>
</record>
</odoo>