2010-04-21 05:37:36 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
import time
|
|
|
|
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.osv import fields, osv
|
|
|
|
from openerp.tools.translate import _
|
2010-04-21 05:37:36 +00:00
|
|
|
|
|
|
|
class account_use_model(osv.osv_memory):
|
|
|
|
|
|
|
|
_name = 'account.use.model'
|
|
|
|
_description = 'Use model'
|
|
|
|
_columns = {
|
2010-06-16 11:51:39 +00:00
|
|
|
'model': fields.many2many('account.model', 'account_use_model_relation', 'account_id', 'model_id', 'Account Model'),
|
2010-08-19 11:51:57 +00:00
|
|
|
}
|
2010-09-06 09:41:24 +00:00
|
|
|
|
2010-09-06 09:14:45 +00:00
|
|
|
def view_init(self, cr , uid , fields_list, context=None):
|
|
|
|
account_model_obj = self.pool.get('account.model')
|
|
|
|
if context is None:
|
|
|
|
context = {}
|
|
|
|
if context.get('active_ids',False):
|
|
|
|
data_model = account_model_obj.browse(cr, uid, context['active_ids'])
|
|
|
|
for model in data_model:
|
|
|
|
for line in model.lines_id:
|
|
|
|
if line.date_maturity == 'partner':
|
|
|
|
if not line.partner_id:
|
2012-08-07 11:31:37 +00:00
|
|
|
raise osv.except_osv(_('Error!'), _("Maturity date of entry line generated by model line '%s' is based on partner payment term!"\
|
2010-11-15 18:46:17 +00:00
|
|
|
"\nPlease define partner on it!")%line.name)
|
2010-09-06 09:14:45 +00:00
|
|
|
pass
|
2010-04-21 05:37:36 +00:00
|
|
|
|
|
|
|
def create_entries(self, cr, uid, ids, context=None):
|
|
|
|
account_model_obj = self.pool.get('account.model')
|
|
|
|
mod_obj = self.pool.get('ir.model.data')
|
|
|
|
if context is None:
|
|
|
|
context = {}
|
2010-06-16 11:51:39 +00:00
|
|
|
data = self.read(cr, uid, ids, context=context)[0]
|
2010-04-21 05:37:36 +00:00
|
|
|
record_id = context and context.get('model_line', False) or False
|
|
|
|
if record_id:
|
2011-11-16 14:13:40 +00:00
|
|
|
model_ids = data['model']
|
2010-04-21 05:37:36 +00:00
|
|
|
else:
|
2011-11-16 14:13:40 +00:00
|
|
|
model_ids = context['active_ids']
|
|
|
|
move_ids = account_model_obj.generate(cr, uid, model_ids, context=context)
|
2010-09-06 09:41:24 +00:00
|
|
|
|
2010-09-03 11:29:50 +00:00
|
|
|
context.update({'move_ids':move_ids})
|
2010-04-21 05:37:36 +00:00
|
|
|
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 {
|
|
|
|
'domain': "[('id','in', ["+','.join(map(str,context['move_ids']))+"])]",
|
|
|
|
'name': 'Entries',
|
|
|
|
'view_type': 'form',
|
|
|
|
'view_mode': 'tree,form',
|
|
|
|
'res_model': 'account.move',
|
|
|
|
'views': [(False,'tree'),(resource_id,'form')],
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-15 18:46:17 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|