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
##############################################################################
26
from time import strftime
27
from tools.translate import _
28
from tools.misc import join_without_redundancy
30
class account_invoice(osv.osv):
31
_name = 'account.invoice'
32
_inherit = 'account.invoice'
34
def action_reverse_engagement_lines(self, cr, uid, ids, context, *args):
36
Reverse an engagement lines with an opposite amount
40
eng_obj = self.pool.get('account.analytic.line')
42
for inv in self.browse(cr, uid, ids, context=context):
43
# Search engagement journal line ids
44
invl_ids = [x.id for x in inv.invoice_line]
45
eng_ids = eng_obj.search(cr, uid, [('invoice_line_id', 'in', invl_ids)])
46
# Browse engagement journal line ids
47
for eng in eng_obj.browse(cr, uid, eng_ids, context=context):
48
# Create new line and change some fields:
51
# - date with invoice_date
52
# Copy this line for reverse
53
new_line_id = eng_obj.copy(cr, uid, eng.id, context=context)
54
# Prepare reverse values
56
'name': join_without_redundancy(eng.name, 'REV'),
57
'amount': eng.amount * -1,
58
'date': inv.date_invoice,
59
'reversal_origin': eng.id,
62
eng_obj.write(cr, uid, [new_line_id], vals, context=context)
65
def action_open_invoice(self, cr, uid, ids, context={}, *args):
67
Give function to use when changing invoice to open state
69
if not self.action_date_assign(cr, uid, ids, context, args):
71
if not self.action_move_create(cr, uid, ids, context, args):
73
if not self.action_reverse_engagement_lines(cr, uid, ids, context, args):
75
if not self.action_number(cr, uid, ids, context):
77
return self.write(cr, uid, ids, {'state': 'open'}, context=context)
81
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: