[IMP] account_reconcile_restrict_partner_mismatch: black, isort

This commit is contained in:
ernestotejeda
2019-11-25 15:07:08 -05:00
parent c80a1f2dfe
commit 00c2e523c4
5 changed files with 89 additions and 85 deletions

View File

@@ -2,18 +2,15 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'Reconcile restrict partner mismatch',
'summary': 'Restrict reconciliation on receivable '
'and payable accounts to the same partner',
'version': '12.0.1.0.0',
'depends': ['account'],
'author': 'Camptocamp, Odoo Community Association (OCA)',
'website': 'http://www.github.com/OCA/account-reconcile',
'category': 'Finance',
'license': 'AGPL-3',
'data': [
'report/account_move_lines_report.xml',
'security/ir.model.access.csv',
],
'installable': True,
"name": "Reconcile restrict partner mismatch",
"summary": "Restrict reconciliation on receivable "
"and payable accounts to the same partner",
"version": "12.0.1.0.0",
"depends": ["account"],
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "http://www.github.com/OCA/account-reconcile",
"category": "Finance",
"license": "AGPL-3",
"data": ["report/account_move_lines_report.xml", "security/ir.model.access.csv"],
"installable": True,
}

View File

@@ -1,7 +1,7 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models, _
from odoo import _, api, models
from odoo.exceptions import UserError
from odoo.tools import config
@@ -11,8 +11,7 @@ class AccountMoveLine(models.Model):
@api.multi
def reconcile(self, writeoff_acc_id=False, writeoff_journal_id=False):
if (config['test_enable']
and not self.env.context.get('test_partner_mismatch')):
if config["test_enable"] and not self.env.context.get("test_partner_mismatch"):
return super().reconcile(writeoff_acc_id, writeoff_journal_id)
# to be consistent with parent method
@@ -20,10 +19,13 @@ class AccountMoveLine(models.Model):
return True
partners = set()
for line in self:
if line.account_id.internal_type in ('receivable', 'payable'):
if line.account_id.internal_type in ("receivable", "payable"):
partners.add(line.partner_id.id)
if len(partners) > 1:
raise UserError(_('The partner has to be the same on all'
' lines for receivable and payable accounts!'))
return super().reconcile(
writeoff_acc_id, writeoff_journal_id)
raise UserError(
_(
"The partner has to be the same on all"
" lines for receivable and payable accounts!"
)
)
return super().reconcile(writeoff_acc_id, writeoff_journal_id)

View File

@@ -5,7 +5,7 @@
<field name="model">account.reconcile.partner.mismatch.report</field>
<field name="arch" type="xml">
<tree string="Reconciled items with partner mismatch" create="false" delete="false" edit="false">
<!-- links are not clickable in tree view
<!-- links are not clickable in tree view
only after open form view -->
<field name="partial_reconcile_id" />
<field name="full_reconcile_id" />

View File

@@ -6,29 +6,22 @@ from odoo import api, fields, models, tools
class AccountReconcilePartnerMismatchReport(models.Model):
_name = 'account.reconcile.partner.mismatch.report'
_description = 'Account Reconcile Partner Mismatch Report'
_name = "account.reconcile.partner.mismatch.report"
_description = "Account Reconcile Partner Mismatch Report"
_auto = False
partial_reconcile_id = fields.Many2one(
'account.partial.reconcile',
string="Partial Reconcile"
"account.partial.reconcile", string="Partial Reconcile"
)
full_reconcile_id = fields.Many2one('account.full.reconcile')
account_id = fields.Many2one(
'account.account',
string="Account"
)
account_type_id = fields.Many2one(
'account.account.type',
string="Account type",
)
debit_move_id = fields.Many2one('account.move.line', string="Debit move")
full_reconcile_id = fields.Many2one("account.full.reconcile")
account_id = fields.Many2one("account.account", string="Account")
account_type_id = fields.Many2one("account.account.type", string="Account type")
debit_move_id = fields.Many2one("account.move.line", string="Debit move")
debit_amount = fields.Float("Debit amount")
debit_partner_id = fields.Many2one('res.partner', string="Debit partner")
credit_move_id = fields.Many2one('account.move.line', string="Credit move")
debit_partner_id = fields.Many2one("res.partner", string="Debit partner")
credit_move_id = fields.Many2one("account.move.line", string="Credit move")
credit_amount = fields.Float("Credit amount")
credit_partner_id = fields.Many2one('res.partner', string="Credit partner")
credit_partner_id = fields.Many2one("res.partner", string="Credit partner")
@api.model_cr
def init(self):

View File

