-
-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10.0] [IMP] base_transaction_id: Add transaction_id on account.payment #183
Merged
OCA-git-bot
merged 3 commits into
OCA:10.0
from
acsone:10.0-transaction_id_account_payment-lmi
Nov 2, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class AccountPayment(models.Model): | ||
|
||
_inherit = 'account.payment' | ||
|
||
transaction_id = fields.Char( | ||
'Transaction ID', | ||
required=False, | ||
copy=False, | ||
help="Transaction id from the financial institute" | ||
) | ||
|
||
invoice_ids = fields.Many2many(inverse='_inverse_invoice_ids') | ||
|
||
@api.multi | ||
def _get_liquidity_move_line_vals(self, amount): | ||
self.ensure_one() | ||
vals = super(AccountPayment, self)._get_liquidity_move_line_vals( | ||
amount) | ||
if self.transaction_id: | ||
vals['name'] = self.transaction_id | ||
vals['transaction_ref'] = self.transaction_id | ||
return vals | ||
|
||
@api.multi | ||
def _inverse_invoice_ids(self): | ||
for rec in self: | ||
invoices = rec.invoice_ids.filtered(lambda x: x.transaction_id) | ||
if not rec.transaction_id and invoices: | ||
rec.transaction_id = ", ".join(invoices.mapped( | ||
'transaction_id')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import test_account_payment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import odoo.tests.common as common | ||
from odoo import fields | ||
|
||
|
||
class TestAccountPayment(common.TransactionCase): | ||
|
||
def test_transaction_id_on_move_line(self): | ||
account_payment = self.env['account.payment'].new({ | ||
'name': 'payment_name' | ||
}) | ||
vals = account_payment._get_liquidity_move_line_vals(10) | ||
self.assertEqual( | ||
vals.get('name'), | ||
'payment_name', | ||
'The name of the move line is the name of the payment if no ' | ||
'transaction_id is specified on the payment') | ||
account_payment.transaction_id = 'transaction id' | ||
vals = account_payment._get_liquidity_move_line_vals(10) | ||
self.assertEqual( | ||
vals.get('name'), | ||
'transaction id', | ||
'The name of the move line is the transaction if of the payment ' | ||
'if specified on the payment') | ||
self.assertEqual( | ||
vals.get('transaction_ref'), | ||
'transaction id', | ||
'The transaction reference of the move line is the transaction if ' | ||
'of the payment ' | ||
'if specified on the payment') | ||
|
||
def test_transaction_id_from_invoice(self): | ||
transaction_ref = '1234568787' | ||
tax = self.env['account.tax'].create({ | ||
'name': 'Tax 10.0', | ||
'amount': 10.0, | ||
'amount_type': 'fixed', | ||
}) | ||
|
||
# Should be changed by automatic on_change later | ||
invoice_account = self.env['account.account'].search( | ||
[('user_type_id', '=', | ||
self.env.ref('account.data_account_type_receivable').id)], | ||
limit=1).id | ||
invoice_line_account = self.env['account.account'].search( | ||
[('user_type_id', '=', | ||
self.env.ref('account.data_account_type_expenses').id)], | ||
limit=1).id | ||
|
||
invoice = self.env['account.invoice'].create( | ||
{'partner_id': self.env.ref('base.res_partner_2').id, | ||
'account_id': invoice_account, | ||
'type': 'out_invoice', | ||
'transaction_id': transaction_ref}) | ||
|
||
self.env['account.invoice.line'].create( | ||
{'product_id': self.env.ref('product.product_product_4').id, | ||
'quantity': 1.0, | ||
'price_unit': 100.0, | ||
'invoice_id': invoice.id, | ||
'name': 'product that cost 100', | ||
'account_id': invoice_line_account, | ||
'invoice_line_tax_ids': [(6, 0, [tax.id])]}) | ||
|
||
# change the state of invoice to open by clicking Validate button | ||
invoice.action_invoice_open() | ||
|
||
journal = self.env['account.journal'].search([('type', '=', 'bank')], | ||
limit=1) | ||
payment = self.env['account.payment'].create({ | ||
'invoice_ids': [(6, 0, invoice.ids)], | ||
'amount': invoice.residual, | ||
'payment_date': fields.Date.today(), | ||
'communication': invoice.reference or invoice.number, | ||
'partner_id': invoice.partner_id.id, | ||
'partner_type': 'customer', | ||
'journal_id': journal.id, | ||
'payment_method_id': self.env.ref( | ||
'account.account_payment_method_manual_in').id, | ||
'payment_type': 'inbound'}) | ||
payment.post() | ||
|
||
self.assertEqual(invoice.state, 'paid') | ||
|
||
move_line = invoice.payment_ids.move_line_ids.filtered( | ||
lambda x: x.account_id.internal_type == 'liquidity') | ||
self.assertEqual(move_line.transaction_ref, transaction_ref) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2017 ACSONE SA/NV | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<odoo> | ||
|
||
<record model="ir.ui.view" id="account_payment_form_view"> | ||
<field name="name">account.payment.form (in base_transaction_id)</field> | ||
<field name="model">account.payment</field> | ||
<field name="inherit_id" ref="account.view_account_payment_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="payment_date" position="after"> | ||
<field name="transaction_id" attrs="{'readonly': [('state', '!=', 'draft')]}"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.ui.view" id="account_payment_tree_view"> | ||
<field name="name">account.payment.tree (in base_transaction_id)</field> | ||
<field name="model">account.payment</field> | ||
<field name="inherit_id" ref="account.view_account_supplier_payment_tree"/> | ||
<field name="arch" type="xml"> | ||
<field name="company_id" position="after"> | ||
<field name="transaction_id"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.ui.view" id="account_payment_search_view"> | ||
<field name="name">account.payment.search (in base_transaction_id)</field> | ||
<field name="model">account.payment</field> | ||
<field name="inherit_id" ref="account.view_account_payment_search"/> | ||
<field name="arch" type="xml"> | ||
<field name="company_id" position="after"> | ||
<field name="transaction_id"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be better to fill transaction_ref (as is done in this module) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transaction_id is actually the transaction reference ...