-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by gurneyalex
- Loading branch information
Showing
7 changed files
with
174 additions
and
2 deletions.
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> |