diff --git a/addons/account/account.py b/addons/account/account.py index 22f2b3bda9c..13b7856c7ce 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1014,10 +1014,15 @@ class account_period(osv.osv): else: company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id args.append(('company_id', '=', company_id)) - ids = self.search(cr, uid, args, context=context) - if not ids: - raise osv.except_osv(_('Error!'), _('There is no period defined for this date: %s.\nPlease create one.')%dt) - return ids + result = [] + if context.get('account_period_prefer_normal'): + # look for non-special periods first, and fallback to all if no result is found + result = self.search(cr, uid, args + [('special', '=', False)], context=context) + if not result: + result = self.search(cr, uid, args, context=context) + if not result: + raise osv.except_osv(_('Error !'), _('There is no period defined for this date: %s.\nPlease create one.')%dt) + return result def action_draft(self, cr, uid, ids, *args): mode = 'draft' @@ -1191,10 +1196,9 @@ class account_move(osv.osv): return res def _get_period(self, cr, uid, context=None): - periods = self.pool.get('account.period').find(cr, uid) - if periods: - return periods[0] - return False + ctx = dict(context or {}, account_period_prefer_normal=True) + period_ids = self.pool.get('account.period').find(cr, uid, context=ctx) + return period_ids[0] def _amount_compute(self, cr, uid, ids, name, args, context, where =''): if not ids: return {} diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index e7e3f740067..464cc5e527a 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -439,10 +439,11 @@ class account_bank_statement(osv.osv): for st in self.browse(cr, uid, ids, context=context): if st.state=='draft': continue - ids = [] + move_ids = [] for line in st.line_ids: - ids += [x.id for x in line.move_ids] - account_move_obj.unlink(cr, uid, ids, context) + move_ids += [x.id for x in line.move_ids] + account_move_obj.button_cancel(cr, uid, move_ids, context=context) + account_move_obj.unlink(cr, uid, move_ids, context) done.append(st.id) return self.write(cr, uid, done, {'state':'draft'}, context=context) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index cdd340ef551..b6c4d07c00b 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -994,7 +994,8 @@ class account_invoice(osv.osv): 'narration':inv.comment } period_id = inv.period_id and inv.period_id.id or False - ctx.update({'company_id': inv.company_id.id}) + ctx.update(company_id=inv.company_id.id, + account_period_prefer_normal=True) if not period_id: period_ids = period_obj.find(cr, uid, inv.date_invoice, context=ctx) period_id = period_ids and period_ids[0] or False diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 25c898f6c0d..a69798b90d6 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -983,7 +983,8 @@ class account_move_line(osv.osv): if context is None: context = {} period_pool = self.pool.get('account.period') - pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)]) + ctx = dict(context, account_period_prefer_normal=True) + pids = period_pool.find(cr, user, date, context=ctx) if pids: res.update({ 'period_id':pids[0] diff --git a/addons/account/process/supplier_invoice_process.xml b/addons/account/process/supplier_invoice_process.xml index 113d4a8194c..58b98220f95 100644 --- a/addons/account/process/supplier_invoice_process.xml +++ b/addons/account/process/supplier_invoice_process.xml @@ -68,6 +68,7 @@ + diff --git a/addons/account/test/account_bank_statement.yml b/addons/account/test/account_bank_statement.yml index 89d0b493444..cbd35be438a 100644 --- a/addons/account/test/account_bank_statement.yml +++ b/addons/account/test/account_bank_statement.yml @@ -69,5 +69,7 @@ !python {model: account.bank.statement}: | try: self.button_cancel(cr, uid, [ref("account_bank_statement_0")]) - except Exception, e: - assert e[0]=='User Error!', 'Another exception has been raised!' + assert False, "An exception should have been raised, the journal should not let us cancel moves!" + except Exception: + # exception was raised as expected, as the journal does not allow cancelling moves + pass diff --git a/addons/account/wizard/account_unreconcile_view.xml b/addons/account/wizard/account_unreconcile_view.xml index 785469aad51..eca7f2bc297 100644 --- a/addons/account/wizard/account_unreconcile_view.xml +++ b/addons/account/wizard/account_unreconcile_view.xml @@ -6,9 +6,9 @@ Unreconcile Entries account.unreconcile -
- -