[13.0][IMP] account_move_reconcile_helper: black, isort

This commit is contained in:
kittiu
2020-01-06 20:22:00 +07:00
committed by Ethan Hildick
parent b84a0a4e07
commit 334ed4e4de
4 changed files with 101 additions and 93 deletions

View File

@@ -2,16 +2,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Account Move Reconcile Helper', "name": "Account Move Reconcile Helper",
'summary': "Provides tools to facilitate reconciliation", "summary": "Provides tools to facilitate reconciliation",
'version': '12.0.1.0.0', "version": "13.0.1.0.0",
'license': 'AGPL-3', "license": "AGPL-3",
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', "author": "ACSONE SA/NV, Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/account-reconcile', "website": "https://github.com/OCA/account-reconcile",
'depends': [ "depends": ["account_balance_line"],
'account_balance_line', "data": ["views/account_move_line.xml"],
],
'data': [
'views/account_move_line.xml',
],
} }

View File

@@ -6,21 +6,24 @@ from odoo import api, fields, models
class AccountMoveLine(models.Model): class AccountMoveLine(models.Model):
_inherit = 'account.move.line' _inherit = "account.move.line"
partial_reconciliation_in_progress = fields.Boolean( partial_reconciliation_in_progress = fields.Boolean(
compute='_compute_partial_reconciliation_in_progress') compute="_compute_partial_reconciliation_in_progress"
)
reconcile_line_ids = fields.One2many( reconcile_line_ids = fields.One2many(
compute='_compute_reconciled_lines', compute="_compute_reconciled_lines",
comodel_name='account.move.line', comodel_name="account.move.line",
string="Reconciled lines") string="Reconciled lines",
)
@api.multi @api.multi
@api.depends('matched_debit_ids', 'matched_credit_ids') @api.depends("matched_debit_ids", "matched_credit_ids")
def _compute_partial_reconciliation_in_progress(self): def _compute_partial_reconciliation_in_progress(self):
for rec in self: for rec in self:
rec.partial_reconciliation_in_progress = ( rec.partial_reconciliation_in_progress = bool(
bool(rec.matched_debit_ids) or bool(rec.matched_credit_ids)) rec.matched_debit_ids
) or bool(rec.matched_credit_ids)
@api.multi @api.multi
def _compute_reconciled_lines(self): def _compute_reconciled_lines(self):
@@ -45,10 +48,9 @@ class AccountMoveLine(models.Model):
if line.full_reconcile_id: if line.full_reconcile_id:
matched_lines = line.full_reconcile_id.reconciled_line_ids matched_lines = line.full_reconcile_id.reconciled_line_ids
elif line.credit > 0: elif line.credit > 0:
matched_lines = line.matched_debit_ids.mapped('debit_move_id') matched_lines = line.matched_debit_ids.mapped("debit_move_id")
else: else:
matched_lines = line.matched_credit_ids.mapped( matched_lines = line.matched_credit_ids.mapped("credit_move_id")
'credit_move_id')
if not matched_lines: if not matched_lines:
continue continue
@@ -58,14 +60,12 @@ class AccountMoveLine(models.Model):
for matched_line in matched_lines: for matched_line in matched_lines:
if matched_line not in move_lines: if matched_line not in move_lines:
move_lines |= matched_line move_lines |= matched_line
move_lines |= matched_line._get_reconciled_lines( move_lines |= matched_line._get_reconciled_lines(move_lines)
move_lines)
return move_lines return move_lines
@api.multi @api.multi
def open_full_reconcile_view(self): def open_full_reconcile_view(self):
action = self.env.ref('account.action_account_moves_all_a').read()[0] action = self.env.ref("account.action_account_moves_all_a").read()[0]
action['domain'] = [ action["domain"] = [("id", "in", self.mapped("reconcile_line_ids").ids)]
('id', 'in', self.mapped('reconcile_line_ids').ids)]
return action return action

View File

@@ -1 +1,2 @@
* Benjamin Willig <benjamin.willig@acsone.eu> * Benjamin Willig <benjamin.willig@acsone.eu>
* Kitti U. <kittiu@ecosoft.co.th>

View File