@@ -1,99 +1,111 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.exceptions import UserError
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
class TestReconciliation(AccountingTestCase):
def setUp(self):
super().setUp()
self.env = self.env(context=dict(
self.env.context, tracking_disable=True,
test_partner_mismatch=True)
self.env = self.env(
context=dict(
self.env.context, tracking_disable=True, test_partner_mismatch=True
)
)
self.partner = self.env.ref("base.res_partner_2")
self.partner_id = self.partner.id
rec_type = self.env['account.account'].search([
('user_type_id', '=',
self.env.ref('account.data_account_type_receivable').id)
], limit=1)
pay_type = self.env['account.account'].search([
('user_type_id', '=',
self.env.ref('account.data_account_type_payable').id)
], limit=1)
self.account_rcv = (self.partner.property_account_receivable_id
or rec_type)
rec_type = self.env["account.account"].search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_receivable").id,
)
],
limit=1,
)
pay_type = self.env["account.account"].search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_payable").id,
)
],
limit=1,
)
self.account_rcv = self.partner.property_account_receivable_id or rec_type
self.account_rsa = self.partner.property_account_payable_id or pay_type
self.bank_journal = self.env['account.journal']. \
create({'name': 'Bank', 'type': 'bank', 'code': 'BNK67'})
self.bank_journal = self.env["account.journal"].create(
{"name": "Bank", "type": "bank", "code": "BNK67"}
)
self.aml = self.init_moves()
def create_move(self, name, amount):
debit_line_vals = {
'name': name,
'debit': amount > 0 and amount or 0.0,
'credit': amount < 0 and -amount or 0.0,
'account_id': self.account_rcv.id,
"name": name,
"debit": amount > 0 and amount or 0.0,
"credit": amount < 0 and -amount or 0.0,
"account_id": self.account_rcv.id,
}
credit_line_vals = debit_line_vals.copy()
credit_line_vals['debit'] = debit_line_vals['credit']
credit_line_vals['credit'] = debit_line_vals['debit']
credit_line_vals['account_id'] = self.account_rsa.id
credit_line_vals["debit"] = debit_line_vals["credit"]
credit_line_vals["credit"] = debit_line_vals["debit"]
credit_line_vals["account_id"] = self.account_rsa.id
vals = {
'journal_id': self.bank_journal.id,
'line_ids': [(0, 0, debit_line_vals), (0, 0, credit_line_vals)]
"journal_id": self.bank_journal.id,
"line_ids": [(0, 0, debit_line_vals), (0, 0, credit_line_vals)],
}
return self.env['account.move'].create(vals).id
return self.env["account.move"].create(vals).id
def init_moves(self):
move_list_vals = [
('1', -1.83),
('2', 728.35),
('3', -4.46),
('4', 0.32),
('5', 14.72),
('6', -737.10),
("1", -1.83),
("2", 728.35),
("3", -4.46),
("4", 0.32),
("5", 14.72),
("6", -737.10),
]
move_ids = []
for name, amount in move_list_vals:
move_ids.append(self.create_move(name, amount))
aml_recs = self.env['account.move.line'].search([
('move_id', 'in', move_ids),
('account_id', '=', self.account_rcv.id)
])
aml_recs = self.env["account.move.line"].search(
[("move_id", "in", move_ids), ("account_id", "=", self.account_rcv.id)]
)
return aml_recs
def test_reconcile_no_partner(self):
self.aml.reconcile()
self.assertTrue(all(self.aml.mapped('reconciled')))
self.assertTrue(all(self.aml.mapped("reconciled")))
def test_reconcile_partner_mismatch(self):
self.aml[0].partner_id = self.partner.id
with self.assertRaises(UserError):
self.aml.reconcile()
# all lines with same partner allowed
self.aml.write({'partner_id': self.partner.id})
self.aml.write({"partner_id": self.partner.id})
self.aml.reconcile()
self.assertTrue(all(self.aml.mapped('reconciled')))
self.assertTrue(all(self.aml.mapped("reconciled")))
def test_reconcile_accounts_excluded(self):
self.aml[0].partner_id = self.partner.id
with self.assertRaises(UserError):
self.aml.reconcile()
# reconciliation forbiden only for certain types of accounts
account = self.env['account.account'].search([
('user_type_id.type', '=', 'other')
], limit=1)
account = self.env["account.account"].search(
[("user_type_id.type", "=", "other")], limit=1
)
account.reconcile = True
self.aml[0].account_id = account.id
with self.assertRaises(UserError):
self.aml.reconcile()
# reconciliation for different partners allowed
# for not forbidden types
self.aml.write({'account_id': account.id})
self.aml.write({"account_id": account.id})
self.aml.reconcile()
self.assertTrue(all(self.aml.mapped('reconciled')))
self.assertTrue(all(self.aml.mapped("reconciled")))