From 1eb80d32354038344d7f99f06c81a0ca46afdb06 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Thu, 23 Sep 2010 14:15:12 +0530 Subject: [PATCH] [IMP] account: Recurring model -> convert company field to related with journal's company [REF] Account: Periond view make company and fiscalyear widget=selection bzr revid: mra@mra-laptop-20100923084512-vy0epr9d0fvcj0vv --- addons/account/account.py | 16 ++++++++++------ addons/account/account_view.xml | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index ae506290ff3..282233276c6 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1996,26 +1996,28 @@ class account_model(osv.osv): _columns = { 'name': fields.char('Model Name', size=64, required=True, help="This is a model for recurring accounting entries"), 'journal_id': fields.many2one('account.journal', 'Journal', required=True), - 'company_id': fields.many2one('res.company', 'Company', required=True), + 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True), 'lines_id': fields.one2many('account.model.line', 'model_id', 'Model Entries'), 'legend' :fields.text('Legend', readonly=True, size=100), } _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, } - def generate(self, cr, uid, ids, datas={}, context={}): + def generate(self, cr, uid, ids, datas={}, context=None): move_ids = [] entry = {} account_move_obj = self.pool.get('account.move') account_move_line_obj = self.pool.get('account.move.line') pt_obj = self.pool.get('account.payment.term') - if datas.get('date', False): - context.update({'date':datas['date']}) - period_id = self.pool.get('account.period').find(cr, uid, dt=context.get('date', False)) + if context is None: + context = {} + if datas.get('date', False): + 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] @@ -2069,7 +2071,9 @@ class account_model(osv.osv): c = context.copy() c.update({'journal_id': model.journal_id.id,'period_id': period_id}) account_move_line_obj.create(cr, uid, val, context=c) + return move_ids + account_model() class account_model_line(osv.osv): diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index cfc44109472..bfe32537708 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -95,8 +95,8 @@ - - + +