1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Business Applications
5 # Copyright (c) 2012 OpenERP S.A. <http://openerp.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 openerp.osv import osv, fields
24 class sale_order(osv.Model):
25 _inherit = 'sale.order'
27 # make the real method inheritable
28 _payment_block_proxy = lambda self,*a,**kw: self._portal_payment_block(*a, **kw)
31 'portal_payment_options': fields.function(_payment_block_proxy, type="html", string="Portal Payment Options"),
34 def _portal_payment_block(self, cr, uid, ids, fieldname, arg, context=None):
35 result = dict.fromkeys(ids, False)
36 payment_acquirer = self.pool.get('portal.payment.acquirer')
37 for this in self.browse(cr, uid, ids, context=context):
38 if this.state not in ('draft','cancel') and not this.invoiced:
39 result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.name,
40 this.pricelist_id.currency_id, this.amount_total, context=context)
43 def action_quotation_send(self, cr, uid, ids, context=None):
44 ''' Override to use a modified template that includes a portal signup link '''
45 action_dict = super(sale_order, self).action_quotation_send(cr, uid, ids, context=context)
47 template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal_sale', 'email_template_edi_sale')[1]
48 # assume context is still a dict, as prepared by super
49 ctx = action_dict['context']
50 ctx['default_template_id'] = template_id
51 ctx['default_use_template'] = True
56 class account_invoice(osv.Model):
57 _inherit = 'account.invoice'
59 # make the real method inheritable
60 _payment_block_proxy = lambda self,*a,**kw: self._portal_payment_block(*a, **kw)
63 'portal_payment_options': fields.function(_payment_block_proxy, type="html", string="Portal Payment Options"),
66 def _portal_payment_block(self, cr, uid, ids, fieldname, arg, context=None):
67 result = dict.fromkeys(ids, False)
68 payment_acquirer = self.pool.get('portal.payment.acquirer')
69 for this in self.browse(cr, uid, ids, context=context):
70 if this.state not in ('draft','done') and not this.reconciled:
71 result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.number,
72 this.currency_id, this.residual, context=context)
75 def action_invoice_sent(self, cr, uid, ids, context=None):
76 ''' Override to use a modified template that includes a portal signup link '''
77 action_dict = super(account_invoice, self).action_invoice_sent(cr, uid, ids, context=context)
79 template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal_sale', 'email_template_edi_invoice')[1]
80 # assume context is still a dict, as prepared by super
81 ctx = action_dict['context']
82 ctx['default_template_id'] = template_id
83 ctx['default_use_template'] = True