Skip to content

Commit

Permalink
Merge pull request #61 from ecino/emanuel
Browse files Browse the repository at this point in the history
Move camt054 module and small fixes
  • Loading branch information
ecino authored Sep 4, 2018
2 parents ecb75bd + 11a53f7 commit a678ddb
Show file tree
Hide file tree
Showing 22 changed files with 916 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ virtualenv:


install:
- pip install -r requirements.txt
- git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<sheet>
<group>
<field name="sequence"/>
<field name="analytic_tag_id"/>
</group>
<group colspan="2">
<field name="account_distribution_line_ids" required="1">
Expand All @@ -36,6 +35,7 @@
</group>
<group string="Conditions">
<field name="account_tag_id"/>
<field name="analytic_tag_id"/>
<field name="date_start"/>
<field name="date_stop"/>
</group>
Expand Down
26 changes: 26 additions & 0 deletions l10n_ch_import_camt054/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

Switzerland camt 054 and transfert account reconcile
====================================================

This module allow you to import camt 054 and reconcile all lines in the transfert account.

** Features list :**
* import camt 054
* refuse the import of a camt 054 file when the NtryRef field is different from the original camt 054
* Add children in school to employee
* New function to reconcile automatically all the lines from the transfert account

** Remarks :**
To use the reconcilion function you need to make a cron. You can do it in the menu : ```Settings->Automation->Scheduled Actions```
and create a new action. The object needed to reach the new function is : ```account.bank.statement.line``` and the function name is : ```camt054_reconcile```.
The unique parameter is the transfert account number, for example : ```("1099",)```

Known issues / Roadmap
======================

Contributors
------------

* Marco Monzione
2 changes: 2 additions & 0 deletions l10n_ch_import_camt054/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

from . import models
21 changes: 21 additions & 0 deletions l10n_ch_import_camt054/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
{
'name': 'CAMT 054 import and reconcile',
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'author': 'Monzione Marco, Odoo Community Association (OCA)',
'website': '...',
'category': 'Banking addons',
'depends': [
'account_bank_statement_import_camt_details',
'l10n_ch_fds_postfinance',
'account_payment_line_cancel',
],
'data': [
'views/account_bank_statement_line_test.xml',
],
'demo': [
'demo/test_data.yml',
],
'installable': True,
}
81 changes: 81 additions & 0 deletions l10n_ch_import_camt054/demo/test_data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Create bank
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
!record {model: res.bank, id: bank_post, view: False}:
name: 'Postfinance AG'
bic: 'POFICHBEXXX'
street: 'Postfinance'
zip: '3030'
city: 'Bern'
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Create accounts types
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
!record {model: account.account.type, id: account_type_post, view: False}:
name: 'Bilan : Liquidites et titres'
type: 'liquidity'
-
!record {model: account.account.type, id: account_type_asset, view: False}:
name: 'Asset'
type: 'other'
-
!record {model: account.account.type, id: account_type_debiteur, view: False}:
name: 'Bilan : Debiteurs'
type: 'receivable'
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Create account
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
!record {model: account.account, id: post_account, view: False}:
code: '1010'
name: 'Postal Account CHF '
reconcile: True
user_type_id: account_type_post
-
!record {model: account.account, id: post_account_lsv, view: False}:
code: '1098'
name: 'transfert lsv dd'
reconcile: True
user_type_id: account_type_asset
-
!record {model: account.account, id: post_account_receivable, view: False}:
code: '1050'
name: 'Receivables'
reconcile: True
user_type_id: account_type_debiteur
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Create partner banks
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
!record {model: res.partner.bank, id: company_bank_post, view: False}:
acc_type: 'postal'
acc_number: 'CH0110100001101001000'
partner_id: base.main_partner #YourCompany
bank_id: bank_post
-
!record {model: res.partner.bank, id: company_bank_lsv_transfert, view: False}:
acc_type: 'postal'
acc_number: '01-010101-1'
partner_id: base.main_partner #YourCompany
bank_id: bank_post
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Create journals
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
!record {model: account.journal, id: post_account_journal, view: False}:
name: 'Postal account'
type: bank
bank_account_id: company_bank_post
update_posted: True
default_debit_account_id: post_account
default_credit_account_id: post_account
-
!record {model: account.journal, id: lsv_account_journal, view: False}:
name: 'LSV test'
type: bank
bank_account_id: company_bank_lsv_transfert
update_posted: True
default_debit_account_id: post_account_lsv
default_credit_account_id: post_account_lsv

6 changes: 6 additions & 0 deletions l10n_ch_import_camt054/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . import custom_parser
from . import account_bank_statement_line
from . import account_move_line
from . import fds_postfinance_file_camt
from . import custom_import_stmt
from . import account_bank_statement
15 changes: 15 additions & 0 deletions l10n_ch_import_camt054/models/account_bank_statement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from odoo import models


