1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
6
# Copyright (c) 2012 Noviat nv/sa (www.noviat.be). All rights reserved.
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Affero General Public License for more details.
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
23
from osv import osv, fields
25
from tools.translate import _
27
_logger = logging.getLogger(__name__)
29
class account_invoice(osv.osv):
30
_inherit = 'account.invoice'
33
'cashflow_code_id': fields.many2one('account.cashflow.code', 'Cash Flow Code', domain=[('type', '=', 'provision')],
34
readonly=True, states={'draft':[('readonly',False)]},
35
help="Specify Cash Flow Code in order to override the Cash Flow Code Assignment Rules."),
36
'cashflow_journal_id': fields.many2one('account.journal', 'Payment Method',
37
context={'journal_type': False}, domain=[('type', 'in', ['bank','cash'])],
38
readonly=True, states={'draft':[('readonly',False)]},
39
help="Specify the financial journal for the payment of this invoice or credit note."),
42
def action_cfc_create(self, cr, uid, ids, *args):
43
cfpline_obj = self.pool.get('account.cashflow.provision.line')
44
for inv in self.browse(cr, uid, ids):
45
if inv.type in ['out_invoice', 'in_refund']:
46
if inv.currency_id != inv.company_id.currency_id: # To DO : adapt for multi-currency support
48
cfpline_amount = inv.amount_total
49
cfpline_journal_id = inv.cashflow_journal_id and inv.cashflow_journal_id.id
50
cfpline_company_id = inv.journal_id.company_id.id
51
cfpline_partner_id = inv.partner_id.id
52
cfpline_note = _('Provision for') + ' ' + (inv.type == 'out_invoice' and _('Customer Invoice') or _('Supplier Refund')) + ' ' + inv.internal_number
53
cfpline_account_id = inv.account_id.id
54
cfpline_type = 'customer'
55
cfpline_date = inv.date_due or inv.date_invoice
56
communication = inv.reference or ''
57
cfpline_cfc_id = False
58
if inv.cashflow_code_id:
59
cfpline_cfc_id = inv.cashflow_code_id.id
61
# assign Cash Flow Code via rules engine
63
'journal_id': cfpline_journal_id,
64
'company_id': cfpline_company_id,
65
'account_id': cfpline_account_id,
66
'partner_id': cfpline_partner_id,
67
'sign': cfpline_amount >= 0 and 'debit' or 'credit',
69
#if context.get('extra_fields', None):
70
# kwargs['extra_fields'] = context['extra_fields']
71
cfc_id = self.pool.get('account.cashflow.rule').cfc_id_get(cr, uid, **kwargs)
73
cfpline_cfc_id = self.pool.get('account.cashflow.code').browse(cr, uid, cfc_id).twin_id.id
74
if not cfpline_cfc_id:
77
cfpline_obj.create(cr, uid, {
78
'description': (inv.type == 'out_invoice' and _('Customer Invoice') or _('Customer Refund')) + ' ' + inv.internal_number,
79
'cashflow_code_id': cfpline_cfc_id,
82
'origin': inv._name + ',' + str(inv.id),
83
'journal_id': cfpline_journal_id,
84
'val_date': cfpline_date,
85
'amount': cfpline_amount,
86
'partner_id': cfpline_partner_id,
87
'name': communication,
88
'company_id': cfpline_company_id,
90
'account_id': cfpline_account_id,
95
def action_cancel(self, cr, uid, ids, *args):
96
super(account_invoice, self).action_cancel(cr, uid, ids, *args)
97
cfpline_obj = self.pool.get('account.cashflow.provision.line')
98
for inv in self.browse(cr, uid, ids):
99
domain = [ ('origin', '=', inv._name + ',' + str(inv.id))]
100
cfpline_ids = cfpline_obj.search(cr, uid, domain)
101
if len(cfpline_ids) > 1:
102
raise osv.except_osv(_('Warning'), _('Cash Flow Provision Line ambiguity, cf. lines %s') % cfpline_ids)
103
elif len(cfpline_ids) == 1:
104
cfpline_obj.write(cr, uid, [cfpline_ids[0]], {'state': 'draft'})
105
cfpline_obj.unlink(cr, uid, [cfpline_ids[0]])
b'\\ No newline at end of file'