Commits

Jordi Esteve (Zikzakmedia) committed 67a25e9

Fix journal selection when invoicing from lines

Comments (0)

Files changed (1)

 __all__ = ['Invoice', 'InvoiceLine']
 __metaclass__ = PoolMeta
 
+_TYPE2JOURNAL = {
+    'out_invoice': 'revenue',
+    'in_invoice': 'expense',
+    'out_credit_note': 'revenue',
+    'in_credit_note': 'expense',
+}
+
 
 class Invoice:
     'Invoice'
         Journal = Pool().get('account.journal')
         PaymentTerm = Pool().get('account.invoice.payment_term')
 
-        journal_id = Journal.search([
-            ('type', '=', 'expense'),
-            ], limit=1)
-        if journal_id:
-            journal_id = journal_id[0]
+        journals = Journal.search([
+                ('type', '=', _TYPE2JOURNAL.get(self.type or 'out_invoice',
+                        'revenue')),
+                ], limit=1)
+        if journals:
+            journal_id, = journals
 
         payment_term_ids = PaymentTerm.search([('active', '=', True)])
         if not len(payment_term_ids) > 0:
             if category.account_revenue:
                 account_found = True
                 category = category.parent
-        if not account_found: 
+        if not account_found:
             self.raise_user_error('missing_account_revenue',
                 error_args=(product.name, product))
 
                 if category.account_revenue:
                     account = category.account_revenue
                     category = category.parent
-        if not account: 
+        if not account:
             self.raise_user_error('missing_account_revenue',
                 error_args=(product.name, product))
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.