From 508df45fb54a933035c18c2604309e26560b78e7 Mon Sep 17 00:00:00 2001 From: "pap (openerp)" Date: Fri, 3 Sep 2010 11:39:37 +0530 Subject: [PATCH 1/7] [IMP] Account: on duplicating fiscal year do not copy the periods, do not copy the journal period of end of year bzr revid: pap@tinyerp.co.in-20100903060937-p1jytkxomm9y1rll --- addons/account/account.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/account/account.py b/addons/account/account.py index 652eddb4218..3a4eea085dd 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -975,6 +975,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() #---------------------------------------------------------- From 62a35f8b0902691e674f56dd1b2d14ba16f280cf Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Fri, 3 Sep 2010 11:56:22 +0530 Subject: [PATCH 2/7] [IMP] account_voucher: Improve YML test cases bzr revid: psi@tinyerp.co.in-20100903062622-ftit23h6ugvdm6g0 --- addons/account_voucher/test/sales_payment.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/account_voucher/test/sales_payment.yml b/addons/account_voucher/test/sales_payment.yml index 050eec1d014..6734b4d599c 100644 --- a/addons/account_voucher/test/sales_payment.yml +++ b/addons/account_voucher/test/sales_payment.yml @@ -18,7 +18,7 @@ property_account_receivable: account.a_recv - - Creat an invoice for the partner + Create an invoice for the partner - !record {model: account.invoice, id: account_invoice_0}: account_id: account.a_recv @@ -72,6 +72,8 @@ 'period_id': ref('account.period_8'), 'type': 'receipt', } + if not res['value']['line_cr_ids']: + res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}] res['value']['line_cr_ids'][0]['amount'] = 450.0 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']] id = self.create(cr, uid, vals) From d93b7ba3bc330aa8574b8a45704f8fbe388f84c5 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Fri, 3 Sep 2010 14:42:56 +0530 Subject: [PATCH 3/7] [IMP] Account: Move line create method if you set the value of journal/period on creation of move line it will not change the value as per context's journal/period ..so you can create different journal/periond with move line bzr revid: mra@mra-laptop-20100903091256-l3ut29d7d1bw1xle --- addons/account/account_move_line.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index cf17c76deff..a2ba1029981 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -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 From cd43bf49df07ba685838b968713a93a94ec2a2a6 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Fri, 3 Sep 2010 16:14:37 +0530 Subject: [PATCH 4/7] [IMP] Account: Bank statement line visible seq field on tree view also bzr revid: mra@mra-laptop-20100903104437-jvrnqrq7jg0jyj2j --- addons/account/account_view.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index a929cd21e6d..1a54d345786 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 @@ -520,7 +520,7 @@ - + @@ -2411,7 +2411,7 @@ - + From 4fd67b69c6b0fc3ce35920df8e8fdc664e1fbc7b Mon Sep 17 00:00:00 2001 From: vra Date: Fri, 3 Sep 2010 16:55:45 +0530 Subject: [PATCH 5/7] [FIX] account: Fixed the opening balance problem in account_cash_statement. bzr revid: vra@tinyerp.com-20100903112545-78hgv1gy6gayvvvt --- addons/account/account_cash_statement.py | 70 +++++++++++++++--------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index 5ed057536a8..5010664e8f2 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"), From 20bbdd3cf1a6604cc6b1bc4110a15268b2fef853 Mon Sep 17 00:00:00 2001 From: "pap (openerp)" Date: Fri, 3 Sep 2010 16:59:50 +0530 Subject: [PATCH 6/7] [IMP] Account: - added analytic_account field on account_model_line - removed wizard asking whether to open entries after creating entries from account model - validating moves through Accounting/Periodical Processing/Draft Entries/Validate Journal Entries wizard validated moves with unbalanced entries too, fixed the bug - added search view on account model bzr revid: pap@tinyerp.co.in-20100903112950-eoferlxasre8pjkw --- addons/account/account.py | 51 ++++++++++--------- addons/account/account_move_line.py | 2 +- addons/account/account_view.xml | 44 ++++++++++++---- addons/account/wizard/account_use_model.py | 26 +++------- .../account/wizard/account_use_model_view.xml | 16 ------ 5 files changed, 72 insertions(+), 67 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 3a4eea085dd..5766a5a1adc 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1129,8 +1129,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 @@ -1150,7 +1151,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 @@ -1421,7 +1422,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() @@ -1986,21 +1988,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, @@ -2008,10 +2015,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, @@ -2027,7 +2040,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() @@ -2040,22 +2053,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_move_line.py b/addons/account/account_move_line.py index a2ba1029981..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 diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 1a54d345786..f720e3c72a8 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -1548,13 +1548,13 @@ - + + - @@ -1571,12 +1571,11 @@ + + - - - @@ -1589,9 +1588,10 @@
- + - + + @@ -1601,6 +1601,7 @@
+ account.model.tree account.model @@ -1609,15 +1610,39 @@ - + + + + account.model.search + account.model + search + + + + + + + + + + + + + + + + + + Recurring Models account.model form - tree,form + tree,form,search + view_model_search @@ -2418,6 +2443,7 @@ + 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 - -
- -