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
25 class sale_order(osv.Model):
26 _inherit = 'sale.order'
28 # make the real method inheritable
29 _payment_block_proxy = lambda self, *a, **kw: self._portal_payment_block(*a, **kw)
32 'portal_payment_options': fields.function(_payment_block_proxy, type="html", string="Portal Payment Options"),
35 def _portal_payment_block(self, cr, uid, ids, fieldname, arg, context=None):
36 result = dict.fromkeys(ids, False)
37 payment_acquirer = self.pool.get('portal.payment.acquirer')
38 for this in self.browse(cr, uid, ids, context=context):
39 if this.state not in ('draft', 'cancel') and not this.invoiced:
40 result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.name,
41 this.pricelist_id.currency_id, this.amount_total, context=context)
44 def action_quotation_send(self, cr, uid, ids, context=None):
45 ''' Override to use a modified template that includes a portal signup link '''
46 action_dict = super(sale_order, self).action_quotation_send(cr, uid, ids, context=context)
48 template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal_sale', 'email_template_edi_sale')[1]
49 # assume context is still a dict, as prepared by super
50 ctx = action_dict['context']
51 ctx['default_template_id'] = template_id
52 ctx['default_use_template'] = True
57 def action_button_confirm(self, cr, uid, ids, context=None):
58 # fetch the partner's id and subscribe the partner to the sale order
60 document = self.browse(cr, uid, ids[0], context=context)
61 partner = document.partner_id
62 if partner.id not in document.message_follower_ids:
63 self.message_subscribe(cr, uid, ids, [partner.id], context=context)
64 return super(sale_order, self).action_button_confirm(cr, uid, ids, context=context)
66 def get_signup_url(self, cr, uid, ids, context=None):
68 document = self.browse(cr, uid, ids[0], context=context)
69 partner = document.partner_id
70 action = 'portal_sale.action_quotations_portal' if document.state in ('draft', 'sent') else 'portal_sale.action_orders_portal'
71 partner.signup_prepare()
72 return partner._get_signup_url_for_action(action=action, view_type='form', res_id=document.id)[partner.id]
75 class account_invoice(osv.Model):
76 _inherit = 'account.invoice'
78 # make the real method inheritable
79 _payment_block_proxy = lambda self, *a, **kw: self._portal_payment_block(*a, **kw)
82 'portal_payment_options': fields.function(_payment_block_proxy, type="html", string="Portal Payment Options"),
85 def _portal_payment_block(self, cr, uid, ids, fieldname, arg, context=None):
86 result = dict.fromkeys(ids, False)
87 payment_acquirer = self.pool.get('portal.payment.acquirer')
88 for this in self.browse(cr, uid, ids, context=context):
89 if this.type == 'out_invoice' and this.state not in ('draft', 'done') and not this.reconciled:
90 result[this.id] = payment_acquirer.render_payment_block(cr, uid, this, this.number,
91 this.currency_id, this.residual, context=context)
94 def action_invoice_sent(self, cr, uid, ids, context=None):
95 ''' Override to use a modified template that includes a portal signup link '''
96 action_dict = super(account_invoice, self).action_invoice_sent(cr, uid, ids, context=context)
98 template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal_sale', 'email_template_edi_invoice')[1]
99 # assume context is still a dict, as prepared by super
100 ctx = action_dict['context']
101 ctx['default_template_id'] = template_id
102 ctx['default_use_template'] = True
107 def get_signup_url(self, cr, uid, ids, context=None):
109 document = self.browse(cr, uid, ids[0], context=context)
110 partner = document.partner_id
111 action = 'portal_sale.portal_action_invoices'
112 partner.signup_prepare()
113 return partner._get_signup_url_for_action(action=action, view_type='form', res_id=document.id)[partner.id]
116 class mail_mail(osv.osv):
117 _inherit = 'mail.mail'
119 def _postprocess_sent_message(self, cr, uid, mail, context=None):
120 if mail.model == 'sale.order':
121 so_obj = self.pool.get('sale.order')
122 order = so_obj.browse(cr, uid, mail.res_id, context=context)
123 partner = order.partner_id
124 # Add the customer in the SO as follower
125 if partner.id not in order.message_follower_ids:
126 so_obj.message_subscribe(cr, uid, [mail.res_id], [partner.id], context=context)
127 # Add all recipients of the email as followers
128 for p in mail.partner_ids:
129 if p.id not in order.message_follower_ids:
130 so_obj.message_subscribe(cr, uid, [mail.res_id], [p.id], context=context)
131 return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context)