diff --git a/addons/account/account_bank.py b/addons/account/account_bank.py index 44411cd637a..acb0e640a7a 100644 --- a/addons/account/account_bank.py +++ b/addons/account/account_bank.py @@ -65,12 +65,11 @@ class bank(osv.osv): # Find the code and parent of the bank account to create dig = 6 current_num = 1 - ids = obj_acc.search(cr, uid, [('type','=','liquidity'), ('company_id', '=', bank.company_id.id)], context=context) + ids = obj_acc.search(cr, uid, [('type','=','liquidity'), ('company_id', '=', bank.company_id.id), ('parent_id', '!=', False)], context=context) # No liquidity account exists, no template available if not ids: continue - ref_acc_bank_temp = obj_acc.browse(cr, uid, ids[0], context=context) - ref_acc_bank = ref_acc_bank_temp.parent_id + ref_acc_bank = obj_acc.browse(cr, uid, ids[0], context=context).parent_id while True: new_code = str(ref_acc_bank.code.ljust(dig-len(str(current_num)), '0')) + str(current_num) ids = obj_acc.search(cr, uid, [('code', '=', new_code), ('company_id', '=', bank.company_id.id)]) @@ -82,7 +81,7 @@ class bank(osv.osv): 'name': name, 'code': new_code, 'type': 'liquidity', - 'user_type': ref_acc_bank_temp.user_type.id, + 'user_type': ref_acc_bank.user_type.id, 'reconcile': False, 'parent_id': ref_acc_bank.id, 'company_id': bank.company_id.id, diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 01476374cf4..0fb6af05e58 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -51,9 +51,12 @@ class account_invoice(osv.osv): company_id = context.get('company_id', user.company_id.id) type2journal = {'out_invoice': 'sale', 'in_invoice': 'purchase', 'out_refund': 'sale_refund', 'in_refund': 'purchase_refund'} journal_obj = self.pool.get('account.journal') - res = journal_obj.search(cr, uid, [('type', '=', type2journal.get(type_inv, 'sale')), - ('company_id', '=', company_id)], - limit=1) + domain = [('company_id', '=', company_id)] + if isinstance(type_inv, list): + domain.append(('type', 'in', [type2journal.get(type) for type in type_inv if type2journal.get(type)])) + else: + domain.append(('type', '=', type2journal.get(type_inv, 'sale'))) + res = journal_obj.search(cr, uid, domain, limit=1) return res and res[0] or False def _get_currency(self, cr, uid, context=None): @@ -578,6 +581,10 @@ class account_invoice(osv.osv): return {'value': {}} def onchange_company_id(self, cr, uid, ids, company_id, part_id, type, invoice_line, currency_id, context=None): + #TODO: add the missing context parameter when forward-porting in trunk so we can remove + # this hack! + context = self.pool['res.users'].context_get(cr, uid) + val = {} dom = {} obj_journal = self.pool.get('account.journal') @@ -634,14 +641,13 @@ class account_invoice(osv.osv): else: continue if company_id and type: - if type in ('out_invoice'): - journal_type = 'sale' - elif type in ('out_refund'): - journal_type = 'sale_refund' - elif type in ('in_refund'): - journal_type = 'purchase_refund' - else: - journal_type = 'purchase' + journal_mapping = { + 'out_invoice': 'sale', + 'out_refund': 'sale_refund', + 'in_refund': 'purchase_refund', + 'in_invoice': 'purchase', + } + journal_type = journal_mapping[type] journal_ids = obj_journal.search(cr, uid, [('company_id','=',company_id), ('type', '=', journal_type)]) if journal_ids: val['journal_id'] = journal_ids[0] @@ -651,7 +657,12 @@ class account_invoice(osv.osv): if r[1] == 'journal_id' and r[2] in journal_ids: val['journal_id'] = r[2] if not val.get('journal_id', False): - raise osv.except_osv(_('Configuration Error!'), (_('Cannot find any account journal of %s type for this company.\n\nYou can create one in the menu: \nConfiguration\Journals\Journals.') % (journal_type))) + journal_type_map = dict(obj_journal._columns['type'].selection) + journal_type_label = self.pool['ir.translation']._get_source(cr, uid, None, ('code','selection'), + context.get('lang'), + journal_type_map.get(journal_type)) + raise osv.except_osv(_('Configuration Error!'), + _('Cannot find any account journal of %s type for this company.\n\nYou can create one in the menu: \nConfiguration\Journals\Journals.') % ('"%s"' % journal_type_label)) dom = {'journal_id': [('id', 'in', journal_ids)]} else: journal_ids = obj_journal.search(cr, uid, []) @@ -968,7 +979,7 @@ class account_invoice(osv.osv): total, total_currency, iml = self.compute_invoice_totals(cr, uid, inv, company_currency, ref, iml, context=ctx) acc_id = inv.account_id.id - name = inv['name'] or '/' + name = inv['name'] or inv['supplier_invoice_number'] or '/' totlines = False if inv.payment_term: totlines = payment_term_obj.compute(cr, @@ -1167,12 +1178,12 @@ class account_invoice(osv.osv): if not ids: return [] types = { - 'out_invoice': 'Invoice ', - 'in_invoice': 'Sup. Invoice ', - 'out_refund': 'Refund ', - 'in_refund': 'Supplier Refund ', + 'out_invoice': _('Invoice'), + 'in_invoice': _('Supplier Invoice'), + 'out_refund': _('Refund'), + 'in_refund': _('Supplier Refund'), } - return [(r['id'], (r['number']) or types[r['type']] + (r['name'] or '')) for r in self.read(cr, uid, ids, ['type', 'number', 'name'], context, load='_classic_write')] + return [(r['id'], '%s %s' % (r['number'] or types[r['type']], r['name'] or '')) for r in self.read(cr, uid, ids, ['type', 'number', 'name'], context, load='_classic_write')] def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100): if not args: diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index e604cc6d1a4..314e3423996 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -1066,12 +1066,12 @@ class account_move_line(osv.osv): for line in self.browse(cr, uid, ids, context=context): ctx = context.copy() - if ('journal_id' not in ctx): + if not ctx.get('journal_id'): if line.move_id: ctx['journal_id'] = line.move_id.journal_id.id else: ctx['journal_id'] = line.journal_id.id - if ('period_id' not in ctx): + if not ctx.get('period_id'): if line.move_id: ctx['period_id'] = line.move_id.period_id.id else: diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index c90f8b36d2d..91c6d6608fd 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -585,7 +585,10 @@ - + diff --git a/addons/account/partner_view.xml b/addons/account/partner_view.xml index 3dcc68e315e..6a58bc7f77e 100644 --- a/addons/account/partner_view.xml +++ b/addons/account/partner_view.xml @@ -61,7 +61,7 @@ partner.view.buttons res.partner - +