1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
23 from openerp.osv import fields, osv
24 from openerp.tools.translate import _
26 class account_use_model(osv.osv_memory):
28 _name = 'account.use.model'
29 _description = 'Use model'
31 'model': fields.many2many('account.model', 'account_use_model_relation', 'account_id', 'model_id', 'Account Model'),
34 def view_init(self, cr , uid , fields_list, context=None):
35 account_model_obj = self.pool.get('account.model')
38 if context.get('active_ids',False):
39 data_model = account_model_obj.browse(cr, uid, context['active_ids'])
40 for model in data_model:
41 for line in model.lines_id:
42 if line.date_maturity == 'partner':
43 if not line.partner_id:
44 raise osv.except_osv(_('Error!'), _("Maturity date of entry line generated by model line '%s' is based on partner payment term!"\
45 "\nPlease define partner on it!")%line.name)
48 def create_entries(self, cr, uid, ids, context=None):
49 account_model_obj = self.pool.get('account.model')
50 mod_obj = self.pool.get('ir.model.data')
53 data = self.read(cr, uid, ids, context=context)[0]
54 record_id = context and context.get('model_line', False) or False
56 model_ids = data['model']
58 model_ids = context['active_ids']
59 move_ids = account_model_obj.generate(cr, uid, model_ids, context=context)
61 context.update({'move_ids':move_ids})
62 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_move_form')], context=context)
63 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
65 'domain': "[('id','in', ["+','.join(map(str,context['move_ids']))+"])]",
68 'view_mode': 'tree,form',
69 'res_model': 'account.move',
70 'views': [(False,'tree'),(resource_id,'form')],
71 'type': 'ir.actions.act_window',
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: