mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[ADD] Adyen statement import
This commit is contained in:
committed by
Ronald Portier (Therp BV)
parent
9c7f36ad5d
commit
80d28d4d57
1
account_bank_statement_clearing_account/__init__.py
Normal file
1
account_bank_statement_clearing_account/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
14
account_bank_statement_clearing_account/__openerp__.py
Normal file
14
account_bank_statement_clearing_account/__openerp__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# coding: utf-8
|
||||
# © 2017 Opener BV (<https://opener.amsterdam>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
{
|
||||
'name': 'Reconcile entries from pseudo bank statements',
|
||||
'version': '8.0.1.0.0',
|
||||
'author': 'Opener B.V.',
|
||||
'category': 'Banking addons',
|
||||
'website': 'https://opener.am',
|
||||
'depends': [
|
||||
'account_cancel',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
from . import account_bank_statement
|
||||
@@ -0,0 +1,80 @@
|
||||
# coding: utf-8
|
||||
from openerp import api, models
|
||||
|
||||
|
||||
class BankStatement(models.Model):
|
||||
_inherit = 'account.bank.statement'
|
||||
|
||||
@api.multi
|
||||
def get_reconcile_clearing_account_lines(self):
|
||||
if (self.journal_id.default_debit_account_id !=
|
||||
self.journal_id.default_credit_account_id or
|
||||
not self.journal_id.default_debit_account_id.reconcile):
|
||||
return False
|
||||
account = self.journal_id.default_debit_account_id
|
||||
currency = self.journal_id.currency or self.company_id.currency_id
|
||||
|
||||
def get_bank_line(st_line):
|
||||
for line in st_line.journal_entry_id.line_id:
|
||||
if st_line.amount > 0:
|
||||
compare_amount = st_line.amount
|
||||
field = 'debit'
|
||||
else:
|
||||
compare_amount = -st_line.amount
|
||||
field = 'credit'
|
||||
if (line[field] and
|
||||
not currency.compare_amounts(
|
||||
line[field], compare_amount) and
|
||||
line.account_id == account):
|
||||
return line
|
||||
return False
|
||||
|
||||
move_lines = self.env['account.move.line']
|
||||
for st_line in self.line_ids:
|
||||
bank_line = get_bank_line(st_line)
|
||||
if not bank_line:
|
||||
return False
|
||||
move_lines += bank_line
|
||||
balance = sum(line.debit - line.credit for line in move_lines)
|
||||
if not currency.is_zero(balance):
|
||||
return False
|
||||
return move_lines
|
||||
|
||||
@api.multi
|
||||
def reconcile_clearing_account(self):
|
||||
self.ensure_one()
|
||||
lines = self.get_reconcile_clearing_account_lines()
|
||||
if not lines:
|
||||
return False
|
||||
if any(line.reconcile_id or line.reconcile_partial_id
|
||||
for line in lines):
|
||||
return False
|
||||
lines.reconcile_partial()
|
||||
|
||||
@api.multi
|
||||
def unreconcile_clearing_account(self):
|
||||
self.ensure_one()
|
||||
lines = self.get_reconcile_clearing_account_lines()
|
||||
if not lines:
|
||||
return False
|
||||
reconciliation = lines[0].reconcile_id
|
||||
if reconciliation and all(
|
||||
line.reconcile_id == reconciliation
|
||||
for line in lines) and all(
|
||||
line in lines
|
||||
for line in reconciliation.line_id):
|
||||
reconciliation.unlink()
|
||||
|
||||
@api.multi
|
||||
def button_draft(self):
|
||||
res = super(BankStatement, self).button_draft()
|
||||
for statement in self:
|
||||
statement.unreconcile_clearing_account()
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def button_confirm_bank(self):
|
||||
res = super(BankStatement, self).button_confirm_bank()
|
||||
for statement in self:
|
||||
statement.reconcile_clearing_account()
|
||||
return res
|
||||
Reference in New Issue
Block a user