~sergio-incaser/openerp-spain/openerp-spain

« back to all changes in this revision

Viewing changes to l10n_es_extras/sale_paytype/sale_paytype.py

  • Committer: Jordi Esteve
  • Date: 2009-12-14 17:53:50 UTC
  • mfrom: (81.1.90 lp-openerp-spain-5.0)
  • Revision ID: jesteve@zikzakmedia.com-20091214175350-6vzzt3avtsof25a2
Recuperación del estado actual del repositorio de localización española de OpenERP: Aplicación de todos los merges pendientes desde la versión 81 (15-11-2008) hasta la actual (02-12-2009)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
 
3
 
##############################################################################
4
 
#
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
10
 
# Service Company
11
 
#
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.
16
 
#
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.
21
 
#
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.
25
 
#
26
 
##############################################################################
27
 
 
28
 
import netsvc
29
 
from osv import fields, osv
30
 
 
31
 
 
32
 
# añadimos a pedidos de venta los campos relativos a la forma de pago 
33
 
class sale_order(osv.osv):
34
 
        _inherit='sale.order'
35
 
        _columns={
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)]} ),          
39
 
        }
40
 
        
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)
44
 
                tipopago_id = False
45
 
                if part:
46
 
                        partner_line = self.pool.get('res.partner').browse(cr, uid, part)
47
 
                        if partner_line:
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
51
 
                                
52
 
                return self.onchange_tipopago_id(cr, uid, ids, tipopago_id, part, result)
53
 
 
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)
60
 
                                if bank_account_id:
61
 
                                        result['value']['acc_number'] = bank_account_id[0]
62
 
                                        return result
63
 
                result['value']['acc_number'] = False
64
 
                return result
65
 
 
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)
72
 
                return inv_id   
73
 
        
74
 
sale_order()