forked from OCA/account-payment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoucher.py
65 lines (58 loc) · 2.91 KB
/
voucher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Agile Business Group sagl
# (<http://www.agilebg.com>)
#
# 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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, orm
from tools.translate import _
class voucher_line(orm.Model):
_inherit = 'account.voucher.line'
def get_suppl_inv_num(self, cr, uid, move_line_id, context=None):
move_line = self.pool.get('account.move.line').browse(cr, uid, move_line_id, context)
return (move_line.invoice and move_line.invoice.supplier_invoice_number or '')
def _get_supplier_invoice_number(self, cr, uid, ids, name, args, context=None):
res={}
for line in self.browse(cr, uid, ids, context):
res[line.id] = ''
if line.move_line_id:
res[line.id] = self.get_suppl_inv_num(cr, uid,
line.move_line_id.id, context=context)
return res
_columns = {
'supplier_invoice_number': fields.function(_get_supplier_invoice_number,
type='char', size=64, string="Supplier Invoice Number"),
}
class voucher(orm.Model):
_inherit = 'account.voucher'
def recompute_voucher_lines(self, cr, uid, ids, partner_id, journal_id, price,
currency_id, ttype, date, context=None):
res = super(voucher,self).recompute_voucher_lines(cr, uid, ids, partner_id,
journal_id, price,
currency_id, ttype, date, context=context)
line_obj = self.pool.get('account.voucher.line')
if res.get('value') and res['value'].get('line_cr_ids'):
for vals in res['value']['line_cr_ids']:
if vals.get('move_line_id'):
vals['supplier_invoice_number'] = line_obj.get_suppl_inv_num(
cr, uid, vals['move_line_id'], context=context)
if res.get('value') and res['value'].get('line_dr_ids'):
for vals in res['value']['line_dr_ids']:
if vals.get('move_line_id'):
vals['supplier_invoice_number'] = line_obj.get_suppl_inv_num(
cr, uid, vals['move_line_id'], context=context)
return res