@@ -5,71 +5,83 @@ from odoo.tests.common import TransactionCase
class TestAccountMoveReconcileHelper(TransactionCase): class TestAccountMoveReconcileHelper(TransactionCase):
def setUp(self): def setUp(self):
super(TestAccountMoveReconcileHelper, self).setUp() super(TestAccountMoveReconcileHelper, self).setUp()
self.AccountObj = self.env['account.account'] self.AccountObj = self.env["account.account"]
self.AccountJournalObj = self.env['account.journal'] self.AccountJournalObj = self.env["account.journal"]
self.AccountMoveObj = self.env['account.move'] self.AccountMoveObj = self.env["account.move"]
self.AccountMoveLineObj = self.env['account.move.line'] self.AccountMoveLineObj = self.env["account.move.line"]
self.account_type_recv = self.env.ref( self.account_type_recv = self.env.ref("account.data_account_type_receivable")
'account.data_account_type_receivable') self.account_type_rev = self.env.ref("account.data_account_type_revenue")
self.account_type_rev = self.env.ref(
'account.data_account_type_revenue')
self.account_recv = self.AccountObj.create({ self.account_recv = self.AccountObj.create(
'code': 'MRH-RECVT', {
'name': "Receivable (test)", "code": "MRH-RECVT",
'reconcile': True, "name": "Receivable (test)",
'user_type_id': self.account_type_recv.id, "reconcile": True,
}) "user_type_id": self.account_type_recv.id,
self.account_sale = self.AccountObj.create({ }
'code': 'MRH-SALET', )
'name': "Receivable (sale)", self.account_sale = self.AccountObj.create(
'reconcile': True, {
'user_type_id': self.account_type_rev.id, "code": "MRH-SALET",
}) "name": "Receivable (sale)",
"reconcile": True,
"user_type_id": self.account_type_rev.id,
}
)
self.sales_journal = self.AccountJournalObj.create({ self.sales_journal = self.AccountJournalObj.create(
'name': "Sales journal", {
'code': 'MRH-SAJT', "name": "Sales journal",
'type': 'sale', "code": "MRH-SAJT",
'default_credit_account_id': self.account_sale.id, "type": "sale",
'default_debit_account_id': self.account_sale.id, "default_credit_account_id": self.account_sale.id,
}) "default_debit_account_id": self.account_sale.id,
}
)
def create_account_move(self, amount, debit_account, credit_account): def create_account_move(self, amount, debit_account, credit_account):
return self.AccountMoveObj.create({ return self.AccountMoveObj.create(
'journal_id': self.sales_journal.id, {
'line_ids': [ "journal_id": self.sales_journal.id,
(0, 0, { "line_ids": [
'name': "Receivable line", (
'account_id': debit_account.id, 0,
'debit': amount, 0,
}), {
(0, 0, { "name": "Receivable line",
'name': "Sales line", "account_id": debit_account.id,
'account_id': credit_account.id, "debit": amount,
'credit': amount, },
}), ),
] (
}) 0,
0,
{
"name": "Sales line",
"account_id": credit_account.id,
"credit": amount,
},
),
],
}
)
def test_01_partial_reconcile(self): def test_01_partial_reconcile(self):
base_move = self.create_account_move( base_move = self.create_account_move(5000, self.account_recv, self.account_sale)
5000, self.account_recv, self.account_sale)
move1 = self.create_account_move( move1 = self.create_account_move(1000, self.account_sale, self.account_recv)
1000, self.account_sale, self.account_recv)
move2 = self.create_account_move( move2 = self.create_account_move(1000, self.account_sale, self.account_recv)
1000, self.account_sale, self.account_recv)
lines = self.AccountMoveLineObj.search([ lines = self.AccountMoveLineObj.search(
('move_id', 'in', [base_move.id, move1.id, move2.id]), [
('account_id', '=', self.account_recv.id) ("move_id", "in", [base_move.id, move1.id, move2.id]),
]) ("account_id", "=", self.account_recv.id),
]
)
lines.reconcile() lines.reconcile()
@@ -77,23 +89,22 @@ class TestAccountMoveReconcileHelper(TransactionCase):
self.assertEquals(line.reconcile_line_ids, lines) self.assertEquals(line.reconcile_line_ids, lines)
def test_02_full_reconcile(self): def test_02_full_reconcile(self):
base_move = self.create_account_move( base_move = self.create_account_move(5000, self.account_recv, self.account_sale)
5000, self.account_recv, self.account_sale)
move2 = self.create_account_move( move2 = self.create_account_move(2500, self.account_sale, self.account_recv)
2500, self.account_sale, self.account_recv) move3 = self.create_account_move(2500, self.account_sale, self.account_recv)
move3 = self.create_account_move(
2500, self.account_sale, self.account_recv)
lines = self.AccountMoveLineObj.search([ lines = self.AccountMoveLineObj.search(
('move_id', 'in', [base_move.id, move2.id, move3.id]), [
('account_id', '=', self.account_recv.id) ("move_id", "in", [base_move.id, move2.id, move3.id]),
]) ("account_id", "=", self.account_recv.id),
]
)
lines.reconcile() lines.reconcile()
for line in lines: for line in lines:
self.assertEquals(line.reconcile_line_ids, lines) self.assertEquals(line.reconcile_line_ids, lines)
self.assertEquals( self.assertEquals(
line.full_reconcile_id.reconciled_line_ids, line.full_reconcile_id.reconciled_line_ids, line.reconcile_line_ids
line.reconcile_line_ids) )