Browse Source

[IMP] Let the res_partner_bank.post_write create the journal if it doesn't exist

pull/19/head
Laurent Mignon 10 years ago
committed by Laurent Mignon (ACSONE)
parent
commit
9c9ebe8cda
  1. 28
      account_bank_statement_import/account_bank_statement_import.py
  2. 8
      account_bank_statement_import/tests/test_import_bank_statement.py
  3. 4
      account_bank_statement_import_ofx/__openerp__.py
  4. 27
      account_bank_statement_import_ofx/demo/demo_data.xml

28
account_bank_statement_import/account_bank_statement_import.py

@ -64,13 +64,19 @@ class account_bank_statement_import(models.TransientModel):
# Try to find the bank account and currency in odoo
currency_id, bank_account_id = self._find_additional_data(
currency_code, account_number)
# Create the bank account if not already existing
if not bank_account_id and account_number:
journal_id = self.env.context.get('journal_id')
company_id = self.env.user.company_id.id
if journal_id:
journal = self.env['account.journal'].browse(journal_id)
company_id = journal.company_id.id
bank_account_id = self._create_bank_account(
account_number, company_id=company_id,
currency_id=currency_id).id
# Find or create the bank journal
journal_id = self._get_journal(
currency_id, bank_account_id, account_number)
# Create the bank account if not already existing
if not bank_account_id and account_number:
self._create_bank_account(
account_number, journal_id=journal_id)
# Prepare statement data to be used for bank statements creation
stmts_vals = self._complete_stmts_vals(
stmts_vals, journal_id, account_number)
@ -202,15 +208,19 @@ class account_bank_statement_import(models.TransientModel):
# (from which statement transactions originate) don't.
# Warning : if company_id is set, the method post_write of class
# bank will create a journal
if journal_id:
company_id = self.env['account.journal'].browse(
journal_id).company_id.id
if company_id:
vals = self.env['res.partner.bank'].onchange_company_id(company_id)
vals_acc.update(vals.get('value', {}))
vals_acc['journal_id'] = journal_id
vals_acc['company_id'] = company_id
return self.env['res.partner.bank'].create(vals_acc)
# When the journal is created at same time of the bank account, we need
# to specify the currency to use a first time for the account.account
res_bank = self.env['res.partner.bank'].with_context(
default_currency_id=currency_id).create(vals_acc)
# and a second time on the journal
if currency_id:
res_bank.journal_id.currency = currency_id
return res_bank
@api.model
def _complete_stmts_vals(self, stmts_vals, journal_id, account_number):

8
account_bank_statement_import/tests/test_import_bank_statement.py

@ -49,11 +49,11 @@ class TestAccountBankStatemetImport(TransactionCase):
"is_company": False,
"email": "test@tes.ttest",
})
company_id = self.base_user_root.company_id.id
self.company_id = self.base_user_root.company_id.id
self.other_user_id_a = self.res_users_model.create(
{"partner_id": self.other_partner_id.id,
"company_id": company_id,
"company_ids": [(4, company_id)],
"company_id": self.company_id,
"company_ids": [(4, self.company_id)],
"login": "my_login a",
"name": "my user",
"groups_id": [(4, self.ref('account.group_account_manager'))]
@ -68,7 +68,7 @@ class TestAccountBankStatemetImport(TransactionCase):
st_import = self.statement_import_model.sudo(self.other_user_id_a.id)
bank = st_import._create_bank_account(
'001251882303', journal_id=self.journal_id)
'001251882303', company_id=self.company_id)
self.assertEqual(bank.partner_id.id,
expected_id)

4
account_bank_statement_import_ofx/__openerp__.py

@ -26,9 +26,7 @@ create periods for the year 2013.
""",
'data' : [],
'depends': ['account_bank_statement_import'],
'demo': [
'demo/demo_data.xml',
],
'demo': [],
'auto_install': True,
'installable': True,
}

27
account_bank_statement_import_ofx/demo/demo_data.xml

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="ofx_bank_journal" model="account.journal">
<field name="name">Bank Journal - (test ofx)</field>
<field name="code">TBNKOFX</field>
<field name="type">bank</field>
<field name="sequence_id" ref="account.sequence_bank_journal"/>
<field name="default_debit_account_id" ref="account.usd_bnk"/>
<field name="default_credit_account_id" ref="account.usd_bnk"/>
<field name="user_id" ref="base.user_root"/>
<field name="currency" ref="base.USD"/>
</record>
<record id="ofx_company_bank" model="res.partner.bank">
<field name="owner_name">Your Company</field>
<field name="acc_number">123456</field>
<field name="partner_id" ref="base.partner_root"></field>
<field name="company_id" ref="base.main_company"></field>
<field name="journal_id" ref="ofx_bank_journal"></field>
<field name="state">bank</field>
<field name="bank" ref="base.res_bank_1"/>
</record>
</data>
</openerp>
Loading…
Cancel
Save