2010-03-04 07:40:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
2010-08-13 12:20:05 +00:00
|
|
|
#
|
2010-03-04 07:40:44 +00:00
|
|
|
# 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
|
2010-08-13 12:20:05 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-03-04 07:40:44 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.osv import fields, osv
|
2010-03-04 07:40:44 +00:00
|
|
|
|
|
|
|
class make_invoice(osv.osv_memory):
|
|
|
|
_name = 'mrp.repair.make_invoice'
|
|
|
|
_description = 'Make Invoice'
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2010-03-04 07:40:44 +00:00
|
|
|
_columns = {
|
2010-12-27 08:40:32 +00:00
|
|
|
'group': fields.boolean('Group by partner invoice address'),
|
2010-03-04 07:40:44 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
def make_invoices(self, cr, uid, ids, context=None):
|
2010-04-06 06:52:09 +00:00
|
|
|
""" Generates invoice(s) of selected records.
|
|
|
|
@param self: The object pointer.
|
|
|
|
@param cr: A database cursor
|
|
|
|
@param uid: ID of the user currently logged in
|
2010-08-13 12:20:05 +00:00
|
|
|
@param ids: List of IDs selected
|
|
|
|
@param context: A standard dictionary
|
2010-04-06 06:52:09 +00:00
|
|
|
@return: Loads the view of new invoice(s).
|
2010-03-10 07:17:18 +00:00
|
|
|
"""
|
2010-11-23 07:05:05 +00:00
|
|
|
if context is None:
|
2010-11-19 13:48:01 +00:00
|
|
|
context = {}
|
|
|
|
inv = self.browse(cr, uid, ids[0], context=context)
|
2010-08-13 12:20:05 +00:00
|
|
|
order_obj = self.pool.get('mrp.repair')
|
2012-11-20 10:40:37 +00:00
|
|
|
mod_obj = self.pool.get('ir.model.data')
|
2010-08-13 12:20:05 +00:00
|
|
|
newinv = order_obj.action_invoice_create(cr, uid, context['active_ids'],
|
|
|
|
group=inv.group,context=context)
|
2012-01-24 14:42:30 +00:00
|
|
|
|
|
|
|
# We have to trigger the workflow of the given repairs, otherwise they remain 'to be invoiced'.
|
|
|
|
# Note that the signal 'action_invoice_create' will trigger another call to the method 'action_invoice_create',
|
|
|
|
# but that second call will not do anything, since the repairs are already invoiced.
|
2014-07-06 14:44:26 +00:00
|
|
|
order_obj.signal_workflow(cr, uid, context['active_ids'], 'action_invoice_create')
|
2010-08-13 12:20:05 +00:00
|
|
|
|
2012-11-20 10:40:37 +00:00
|
|
|
form_res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_form')
|
|
|
|
form_id = form_res and form_res[1] or False
|
|
|
|
tree_res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_tree')
|
2015-08-12 09:19:42 +00:00
|
|
|
tree_id = tree_res and tree_res[1] or False
|
2012-11-20 10:40:37 +00:00
|
|
|
|
2010-03-04 07:40:44 +00:00
|
|
|
return {
|
|
|
|
'domain': [('id','in', newinv.values())],
|
|
|
|
'name': 'Invoices',
|
|
|
|
'view_type': 'form',
|
|
|
|
'view_mode': 'tree,form',
|
|
|
|
'res_model': 'account.invoice',
|
|
|
|
'view_id': False,
|
2012-11-20 10:40:37 +00:00
|
|
|
'views': [(tree_id, 'tree'),(form_id, 'form')],
|
2010-03-04 07:40:44 +00:00
|
|
|
'context': "{'type':'out_invoice'}",
|
|
|
|
'type': 'ir.actions.act_window'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|