2
#-*- encoding:utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
7
# Developer: Olivier DOSSMANN
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
25
from osv import fields
26
from tools.translate import _
28
class account_invoice_line(osv.osv):
29
_name = 'account.invoice.line'
30
_inherit = 'account.invoice.line'
32
def copy(self, cr, uid, id, default=None, context=None):
38
new_id = super(account_invoice_line, self).copy(cr, uid, id, default, context)
40
if 'split_it' in context:
41
purchase_lines_obj = self.pool.get('purchase.order.line')
42
sale_lines_obj = self.pool.get('sale.order.line')
44
if purchase_lines_obj:
45
purchase_line_ids = purchase_lines_obj.search(cr, uid, [('invoice_lines', 'in', [id])])
47
purchase_lines_obj.write(cr, uid, purchase_line_ids, {'invoice_lines': [(4, new_id)]})
50
sale_lines_ids = sale_lines_obj.search(cr, uid, [('invoice_lines', 'in', [id])])
52
sale_lines_obj.write(cr, uid, sale_lines_ids, {'invoice_lines': [(4, new_id)]})
56
account_invoice_line()
59
class account_invoice(osv.osv):
60
_name = 'account.invoice'
61
_description = 'Account invoice'
63
_inherit = 'account.invoice'
65
def copy(self, cr, uid, id, default=None, context=None):
71
if 'register_line_ids' not in default:
72
default['register_line_ids'] = []
74
new_id = super(account_invoice, self).copy(cr, uid, id, default, context)
76
if 'split_it' in context:
77
purchase_obj = self.pool.get('purchase.order')
78
sale_obj = self.pool.get('sale.order')
81
# attach new invoice to PO
82
purchase_ids = purchase_obj.search(cr, uid, [('invoice_ids', 'in', [id])], context=context)
84
purchase_obj.write(cr, uid, purchase_ids, {'invoice_ids': [(4, new_id)]}, context=context)
86
# attach new invoice to SO
87
sale_ids = sale_obj.search(cr, uid, [('invoice_ids', 'in', [id])], context=context)
89
sale_obj.write(cr, uid, sale_ids, {'invoice_ids': [(4, new_id)]}, context=context)
93
def button_split_invoice(self, cr, uid, ids, context=None):
95
Launch the split invoice wizard to split an invoice in two elements.
100
if isinstance(ids, (int, long)):
103
wiz_lines_obj = self.pool.get('wizard.split.invoice.lines')
104
inv_lines_obj = self.pool.get('account.invoice.line')
106
wizard_id = self.pool.get('wizard.split.invoice').create(cr, uid, {'invoice_id': ids[0]}, context=context)
107
# Add invoices_lines into the wizard
108
invoice_line_ids = self.pool.get('account.invoice.line').search(cr, uid, [('invoice_id', '=', ids[0])], context=context)
109
# Some other verifications
110
if not len(invoice_line_ids):
111
raise osv.except_osv(_('Error'), _('No invoice line in this invoice or not enough elements'))
112
for invl in inv_lines_obj.browse(cr, uid, invoice_line_ids, context=context):
113
wiz_lines_obj.create(cr, uid, {'invoice_line_id': invl.id, 'product_id': invl.product_id.id, 'quantity': invl.quantity,
114
'price_unit': invl.price_unit, 'description': invl.name, 'wizard_id': wizard_id}, context=context)
118
'name': "Split Invoice",
119
'type': 'ir.actions.act_window',
120
'res_model': 'wizard.split.invoice',
122
'view_mode': 'form,tree',
124
'res_id': [wizard_id],
129
'wizard_id': wizard_id,
136
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: