← Back to team overview

banking-addons-team team mailing list archive

[Merge] lp:~therp-nl/banking-addons/6.1-dev-useful_defaults into lp:~banking-addons-team/banking-addons/6.1-dev

 

Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/banking-addons/6.1-dev-useful_defaults into lp:~banking-addons-team/banking-addons/6.1-dev with lp:~therp-nl/banking-addons/6.1-dev-fixes_from_testing_iteration_2 as a prerequisite.

Requested reviews:
  Banking Addons Team (banking-addons-team)
Related bugs:
  Bug #931395 in Banking Addons: "Use account_id from receivable/payable properties"
  https://bugs.launchpad.net/banking-addons/+bug/931395

For more details, see:
https://code.launchpad.net/~therp-nl/banking-addons/6.1-dev-useful_defaults/+merge/104398

This branch adds a number of useful defaults, such as the ones discussed in lp:931395
-- 
https://code.launchpad.net/~therp-nl/banking-addons/6.1-dev-useful_defaults/+merge/104398
Your team Banking Addons Team is requested to review the proposed merge of lp:~therp-nl/banking-addons/6.1-dev-useful_defaults into lp:~banking-addons-team/banking-addons/6.1-dev.
=== modified file 'account_banking/account_banking.py'
--- account_banking/account_banking.py	2012-05-02 15:15:23 +0000
+++ account_banking/account_banking.py	2012-05-02 15:15:24 +0000
@@ -131,9 +131,41 @@
         user = self.pool.get('res.users').browse(cursor, uid, uid, context=context)
         if user.company_id:
             return user.company_id.id
-        return self.pool.get('res.company').search(cursor, uid,
-                                                   [('parent_id', '=', False)]
-                                                  )[0]
+        company_ids = self.pool.get('res.company').search(
+            cursor, uid, [('parent_id', '=', False)])
+        return len(company_ids) == 1 and company_ids[0] or False
+
+    def _default_journal(self, cr, uid, context=None):
+        domain = [('type', '=', 'bank')]
+        user = self.pool.get('res.users').read(
+            cr, uid, uid, ['company_id'], context=context)
+        if user['company_id']:
+            domain.append(('company_id', '=', user['company_id'][0]))
+        journal_ids = self.pool.get('account.journal').search(
+            cr, uid, domain)
+        return len(journal_ids) == 1 and journal_ids[0] or False
+
+    def _default_partner_bank_id(self, cr, uid, context=None):
+        user = self.pool.get('res.users').read(
+            cr, uid, uid, ['company_id'], context=context)
+        if user['company_id']:
+            bank_ids = self.pool.get('res.partner.bank').search(
+                cr, uid, [('company_id', '=', user['company_id'][0])])
+            if len(bank_ids) == 1:
+                return bank_ids[0]
+        return False
+
+    def _default_debit_account_id(self, cr, uid, context=None):
+        account_def = self.pool.get('ir.property').get(
+            cr, uid, 'property_account_receivable',
+            'res.partner', context=context)
+        return account_def and account_def.id or False
+
+    def _default_credit_account_id(self, cr, uid, context=None):
+        account_def = self.pool.get('ir.property').get(
+            cr, uid, 'property_account_payable',
+            'res.partner', context=context)
+        return account_def and account_def.id or False
 
     def find(self, cr, uid, journal_id, partner_bank_id=False, context=None):
         domain = [('journal_id','=',journal_id)]
@@ -143,6 +175,10 @@
 
     _defaults = {
         'company_id': _default_company,
+        'journal_id': _default_journal,
+        'default_debit_account_id': _default_debit_account_id,
+        'default_credit_account_id': _default_credit_account_id,
+        'partner_bank_id': _default_partner_bank_id,
         #'multi_currency': lambda *a: False,
     }
 account_banking_account_settings()

=== modified file 'account_banking/i18n/nl.po'
--- account_banking/i18n/nl.po	2012-04-16 07:35:36 +0000
+++ account_banking/i18n/nl.po	2012-05-02 15:15:24 +0000
@@ -1057,7 +1057,7 @@
 #. module: account_banking
 #: help:account.banking.account.settings,default_debit_account_id:0
 msgid "The account to use when an unexpected payment is received. This can be needed when a customer pays in advance or when no matching invoice can be found. Mind that you can correct movements before confirming them."
-msgstr "De grootboekrekening waarop een onverwachte betaling kan worden geboekt, bijvoorbeeld in het geval van eeen klant die vooruitbetaalt of als er geen overeenkomende factuur kan worden gevonden in het systeem. Merk op dat er voor het bevestigen van de boekingen nog wijzigingen kunnen worden aangebracht."
+msgstr "De grootboekrekening waarop een onverwachte betaling kan worden geboekt, bijvoorbeeld in het geval van een klant die vooruitbetaalt of als er geen overeenkomende factuur kan worden gevonden in het systeem. Merk op dat er voor het bevestigen van de boekingen nog wijzigingen kunnen worden aangebracht."
 
 #. module: account_banking
 #: field:payment.mode.type,payment_order_type:0

=== modified file 'account_banking/wizard/bank_import.py'
--- account_banking/wizard/bank_import.py	2012-02-21 23:50:13 +0000
+++ account_banking/wizard/bank_import.py	2012-05-02 15:15:24 +0000
@@ -423,11 +423,16 @@
             ),
         }
 
+    def _default_parser_type(self, cr, uid, context=None):
+        types = models.parser_type.get_parser_types()
+        return types and types[0][0] or False
+
     _defaults = {
         'state': 'init',
         'company': lambda s,cr,uid,c:
             s.pool.get('res.company')._company_default_get(
             cr, uid, 'bank.import.transaction', context=c),
+        'parser': _default_parser_type,
         }
 
 banking_import()

=== modified file 'account_banking/wizard/bank_import_view.xml'
--- account_banking/wizard/bank_import_view.xml	2012-02-17 23:36:43 +0000
+++ account_banking/wizard/bank_import_view.xml	2012-05-02 15:15:24 +0000
@@ -34,7 +34,8 @@
                             <field name="log" colspan="4" nolabel="1" width="500"/>
                         </page>
                         <page attrs="{'invisible': [('state', '!=', 'ready')]}" string="Statements">
-                            <field name="statement_ids" colspan="4" nolabel="1"/>
+                            <field name="statement_ids" colspan="4" nolabel="1"
+                                   attrs="{'invisible': [('state', '!=', 'ready')]}" />
                         </page>
                     </notebook>
 		    <group colspan="2" >