diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index c432689de44..0816bbbf4a7 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -46,6 +46,7 @@ module named account_voucher. "depends" : ["product", "analytic", "process","board"], 'update_xml': [ 'security/account_security.xml', + 'security/analytic_security.xml', 'security/ir.model.access.csv', 'account_menuitem.xml', 'account_wizard.xml', diff --git a/addons/account/account.py b/addons/account/account.py index 6f55aed1f36..d8be0075611 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -970,6 +970,13 @@ class account_fiscalyear(osv.osv): _columns = { 'end_journal_period_id':fields.many2one('account.journal.period','End of Year Entries Journal', readonly=True), } + + def copy(self, cr, uid, id, default={}, context=None): + default.update({ + 'period_ids': [], + 'end_journal_period_id': False + }) + return super(account_fiscalyear, self).copy(cr, uid, id, default=default, context=context) account_fiscalyear() #---------------------------------------------------------- @@ -1117,8 +1124,9 @@ class account_move(osv.osv): def post(self, cr, uid, ids, context=None): invoice = context.get('invoice', False) - if self.validate(cr, uid, ids, context) and len(ids): - for move in self.browse(cr, uid, ids): + valid_moves = self.validate(cr, uid, ids, context) + if valid_moves: + for move in self.browse(cr, uid, valid_moves): if move.name =='/': new_name = False journal = move.journal_id @@ -1138,7 +1146,7 @@ class account_move(osv.osv): cr.execute('UPDATE account_move '\ 'SET state=%s '\ 'WHERE id IN %s', - ('posted', tuple(ids),)) + ('posted', tuple(valid_moves),)) else: raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !\nMake sure you have configured Payment Term properly !\nIt should contain atleast one Payment Term Line with type "Balance" !')) return True @@ -1409,7 +1417,8 @@ class account_move(osv.osv): for record in valid_moves: self.pool.get('account.move.line').create_analytic_lines(cr, uid, [line.id for line in record.line_id], context) - return len(valid_moves) > 0 + valid_moves = [move.id for move in valid_moves] + return len(valid_moves) > 0 and valid_moves or False account_move() @@ -1974,21 +1983,26 @@ class account_model(osv.osv): 'company_id': fields.many2one('res.company', 'Company', required=True), 'lines_id': fields.one2many('account.model.line', 'model_id', 'Model Entries'), 'legend' :fields.text('Legend', readonly=True, size=100), + 'date': fields.selection([('today','Date of the day'), ('partner','Partner Payment Term')], 'Current Date', required=True, help="The date of the generated entries"), } _defaults = { 'legend': lambda self, cr, uid, context:_('You can specify year, month and date in the name of the model using the following labels:\n\n%(year)s : To Specify Year \n%(month)s : To Specify Month \n%(date)s : Current Date\n\ne.g. My model on %(date)s'), - 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id + 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, + 'date': 'today' } def generate(self, cr, uid, ids, datas={}, context={}): move_ids = [] + account_move_obj = self.pool.get('account.move') + account_move_line_obj = self.pool.get('account.move.line') + period_id = self.pool.get('account.period').find(cr, uid, dt=context.get('date', False)) + if not period_id: + raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !')) + period_id = period_id[0] + for model in self.browse(cr, uid, ids, context): context.update({'date':datas['date']}) - period_id = self.pool.get('account.period').find(cr, uid, dt=context.get('date', False)) - if not period_id: - raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !')) - period_id = period_id[0] - move_id = self.pool.get('account.move').create(cr, uid, { + move_id = account_move_obj.create(cr, uid, { 'ref': model.ref, 'period_id': period_id, 'journal_id': model.journal_id.id, @@ -1996,10 +2010,16 @@ class account_model(osv.osv): }) move_ids.append(move_id) for line in model.lines_id: + analytic_account_id = False + if line.analytic_account_id: + if not model.journal_id.analytic_journal_id: + raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (model.journal_id.name,)) + analytic_account_id = line.analytic_account_id.id val = { 'move_id': move_id, 'journal_id': model.journal_id.id, - 'period_id': period_id + 'period_id': period_id, + 'analytic_account_id': analytic_account_id } val.update({ 'name': line.name, @@ -2015,7 +2035,7 @@ class account_model(osv.osv): }) c = context.copy() c.update({'journal_id': model.journal_id.id,'period_id': period_id}) - self.pool.get('account.move.line').create(cr, uid, val, context=c) + account_move_line_obj.create(cr, uid, val, context=c) return move_ids account_model() @@ -2028,22 +2048,14 @@ class account_model_line(osv.osv): 'quantity': fields.float('Quantity', digits_compute=dp.get_precision('Account'), help="The optional quantity on entries"), 'debit': fields.float('Debit', digits_compute=dp.get_precision('Account')), 'credit': fields.float('Credit', digits_compute=dp.get_precision('Account')), - - 'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade"), - - 'model_id': fields.many2one('account.model', 'Model', required=True, ondelete="cascade", select=True), - 'ref': fields.char('Reference', size=16), - + 'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade"), + 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', ondelete="cascade"), + 'model_id': fields.many2one('account.model', 'Model', required=True, ondelete="cascade", select=True), 'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optional other currency."), 'currency_id': fields.many2one('res.currency', 'Currency'), - 'partner_id': fields.many2one('res.partner', 'Partner'), 'date_maturity': fields.selection([('today','Date of the day'), ('partner','Partner Payment Term')], 'Maturity date', help="The maturity date of the generated entries for this model. You can choose between the creation date or the creation date of the entries plus the partner payment terms."), - 'date': fields.selection([('today','Date of the day'), ('partner','Partner Payment Term')], 'Current Date', required=True, help="The date of the generated entries"), - } - _defaults = { - 'date': lambda *a: 'today' } _order = 'sequence' _sql_constraints = [ diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index b9cdf7df09b..b06b3ba3b1e 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -151,17 +151,37 @@ class account_cash_statement(osv.osv): res[r] = round(res[r], 2) return res - def _get_company(self, cr, uid, ids, context={}): + def _get_company(self, cr, uid, context={}): user_pool = self.pool.get('res.users') company_pool = self.pool.get('res.company') - user = user_pool.browse(cr, uid, uid, uid) + user = user_pool.browse(cr, uid, uid, context) company_id = user.company_id and user.company_id.id if not company_id: company_id = company_pool.search(cr, uid, [])[0] return company_id - def _get_cash_open_box_lines(self, cr, uid, ids, context={}): + def _get_cash_open_box_lines(self, cr, uid, context={}): + res = [] + curr = [1, 2, 5, 10, 20, 50, 100, 500] + for rs in curr: + dct = { + 'pieces':rs, + 'number':0 + } + res.append(dct) + journal_ids = self.pool.get('account.journal').search(cr, uid, [('type','=','cash')], context=context) + if journal_ids: + results = self.search(cr, uid, [('journal_id','in',journal_ids),('state','=','confirm')],context=context) + if results: + cash_st = self.browse(cr, uid, results, context)[0] + for cash_line in cash_st.ending_details_ids: + for r in res: + if cash_line.pieces == r['pieces']: + r['number'] = cash_line.number + return res + + def _get_default_cash_close_box_lines(self, cr, uid, context={}): res = [] curr = [1, 2, 5, 10, 20, 50, 100, 500] for rs in curr: @@ -172,7 +192,7 @@ class account_cash_statement(osv.osv): res.append(dct) return res - def _get_cash_close_box_lines(self, cr, uid, ids, context={}): + def _get_cash_close_box_lines(self, cr, ids, uid, context={}): res = [] curr = [1, 2, 5, 10, 20, 50, 100, 500] for rs in curr: @@ -180,7 +200,7 @@ class account_cash_statement(osv.osv): 'pieces':rs, 'number':0 } - res.append((0, 0, dct)) + res.append((0,0,dct)) return res _columns = { @@ -206,7 +226,7 @@ class account_cash_statement(osv.osv): 'user_id': lambda self, cr, uid, context=None: uid, 'company_id': _get_company, 'starting_details_ids':_get_cash_open_box_lines, - 'ending_details_ids':_get_cash_open_box_lines + 'ending_details_ids':_get_default_cash_close_box_lines } def create(self, cr, uid, vals, context=None): @@ -305,25 +325,25 @@ class account_cash_statement(osv.osv): 'name': number }) - cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm')) - rs = cr.fetchone() - rs = rs and rs[0] or None - if rs: - if len(statement.starting_details_ids) > 0: - sid = [] - for line in statement.starting_details_ids: - sid.append(line.id) - cash_pool.unlink(cr, uid, sid) - - statement = statement_pool.browse(cr, uid, rs) - balance_start = statement.balance_end_real or 0.0 - open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)]) - for sid in open_ids: - default = { - 'ending_id': False, - 'starting_id':ids[0] - } - cash_pool.copy(cr, uid, sid, default) +# cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm')) +# rs = cr.fetchone() +# rs = rs and rs[0] or None +# if rs: +# if len(statement.starting_details_ids) > 0: +# sid = [] +# for line in statement.starting_details_ids: +# sid.append(line.id) +# cash_pool.unlink(cr, uid, sid) +# +# statement = statement_pool.browse(cr, uid, rs) +# balance_start = statement.balance_end_real or 0.0 +# open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)]) +# for sid in open_ids: +# default = { +# 'ending_id': False, +# 'starting_id':ids[0] +# } +# cash_pool.copy(cr, uid, sid, default) vals.update({ 'date':time.strftime("%Y-%m-%d %H:%M:%S"), diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index cf17c76deff..79a846c8ad7 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -986,7 +986,7 @@ class account_move_line(osv.osv): if 'period_id' in vals and 'period_id' not in context: period_id = vals['period_id'] elif 'journal_id' not in context and 'move_id' in vals: - if vals['move_id']: + if vals.get('move_id', False): m = self.pool.get('account.move').browse(cr, uid, vals['move_id']) journal_id = m.journal_id.id period_id = m.period_id.id @@ -1086,9 +1086,9 @@ class account_move_line(osv.osv): self._check_date(cr, uid, vals, context, check) if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']: raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!')) - if 'journal_id' in vals and 'journal_id' not in context: + if 'journal_id' in vals: context['journal_id'] = vals['journal_id'] - if 'period_id' in vals and 'period_id' not in context: + if 'period_id' in vals: context['period_id'] = vals['period_id'] if ('journal_id' not in context) and ('move_id' in vals) and vals['move_id']: m = self.pool.get('account.move').browse(cr, uid, vals['move_id']) @@ -1097,7 +1097,6 @@ class account_move_line(osv.osv): self._update_journal_check(cr, uid, context['journal_id'], context['period_id'], context) company_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id - move_id = vals.get('move_id', False) journal = self.pool.get('account.journal').browse(cr, uid, context['journal_id']) is_new_move = False diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 77922b3ca39..afaa22953ab 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -121,7 +121,7 @@ - + account.period.search account.period @@ -137,7 +137,7 @@ - + Periods account.period @@ -521,7 +521,7 @@ - + @@ -1552,13 +1552,13 @@ - + + - @@ -1575,12 +1575,11 @@ + + - - - @@ -1593,9 +1592,10 @@
- + - + + @@ -1605,6 +1605,7 @@
+ account.model.tree account.model @@ -1613,15 +1614,39 @@ - + + + + account.model.search + account.model + search + + + + + + + + + + + + + + + + + + Recurring Models account.model form - tree,form + tree,form,search + @@ -2425,13 +2450,14 @@ - + + diff --git a/addons/account/security/analytic_security.xml b/addons/account/security/analytic_security.xml new file mode 100644 index 00000000000..b2543f5fa05 --- /dev/null +++ b/addons/account/security/analytic_security.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/addons/account/wizard/account_use_model.py b/addons/account/wizard/account_use_model.py index facb675a090..84554dd6d79 100644 --- a/addons/account/wizard/account_use_model.py +++ b/addons/account/wizard/account_use_model.py @@ -60,10 +60,16 @@ class account_use_model(osv.osv_memory): }) move_ids.append(move_id) for line in model.lines_id: + analytic_account_id = False + if line.analytic_account_id: + if not model.journal_id.analytic_journal_id: + raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (model.journal_id.name,)) + analytic_account_id = line.analytic_account_id.id val = { 'move_id': move_id, 'journal_id': model.journal_id.id, - 'period_id': period_id + 'period_id': period_id, + 'analytic_account_id': analytic_account_id } val.update({ 'name': line.name, @@ -80,24 +86,8 @@ class account_use_model(osv.osv_memory): c = context.copy() c.update({'journal_id': model.journal_id.id,'period_id': period_id}) id_line = account_move_line_obj.create(cr, uid, val, context=c) - context.update({'move_ids':move_ids}) - model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_use_model_open_entry')], context=context) - resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] - return { - 'name': _('Use Model'), - 'context': context, - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'account.use.model', - 'views': [(resource_id,'form')], - 'type': 'ir.actions.act_window', - 'target': 'new', - } - def open_moves(self, cr, uid, ids, context=None): - mod_obj = self.pool.get('ir.model.data') - if context is None: - context = {} + context.update({'move_ids':move_ids}) model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_move_form')], context=context) resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] return { diff --git a/addons/account/wizard/account_use_model_view.xml b/addons/account/wizard/account_use_model_view.xml index fd3b13f3888..232c1b8df88 100644 --- a/addons/account/wizard/account_use_model_view.xml +++ b/addons/account/wizard/account_use_model_view.xml @@ -42,22 +42,6 @@ account.move.line - - account.use.model.open.entry.form - account.use.model - form - -
- -