=== modified file 'account/account_move_line.py' --- account/account_move_line.py 2013-09-18 14:31:46 +0000 +++ account/account_move_line.py 2013-09-27 15:33:32 +0000 @@ -565,6 +567,33 @@ if not cr.fetchone(): cr.execute('CREATE INDEX account_move_line_journal_id_period_id_index ON account_move_line (journal_id, period_id)') + def _check_all(self, cr, uid, ids, context=None): + for l in self.browse(cr, uid, ids, context=context): + if l.account_id.type == 'view': + raise osv.except_osv(_('Error!'), _('You cannot create journal items on an account of type view %s %s.') % (l.account_id.code, l.account_id.name)) + elif l.account_id.type == 'closed': + raise osv.except_osv(_('Error!'), _('You cannot create journal items on a closed account %s %s.') % (l.account_id.code, l.account_id.name)) + + if l.company_id != l.account_id.company_id or l.company_id != l.period_id.company_id: + raise osv.except_osv(_('Error!'), _('Account and Period must belong to the company %s.') % (l.company_id.name)) + + if l.journal_id.allow_date: + if not time.strptime(l.date[:10],'%Y-%m-%d') >= time.strptime(l.period_id.date_start, '%Y-%m-%d') or not time.strptime(l.date[:10], '%Y-%m-%d') <= time.strptime(l.period_id.date_stop, '%Y-%m-%d'): + raise osv.except_osv(_('Error!'), _('The date of your Journal Entry is not in the defined period! You should change the date or remove this constraint from the journal.')) + + if l.account_id.currency_id: + if not l.currency_id or not l.currency_id.id == l.account_id.currency_id.id: + raise osv.except_osv(_('Error!'), _('The selected account %s 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.' % l.account_id.name)) + if (l.amount_currency and not l.currency_id): + raise osv.except_osv(_('Error!'), _("You cannot create journal items with a secondary currency without recording both 'currency' and 'amount currency' field.")) + if l.currency_id.id == l.company_id.currency_id.id: + raise osv.except_osv(_('Error!'), _("You cannot provide a secondary currency if it is the same than the company one.")) + if l.amount_currency: + if (l.amount_currency > 0.0 and l.credit > 0.0) or (l.amount_currency < 0.0 and l.debit > 0.0): + raise osv.except_osv(_('Error!'), _("The amount expressed in the secondary currency must be positive when the journal item is a debit and negative when if it is a credit.")) + return True + def _check_no_view(self, cr, uid, ids, context=None): lines = self.browse(cr, uid, ids, context=context) for l in lines: @@ -620,14 +649,15 @@ return True _constraints = [ - (_check_no_view, 'You cannot create journal items on an account of type view.', ['account_id']), - (_check_no_closed, 'You cannot create journal items on closed account.', ['account_id']), - (_check_company_id, 'Account and Period must belong to the same company.', ['company_id']), - (_check_date, 'The date of your Journal Entry is not in the defined period! You should change the date or remove this constraint from the journal.', ['date']), - (_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 positive when the journal item is a debit and negative when if it is a credit.', ['amount_currency']), - (_check_currency_company, "You cannot provide a secondary currency if it is the same than the company one." , ['currency_id']), + (_check_all, 'Invalid line.', ['account_id', 'date', 'currency_id','amount_currency', 'company_id']), + # (_check_no_view, 'You cannot create journal items on an account of type view.', ['account_id']), + # (_check_no_closed, 'You cannot create journal items on closed account.', ['account_id']), + # (_check_company_id, 'Account and Period must belong to the same company.', ['company_id']), + # (_check_date, 'The date of your Journal Entry is not in the defined period! You should change the date or remove this constraint from the journal.', ['date']), + # (_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 positive when the journal item is a debit and negative when if it is a credit.', ['amount_currency']), + # (_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 @@ -1209,20 +1239,6 @@ if not ok: raise osv.except_osv(_('Bad Account!'), _('You cannot use this general account in this journal, check the tab \'Entry Controls\' on the related journal.')) - if vals.get('analytic_account_id',False): - if journal.analytic_journal_id: - vals['analytic_lines'] = [(0,0, { - 'name': vals['name'], - 'date': vals.get('date', time.strftime('%Y-%m-%d')), - 'account_id': vals.get('analytic_account_id', False), - 'unit_amount': vals.get('quantity', 1.0), - 'amount': vals.get('debit', 0.0) or vals.get('credit', 0.0), - 'general_account_id': vals.get('account_id', False), - 'journal_id': journal.analytic_journal_id.id, - 'ref': vals.get('ref', False), - 'user_id': uid - })] - result = super(account_move_line, self).create(cr, uid, vals, context=context) # CREATE Taxes if vals.get('account_tax_id', False):