class AccountBankStatement(models.Model):
_inherit = 'account.bank.statement'

# Todo shoud autoreconcile at the close of a statement
# def button_confirm_bank(self):
#
# account_bank_stmt_line_obj = self.env['account.bank.statement.line']
#
# super(AccountBankStatement, self).button_confirm_bank()
#
# account_bank_stmt_line_obj.camt054_reconcile(self.journal_id.default_debit_account_id.code)
69 changes: 69 additions & 0 deletions l10n_ch_import_camt054/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
"""Add process_camt method to account.bank.statement.import."""
# © 2017 Compassion CH <http://www.compassion.ch>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields


class AccountBankStatementLine(models.Model):
"""Add process_camt method to account.bank.statement.import."""
_inherit = 'account.bank.statement.line'

acct_svcr_ref = fields.Char()

def process_reconciliation(self, counterpart_aml_dicts=None,
payment_aml_rec=None, new_aml_dicts=None):
counterpart_moves = super(
AccountBankStatementLine, self).process_reconciliation(
counterpart_aml_dicts, payment_aml_rec, new_aml_dicts)

if hasattr(self, 'acct_svcr_ref') and self.acct_svcr_ref:
for move_line in counterpart_moves.line_ids:
move_line.acct_svcr_ref = self.acct_svcr_ref

return counterpart_moves

def _prepare_reconciliation_move_line(self, move, amount):
data = super(AccountBankStatementLine, self).\
_prepare_reconciliation_move_line(move, amount)
# Add the acct svcr ref to both move line.
data['acct_svcr_ref'] = self.acct_svcr_ref
return data

def camt054_reconcile(self, account_code):
move_line_obj = self.env['account.move.line']

move_line_list = move_line_obj.search([
('reconciled', '!=', 'False'),
('account_id.code', '=', account_code),
('acct_svcr_ref', '!=', None)
])

list_line = dict()

# Group each line by acct_svcr_ref
for line in move_line_list:
acct_svcr_ref = line.acct_svcr_ref

# Add the acct_svcr_ref to the list if it's not already present
if acct_svcr_ref not in list_line:
list_line[acct_svcr_ref] = []
# If it is already present we add the line the the list of
# this acct_svcr_ref
list_line[acct_svcr_ref].append(line)

for list_acct_svcr_ref in list_line:

credit = 0
debit = 0
move_line_list = move_line_obj.search([
('acct_svcr_ref', '=', list_acct_svcr_ref),
('reconciled', '!=', 'False'),
('account_id.code', '=', account_code)])

# Check if credit = debit
for line in move_line_list:
credit += line.credit
debit += line.debit
if credit == debit:
move_line_list.reconcile()
10 changes: 10 additions & 0 deletions l10n_ch_import_camt054/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# © 2017 Compassion CH <http://www.compassion.ch>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields


class AccountMoveLine(models.Model):
_inherit = 'account.move.line'
# The new field would be use for an automatic reconciliation.
acct_svcr_ref = fields.Char()
54 changes: 54 additions & 0 deletions l10n_ch_import_camt054/models/custom_import_stmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
from odoo import api, models

import base64


class AccountStatementImportCustomCamt053(models.TransientModel):
_inherit = 'account.bank.statement.import'

@api.model
def _complete_stmts_vals(self, stmts_vals, journal, account_number):
# When a return transaction is found, it search for the
# opposite transaction (same ref).

stmts_vals = super(AccountStatementImportCustomCamt053, self).\
_complete_stmts_vals(stmts_vals, journal, account_number)

list_transactions = stmts_vals[0]['transactions']

for transaction in list_transactions:
if transaction.get('sub_fmly_cd') == 'RRTN'\
and 'account_id' in transaction \
and 'ref' in transaction:

for transactionBis in list_transactions:
if 'ref' in transactionBis \
and transactionBis['ref'] == transaction['ref']\
and transactionBis != transaction:

transactionBis['account_id'] =\
transaction['account_id']

return stmts_vals

def _create_bank_statements(self, stmts_vals):
statement_ids, notifications =\
super(AccountStatementImportCustomCamt053, self).\
_create_bank_statements(stmts_vals)

if 'data_file' in stmts_vals[0]:
# Add the file imported file to the statement.
if 'file_name' in stmts_vals[0]:
file_name = stmts_vals[0]['file_name']
else:
file_name = self.filename

self.env['ir.attachment'].create({
'datas_fname': file_name,
'res_model': 'account.bank.statement',
'datas': base64.b64encode(stmts_vals[0]['data_file']),
'name': file_name,
'res_id': statement_ids[0]})

return statement_ids, notifications
Loading

0 comments on commit a678ddb

Please sign in to comment.