mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[IMP] account_payment_order_return: black, isort, prettier
This commit is contained in:
@@ -2,20 +2,14 @@
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
{
|
||||
'name': 'Account Payment Order Return',
|
||||
'version': '12.0.1.1.0',
|
||||
'category': 'Banking addons',
|
||||
'author': 'Tecnativa, '
|
||||
'Odoo Community Association (OCA)',
|
||||
'website': 'https://github.com/OCA/bank-payment',
|
||||
'depends': [
|
||||
'account_payment_return',
|
||||
'account_payment_order',
|
||||
],
|
||||
'data': [
|
||||
'wizards/account_payment_line_create_view.xml',
|
||||
],
|
||||
'license': 'AGPL-3',
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
"name": "Account Payment Order Return",
|
||||
"version": "12.0.1.1.0",
|
||||
"category": "Banking addons",
|
||||
"author": "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/bank-payment",
|
||||
"depends": ["account_payment_return", "account_payment_order",],
|
||||
"data": ["wizards/account_payment_line_create_view.xml",],
|
||||
"license": "AGPL-3",
|
||||
"installable": True,
|
||||
"auto_install": True,
|
||||
}
|
||||
|
||||
@@ -1,95 +1,124 @@
|
||||
# Copyright 2017 Tecnativa - Luis M. Ontalba
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0
|
||||
|
||||
from odoo.tests import common
|
||||
from odoo import fields
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestAccountPaymentOrderReturn(common.SavepointCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAccountPaymentOrderReturn, cls).setUpClass()
|
||||
cls.account_type = cls.env['account.account.type'].create({
|
||||
'name': 'Test Account Type'})
|
||||
cls.a_receivable = cls.env['account.account'].create({
|
||||
'code': 'TAA',
|
||||
'name': 'Test Receivable Account',
|
||||
'internal_type': 'receivable',
|
||||
'user_type_id': cls.account_type.id,
|
||||
})
|
||||
cls.partner = cls.env['res.partner'].create({
|
||||
'name': 'Test Partner 2',
|
||||
'parent_id': False,
|
||||
})
|
||||
cls.journal = cls.env['account.journal'].create({
|
||||
'name': 'Test Journal',
|
||||
'type': 'bank',
|
||||
})
|
||||
cls.invoice = cls.env['account.invoice'].create({
|
||||
'name': 'Test Invoice 3',
|
||||
'partner_id': cls.partner.id,
|
||||
'type': 'out_invoice',
|
||||
'journal_id': cls.journal.id,
|
||||
'invoice_line_ids': [(0, 0, {
|
||||
'account_id': cls.a_receivable.id,
|
||||
'name': 'Test line',
|
||||
'quantity': 1.0,
|
||||
'price_unit': 100.00,
|
||||
})],
|
||||
})
|
||||
cls.payment_mode = cls.env['account.payment.mode'].create({
|
||||
'name': 'Test payment mode',
|
||||
'fixed_journal_id': cls.journal.id,
|
||||
'bank_account_link': 'variable',
|
||||
'payment_method_id': cls.env.ref(
|
||||
'account.account_payment_method_manual_in').id})
|
||||
cls.payment_order = cls.env['account.payment.order'].create({
|
||||
'payment_mode_id': cls.payment_mode.id,
|
||||
'date_prefered': 'due',
|
||||
'payment_type': 'inbound',
|
||||
})
|
||||
cls.account_type = cls.env["account.account.type"].create(
|
||||
{"name": "Test Account Type"}
|
||||
)
|
||||
cls.a_receivable = cls.env["account.account"].create(
|
||||
{
|
||||
"code": "TAA",
|
||||
"name": "Test Receivable Account",
|
||||
"internal_type": "receivable",
|
||||
"user_type_id": cls.account_type.id,
|
||||
}
|
||||
)
|
||||
cls.partner = cls.env["res.partner"].create(
|
||||
{"name": "Test Partner 2", "parent_id": False,}
|
||||
)
|
||||
cls.journal = cls.env["account.journal"].create(
|
||||
{"name": "Test Journal", "type": "bank",}
|
||||
)
|
||||
cls.invoice = cls.env["account.invoice"].create(
|
||||
{
|
||||
"name": "Test Invoice 3",
|
||||
"partner_id": cls.partner.id,
|
||||
"type": "out_invoice",
|
||||
"journal_id": cls.journal.id,
|
||||
"invoice_line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"account_id": cls.a_receivable.id,
|
||||
"name": "Test line",
|
||||
"quantity": 1.0,
|
||||
"price_unit": 100.00,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
cls.payment_mode = cls.env["account.payment.mode"].create(
|
||||
{
|
||||
"name": "Test payment mode",
|
||||
"fixed_journal_id": cls.journal.id,
|
||||
"bank_account_link": "variable",
|
||||
"payment_method_id": cls.env.ref(
|
||||
"account.account_payment_method_manual_in"
|
||||
).id,
|
||||
}
|
||||
)
|
||||
cls.payment_order = cls.env["account.payment.order"].create(
|
||||
{
|
||||
"payment_mode_id": cls.payment_mode.id,
|
||||
"date_prefered": "due",
|
||||
"payment_type": "inbound",
|
||||
}
|
||||
)
|
||||
|
||||
def test_global(self):
|
||||
self.invoice.action_invoice_open()
|
||||
wizard_o = self.env['account.payment.line.create']
|
||||
wizard_o = self.env["account.payment.line.create"]
|
||||
context = wizard_o._context.copy()
|
||||
context.update({
|
||||
'active_model': 'account.payment.order',
|
||||
'active_id': self.payment_order.id,
|
||||
})
|
||||
wizard = wizard_o.with_context(context).create({
|
||||
'order_id': self.payment_order.id,
|
||||
'journal_ids': [(4, self.journal.id)],
|
||||
'allow_blocked': True,
|
||||
'date_type': 'move',
|
||||
'move_date': fields.Date.today(),
|
||||
'payment_mode': 'any',
|
||||
'invoice': True,
|
||||
'include_returned': True,
|
||||
|
||||
})
|
||||
context.update(
|
||||
{
|
||||
"active_model": "account.payment.order",
|
||||
"active_id": self.payment_order.id,
|
||||
}
|
||||
)
|
||||
wizard = wizard_o.with_context(context).create(
|
||||
{
|
||||
"order_id": self.payment_order.id,
|
||||
"journal_ids": [(4, self.journal.id)],
|
||||
"allow_blocked": True,
|
||||
"date_type": "move",
|
||||
"move_date": fields.Date.today(),
|
||||
"payment_mode": "any",
|
||||
"invoice": True,
|
||||
"include_returned": True,
|
||||
}
|
||||
)
|
||||
wizard.populate()
|
||||
self.assertTrue(len(wizard.move_line_ids), 1)
|
||||
self.receivable_line = self.invoice.move_id.line_ids.filtered(
|
||||
lambda x: x.account_id.internal_type == 'receivable')
|
||||
lambda x: x.account_id.internal_type == "receivable"
|
||||
)
|
||||
# Invert the move to simulate the payment
|
||||
self.payment_move = self.invoice.move_id.copy({
|
||||
'journal_id': self.journal.id
|
||||
})
|
||||
self.payment_move = self.invoice.move_id.copy({"journal_id": self.journal.id})
|
||||
for move_line in self.payment_move.line_ids:
|
||||
move_line.with_context(check_move_validity=False).write({
|
||||
'debit': move_line.credit, 'credit': move_line.debit})
|
||||
move_line.with_context(check_move_validity=False).write(
|
||||
{"debit": move_line.credit, "credit": move_line.debit}
|
||||
)
|
||||
self.payment_line = self.payment_move.line_ids.filtered(
|
||||
lambda x: x.account_id.internal_type == 'receivable')
|
||||
lambda x: x.account_id.internal_type == "receivable"
|
||||
)
|
||||
# Reconcile both
|
||||
(self.receivable_line | self.payment_line).reconcile()
|
||||
# Create payment return
|
||||
self.payment_return = self.env['payment.return'].create(
|
||||
{'journal_id': self.journal.id,
|
||||
'line_ids': [
|
||||
(0, 0, {'partner_id': self.partner.id,
|
||||
'move_line_ids': [(6, 0, self.payment_line.ids)],
|
||||
'amount': self.payment_line.credit})]})
|
||||
self.payment_return = self.env["payment.return"].create(
|
||||
{
|
||||
"journal_id": self.journal.id,
|
||||
"line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"partner_id": self.partner.id,
|
||||
"move_line_ids": [(6, 0, self.payment_line.ids)],
|
||||
"amount": self.payment_line.credit,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
self.payment_return.action_confirm()
|
||||
wizard.include_returned = False
|
||||
wizard.populate()
|
||||
|
||||
@@ -5,19 +5,17 @@ from odoo import api, fields, models
|
||||
|
||||
|
||||
class AccountPaymentLineCreate(models.TransientModel):
|
||||
_inherit = 'account.payment.line.create'
|
||||
_inherit = "account.payment.line.create"
|
||||
|
||||
include_returned = fields.Boolean(
|
||||
string='Include move lines from returns')
|
||||
include_returned = fields.Boolean(string="Include move lines from returns")
|
||||
|
||||
@api.multi
|
||||
def _prepare_move_line_domain(self):
|
||||
domain = super(AccountPaymentLineCreate,
|
||||
self)._prepare_move_line_domain()
|
||||
domain = super(AccountPaymentLineCreate, self)._prepare_move_line_domain()
|
||||
if not self.include_returned:
|
||||
domain += [
|
||||
'|',
|
||||
('invoice_id', '=', False),
|
||||
('invoice_id.returned_payment', '=', False)
|
||||
"|",
|
||||
("invoice_id", "=", False),
|
||||
("invoice_id.returned_payment", "=", False),
|
||||
]
|
||||
return domain
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="account_payment_line_create_form" model="ir.ui.view">
|
||||
<field name="inherit_id" ref="account_payment_order.account_payment_line_create_form"/>
|
||||
<field
|
||||
name="inherit_id"
|
||||
ref="account_payment_order.account_payment_line_create_form"
|
||||
/>
|
||||
<field name="model">account.payment.line.create</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="invoice" position="after">
|
||||
<field name="include_returned"/>
|
||||
<field name="include_returned" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user