Launchpad automatic translations update.
[odoo/odoo.git] / addons / portal_sale / portal_sale.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Business Applications
5 #    Copyright (c) 2012 OpenERP S.A. <http://openerp.com>
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from openerp.osv import osv, fields
23
24 class sale_order(osv.Model):
25     _inherit = 'sale.order'
26
27     # make the real method inheritable
28     _payment_block_proxy = lambda self,*a,**kw: self._portal_payment_block(*a, **kw)
29
30     _columns = {
31         'portal_payment_options': fields.function(_payment_block_proxy, type="html", string="Portal Payment Options"),
32     }
33
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)
41         return result
42
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) 
46         try:
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
52         except Exception:
53             pass
54         return action_dict
55
56 class account_invoice(osv.Model):
57     _inherit = 'account.invoice'
58
59     # make the real method inheritable
60     _payment_block_proxy = lambda self,*a,**kw: self._portal_payment_block(*a, **kw)
61
62     _columns = {
63         'portal_payment_options': fields.function(_payment_block_proxy, type="html", string="Portal Payment Options"),
64     }
65
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)
73         return result
74
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) 
78         try:
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
84         except Exception:
85             pass
86         return action_dict