1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 Domsense s.r.l. (<http://www.domsense.com>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import fields, osv
23
from tools.translate import _
25
class account_invoice(osv.osv):
26
_inherit = "account.invoice"
28
'vat_on_cash': fields.boolean('Vat on cash receipts'),
32
class account_voucher(osv.osv):
33
_inherit = "account.voucher"
35
def action_move_line_create(self, cr, uid, ids, context=None):
36
if isinstance(ids, (int, long)):
40
res = super(account_voucher, self).action_move_line_create(cr, uid, ids, context)
41
invoice_pool=self.pool.get('account.invoice')
42
move_pool=self.pool.get('account.move')
43
line_pool=self.pool.get('account.move.line')
46
# search for reconciled invoices and compute partial payment
47
for voucher in self.browse(cr, uid, ids):
48
for line in voucher.move_ids:
49
if line.reconcile_partial_id:
52
for reconcile_line in line.reconcile_partial_id.line_partial_ids:
53
if reconcile_line.invoice:
54
invoice_id = reconcile_line.invoice.id
55
inv_amount = reconcile_line.invoice.amount_total
56
elif reconcile_line.credit > 0.0:
57
paid_amount += reconcile_line.credit
58
inv_tuple = (invoice_id, paid_amount / inv_amount)
59
if inv_tuple not in invoices:
60
invoices.append(inv_tuple)
62
for reconcile_line in line.reconcile_id.line_id:
63
if reconcile_line.invoice:
64
if (reconcile_line.invoice.id,1) not in invoices:
65
invoices.append((reconcile_line.invoice.id,1))
67
for invoice_tuple in invoices:
68
invoice = invoice_pool.browse(cr, uid, invoice_tuple[0], context)
69
if invoice.vat_on_cash:
71
'name': _('VAT on cash') + ' - ' + invoice.move_id.name,
73
if invoice.journal_id.vat_on_cash_related_journal_id:
74
move_data['journal_id'
75
] = invoice.journal_id.vat_on_cash_related_journal_id.id
77
move_data['journal_id'] = invoice.journal_id.id
78
move_id = move_pool.create(cr, uid, move_data)
79
move = move_pool.browse(cr, uid, move_id)
81
for move_line in invoice.move_id.line_id:
83
if move_line.credit > 0.0:
84
if move_line.account_id.vat_on_cash_related_account_id:
88
'name': _('VAT on cash') + ' - ' + move_line.name,
89
'debit': move_line.debit * invoice_tuple[1],
90
'credit': move_line.credit * invoice_tuple[1],
91
'account_id': move_line.account_id.vat_on_cash_related_account_id.id,
93
'journal_id': move.journal_id.id,
94
'period_id': move.period_id.id,
98
'name': _('VAT on cash') + ' - ' + move_line.name,
99
'debit': move_line.credit * invoice_tuple[1],
100
'credit': move_line.debit * invoice_tuple[1],
101
'account_id': move_line.account_id.id,
103
'journal_id': move.journal_id.id,
104
'period_id': move.period_id.id,
107
if move_line.tax_code_id:
108
shadow_line_data['tax_code_id'] = move_line.tax_code_id.id
109
shadow_line_data['tax_amount'] = (shadow_line_data['credit']
110
- shadow_line_data['debit'])
111
if move_line.tax_code_id.vat_on_cash_related_tax_code_id:
112
line_data['tax_code_id'
113
] = move_line.tax_code_id.vat_on_cash_related_tax_code_id.id
114
line_data['tax_amount'] = (line_data['credit']
115
- line_data['debit'])
117
line_pool.create(cr, uid, line_data)
118
line_pool.create(cr, uid, shadow_line_data)
120
raise osv.except_osv(_('Error!'), _('You are trying to reconcile a "Vat on cash receipts" invoice, but no account used by the invoice has a related account used for real registrations on a VAT on cash basis'))
122
move_pool.post(cr, uid, [move_id], context={})
128
class account_account(osv.osv):
129
_inherit = "account.account"
131
'vat_on_cash_related_account_id': fields.many2one('account.account', 'Account for VAT on cash', help='Related account used for real registrations on a VAT on cash basis'),
135
class account_tax_code(osv.osv):
136
_inherit = "account.tax.code"
138
'vat_on_cash_related_tax_code_id': fields.many2one('account.tax.code', 'Tax code for VAT on cash', help='Related tax code used for real registrations on a VAT on cash basis'),
142
class account_journal(osv.osv):
143
_inherit = "account.journal"
145
'vat_on_cash_related_journal_id': fields.many2one('account.journal', 'Journal for VAT on cash', help='Related journal used for real registrations on a VAT on cash basis'),