diff --git a/addons/account/account.py b/addons/account/account.py index da161c48fcd..15881100441 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -641,7 +641,7 @@ class account_account(osv.osv): return True def _check_allow_type_change(self, cr, uid, ids, new_type, context=None): - group_dest = ['consolidation','view'] + restricted_groups = ['consolidation','view'] line_obj = self.pool.get('account.move.line') for account in self.browse(cr, uid, ids, context=context): old_type = account.type @@ -649,10 +649,10 @@ class account_account(osv.osv): if line_obj.search(cr, uid, [('account_id', 'in', account_ids)]): #Check for 'Closed' type if old_type == 'closed' and new_type !='closed': - raise osv.except_osv(_('Warning !'), _("You cannot change the type of account from 'Closed' to any other type which contains journal items!")) - # Forbid to change an account type for group_dest if move are on it (or his children) - if (new_type in group_dest): - raise osv.except_osv(_('Warning !'), _("You cannot change the type of account for '%s' type as it contains journal items!") % (new_type,)) + raise osv.except_osv(_('Warning !'), _("You cannot change the type of account from 'Closed' to any other type as it contains journal items!")) + # Forbid to change an account type for restricted_groups as it contains journal items (or if one of its children does) + if (new_type in restricted_groups): + raise osv.except_osv(_('Warning !'), _("You cannot change the type of account to '%s' type as it contains journal items!") % (new_type,)) return True @@ -662,8 +662,8 @@ class account_account(osv.osv): def _check_allow_code_change(self, cr, uid, ids, context=None): line_obj = self.pool.get('account.move.line') for account in self.browse(cr, uid, ids, context=context): - account_ids = self.search(cr, uid, [('id', 'child_of', [account.id])]) - if line_obj.search(cr, uid, [('account_id', 'in', account_ids)]): + account_ids = self.search(cr, uid, [('id', 'child_of', [account.id])], context=context) + if line_obj.search(cr, uid, [('account_id', 'in', account_ids)], context=context): raise osv.except_osv(_('Warning !'), _("You cannot change the code of account which contains journal items!")) return True @@ -1321,14 +1321,6 @@ class account_move(osv.osv): 'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, } - def _check_fiscal_year(self, cursor, user, ids): - for move in self.browse(cursor, user, ids): - date_start = move.period_id.fiscalyear_id.date_start - date_stop = move.period_id.fiscalyear_id.date_stop - if move.date < date_start or move.date > date_stop: - return False - return True - def _check_centralisation(self, cursor, user, ids, context=None): for move in self.browse(cursor, user, ids, context=context): if move.journal_id.centralisation: @@ -1344,9 +1336,6 @@ class account_move(osv.osv): (_check_centralisation, 'You cannot create more than one move per period on a centralized journal.', ['journal_id']), - (_check_fiscal_year, - 'You cannot create entries with date not in the fiscal year of the chosen period', - ['line_id','']), ] def post(self, cr, uid, ids, context=None): @@ -1496,7 +1485,7 @@ class account_move(osv.osv): for line in move.line_id: if line.invoice: raise osv.except_osv(_('User Error!'), - _("Move cannot be deleted if linked to an invoice: %s : Move ID:%s.") % \ + _("Move cannot be deleted if linked to an invoice. (Invoice: %s - Move ID:%s)") % \ (line.invoice.number,move.name)) line_ids = map(lambda x: x.id, move.line_id) context['journal_id'] = move.journal_id.id @@ -1706,18 +1695,17 @@ class account_move_reconcile(osv.osv): 'line_id': fields.one2many('account.move.line', 'reconcile_id', 'Entry Lines'), 'line_partial_ids': fields.one2many('account.move.line', 'reconcile_partial_id', 'Partial Entry lines'), 'create_date': fields.date('Creation date', readonly=True), - 'opening_reconcile': fields.boolean('Opening entries reconciliation', help="Is this reconciliation produced by the opening of a new fiscal year ?."), + 'opening_reconciliation': fields.boolean('Opening Entries Reconciliation', help="Is this reconciliation produced by the opening of a new fiscal year ?."), } _defaults = { 'name': lambda self,cr,uid,ctx=None: self.pool.get('ir.sequence').get(cr, uid, 'account.reconcile', context=ctx) or '/', - 'opening_reconcile': 0, } - # You cannot unlink a reconciliation if it is a opening_reconcile one, + # You cannot unlink a reconciliation if it is a opening_reconciliation one, # you should use the generate opening entries wizard for that def unlink(self, cr, uid, ids, context=None): - for move_rec in self.browse(cr, uid, ids): - if move_rec.opening_reconcile: + for move_rec in self.browse(cr, uid, ids, context=context): + if move_rec.opening_reconciliation: raise osv.except_osv(_('Error!'), _('You cannot unreconcile journal items if they has been generated by the \ opening/closing fiscal year process.')) return super(account_move_reconcile, self).unlink(cr, uid, ids, context=context) @@ -1727,7 +1715,7 @@ class account_move_reconcile(osv.osv): def _check_same_partner(self, cr, uid, ids, context=None): for reconcile in self.browse(cr, uid, ids, context=context): move_lines = [] - if not reconcile.opening_reconcile: + if not reconcile.opening_reconciliation: if reconcile.line_id: first_partner = reconcile.line_id[0].partner_id.id move_lines = reconcile.line_id @@ -1739,7 +1727,7 @@ class account_move_reconcile(osv.osv): return True _constraints = [ - (_check_same_partner, 'You can only reconcile moves where the partner (we mean ID) is the same or empty on all entries.', ['line_id']), + (_check_same_partner, 'You can only reconcile journal items with the same partner.', ['line_id']), ] def reconcile_partial_check(self, cr, uid, ids, type='auto', context=None): diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index b5e49951dfa..935ae70a059 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -615,7 +615,7 @@ class account_move_line(osv.osv): def _check_currency_and_amount(self, cr, uid, ids, context=None): for l in self.browse(cr, uid, ids, context=context): - if (l.currency_id and not l.amount_currency) or (not l.currency_id and l.amount_currency): + if (l.amount_currency and not l.currency_id): return False return True @@ -640,7 +640,7 @@ class account_move_line(osv.osv): (_check_currency, 'The selected account of your Journal Entry forces to provide a secondary currency. You should remove the secondary currency on the account or select a multi-currency view on the journal.', ['currency_id']), (_check_currency_and_amount, "You cannot create journal items with a secondary currency without recording both 'currency' and 'amount currency' field.", ['currency_id','amount_currency']), (_check_currency_amount, 'The amount expressed in the secondary currency must be positif when journal item are debit and negatif when journal item are credit.', ['amount_currency']), - (_check_currency_company, "You can't provide a secondary currency if the same than the company one." , ['currency_id']), + (_check_currency_company, "You cannot provide a secondary currency if it is the same than the company one." , ['currency_id']), ] #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id @@ -1126,7 +1126,7 @@ class account_move_line(osv.osv): 'has been confirmed.') % res[2]) return res - def _remove_move_reconcile(self, cr, uid, move_ids=None, opening_reconcile=False, context=None): + def _remove_move_reconcile(self, cr, uid, move_ids=None, opening_reconciliation=False, context=None): # Function remove move rencocile ids related with moves obj_move_line = self.pool.get('account.move.line') obj_move_rec = self.pool.get('account.move.reconcile') @@ -1141,8 +1141,8 @@ class account_move_line(osv.osv): unlink_ids += rec_ids unlink_ids += part_rec_ids if unlink_ids: - if opening_reconcile: - obj_move_rec.write(cr, uid, unlink_ids, {'opening_reconcile':False}) + if opening_reconciliation: + obj_move_rec.write(cr, uid, unlink_ids, {'opening_reconciliation': False}) obj_move_rec.unlink(cr, uid, unlink_ids) return True diff --git a/addons/account/wizard/account_fiscalyear_close.py b/addons/account/wizard/account_fiscalyear_close.py index 600b0312596..e11b4dcd34b 100644 --- a/addons/account/wizard/account_fiscalyear_close.py +++ b/addons/account/wizard/account_fiscalyear_close.py @@ -60,7 +60,7 @@ class account_fiscalyear_close(osv.osv_memory): cr.execute('select distinct(company_id) from account_move_line where id in %s',(tuple(ids),)) if len(cr.fetchall()) > 1: raise osv.except_osv(_('Warning!'), _('The entries to reconcile should belong to the same company.')) - r_id = self.pool.get('account.move.reconcile').create(cr, uid, {'type': 'auto', 'opening_reconcile':True}) + r_id = self.pool.get('account.move.reconcile').create(cr, uid, {'type': 'auto', 'opening_reconciliation': True}) cr.execute('update account_move_line set reconcile_id = %s where id in %s',(r_id, tuple(ids),)) return r_id @@ -107,7 +107,7 @@ class account_fiscalyear_close(osv.osv_memory): ('journal_id', '=', new_journal.id), ('period_id', '=', period.id)]) if move_ids: move_line_ids = obj_acc_move_line.search(cr, uid, [('move_id', 'in', move_ids)]) - obj_acc_move_line._remove_move_reconcile(cr, uid, move_line_ids, opening_reconcile=True, context=context) + obj_acc_move_line._remove_move_reconcile(cr, uid, move_line_ids, opening_reconciliation=True, context=context) obj_acc_move_line.unlink(cr, uid, move_line_ids, context=context) obj_acc_move.unlink(cr, uid, move_ids, context=context) diff --git a/addons/account_payment/account_invoice.py b/addons/account_payment/account_invoice.py index 60085a890c7..2ef894df4b5 100644 --- a/addons/account_payment/account_invoice.py +++ b/addons/account_payment/account_invoice.py @@ -30,18 +30,16 @@ class Invoice(osv.osv): # used in a payment order. The risk is that importing the payment line # in the bank statement will result in a crash cause no more move will # be found in the payment line - def action_cancel(self, cr, uid, ids, *args): + def action_cancel(self, cr, uid, ids, context=None): payment_line_obj = self.pool.get('payment.line') - invoices = self.browse(cr, uid, ids) - for inv in invoices: - inv_mv_lines = map(lambda x: x.id, inv.move_id.line_id) - pl_line_ids = payment_line_obj.search(cr, uid, [('move_line_id','in',inv_mv_lines)]) + for inv in self.browse(cr, uid, ids, context=context): + inv_mv_lines = [x.id for x in inv.move_id.line_id] + pl_line_ids = payment_line_obj.search(cr, uid, [('move_line_id','in',inv_mv_lines)], context=context) if pl_line_ids: - pay_line = payment_line_obj.browse(cr,uid,pl_line_ids) + pay_line = payment_line_obj.browse(cr, uid, pl_line_ids, context=context) payment_order_name = ','.join(map(lambda x: x.order_id.reference, pay_line)) raise osv.except_osv(_('Error!'), _("You cannot cancel an invoice which has already been imported in a payment order. Remove it from the following payment order : %s."%(payment_order_name))) - result = super(Invoice, self).action_cancel(cr, uid, ids, *args) - return result + return super(Invoice, self).action_cancel(cr, uid, ids, context=context) def _amount_to_pay(self, cursor, user, ids, name, args, context=None): '''Return the amount still to pay regarding all the payment orders''' diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index a579617c754..ffc7cf1769d 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -1550,14 +1550,12 @@ class account_bank_statement(osv.osv): return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line.id, company_currency_id, next_number, context=context) def write(self, cr, uid, ids, vals, context=None): - # We should not be able to change the journal if we already have - # bank statement line generated in case we use the voucher. This is because - # the import feature will write the current used journal. That lead to crap - # cause we should not be able to do that... A bank statement is by definition linked - # to one journal ! + # Restrict to modify the journal if we already have some voucher of reconciliation created/generated. + # Because the voucher keeps in memory the journal it was created with. for bk_st in self.browse(cr, uid, ids, context=context): - if vals.get('journal_id', False) and bk_st.line_ids: - raise osv.except_osv(_('Unable to change journal !'), _('You can not change the journal if you already generated lines !')) + if vals.get('journal_id') and bk_st.line_ids: + if any([x.voucher_id and True or False for x in bk_st.line_ids]): + raise osv.except_osv(_('Unable to change journal !'), _('You can not change the journal as you already reconciled some statement lines!')) return super(account_bank_statement, self).write(cr, uid, ids, vals, context=context) account_bank_statement()