1
# -*- encoding: utf-8 -*-
3
##############################################################################
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
29
from osv import fields, osv
32
# añadimos a pedidos de venta los campos relativos a la forma de pago
33
class sale_order(osv.osv):
36
'tipopago_id': fields.many2one('account.paytype', 'Tipo de Pago'),
37
'acc_number': fields.many2one('res.partner.bank','Account number', select=True,),
38
'payment_term': fields.many2one('account.payment.term', 'Payment Term',readonly=True, states={'draft':[('readonly',False)]} ),
41
def onchange_partner_id2(self, cr, uid, ids, part):
42
# Copia los datos del partner en el pedido, incluyendo payment_term y el nuevo campo tipopago_id
43
result = self.onchange_partner_id(cr, uid, ids, part)
46
partner_line = self.pool.get('res.partner').browse(cr, uid, part)
48
tipopago_id = partner_line.tipopago_id.id
49
result['value']['tipopago_id'] = tipopago_id
50
result['value']['payment_term'] = partner_line.property_payment_term.id
52
return self.onchange_tipopago_id(cr, uid, ids, tipopago_id, part, result)
54
def onchange_tipopago_id(self, cr, uid, ids, tipopago_id, partner_id, result = {'value': {}}):
55
if tipopago_id and partner_id:
56
if self.pool.get('account.paytype').browse(cr, uid, [tipopago_id])[0].link_bank: # Si la forma de pago está asociada a una cuenta bancaria
57
partner_bank_obj = self.pool.get('res.partner.bank')
58
args = [('partner_id', '=', partner_id), ('default_bank', '=', 1)]
59
bank_account_id = partner_bank_obj.search(cr, uid, args)
61
result['value']['acc_number'] = bank_account_id[0]
63
result['value']['acc_number'] = False
66
# redefinimos _make_invoice para que
67
# la factura generada recoja el payment_term, tipopago_id y acc_number del pedido de venta.
68
def _make_invoice(self, cr, uid, order, lines):
69
inv_id = super(sale_order, self)._make_invoice(cr, uid, order, lines)
70
inv_obj = self.pool.get('account.invoice').browse(cr, uid, [inv_id])[0]
71
inv_obj.write(cr, uid, inv_id, {'payment_term':order.payment_term.id,'tipopago_id':order.tipopago_id.id,'acc_number':order.acc_number.id}, None)