[MIG] portal_sale : migrate code to new API
This commit is contained in:
@@ -1,34 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.osv import osv
|
||||
from openerp import SUPERUSER_ID
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class account_invoice(osv.Model):
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
def invoice_validate(self, cr, uid, ids, context=None):
|
||||
@api.multi
|
||||
def invoice_validate(self):
|
||||
# fetch the partner's id and subscribe the partner to the invoice
|
||||
for invoice in self.browse(cr, uid, ids, context=context):
|
||||
partner = invoice.partner_id
|
||||
if partner not in invoice.message_partner_ids:
|
||||
self.message_subscribe(cr, uid, [invoice.id], [partner.id], context=context)
|
||||
return super(account_invoice, self).invoice_validate(cr, uid, ids, context=context)
|
||||
for invoice in self:
|
||||
if invoice.partner_id not in invoice.message_partner_ids:
|
||||
invoice.message_subscribe([invoice.partner_id.id])
|
||||
return super(AccountInvoice, self).invoice_validate()
|
||||
|
||||
def get_signup_url(self, cr, uid, ids, context=None):
|
||||
assert len(ids) == 1
|
||||
document = self.browse(cr, uid, ids[0], context=context)
|
||||
contex_signup = dict(context, signup_valid=True)
|
||||
return self.pool['res.partner']._get_signup_url_for_action(
|
||||
cr, uid, [document.partner_id.id], action='/mail/view',
|
||||
model=self._name, res_id=document.id, context=contex_signup,
|
||||
)[document.partner_id.id]
|
||||
@api.multi
|
||||
def get_signup_url(self):
|
||||
self.ensure_one()
|
||||
return self.partner_id.with_context(signup_valid=True)._get_signup_url_for_action(
|
||||
action='/mail/view',
|
||||
model=self._name,
|
||||
res_id=self.id)[self.partner_id.id]
|
||||
|
||||
def get_formview_action(self, cr, uid, id, context=None):
|
||||
context = context or {}
|
||||
user = self.pool['res.users'].browse(cr, SUPERUSER_ID, context.get('uid', uid), context=context)
|
||||
if user.share:
|
||||
return self.pool['ir.actions.act_window'].for_xml_id(cr, uid, 'portal_sale', 'portal_action_invoices', context=context)
|
||||
return super(account_invoice, self).get_formview_action(cr, uid, id, context=context)
|
||||
@api.multi
|
||||
def get_formview_action(self):
|
||||
# NOTE : if this method is call as sudo, the only to determine if the user is portal is to check the uid from context
|
||||
# This was introduced with https://github.com/odoo/odoo/commit/f5fedbcb18a57ee9aeab952f3ff95f692f7a863c, and should be better fixed.
|
||||
uid = self.env.context.get('uid', self.env.user.id)
|
||||
if self.env['res.users'].sudo().browse(uid).share:
|
||||
return self.env['ir.actions.act_window'].for_xml_id('portal_sale', 'portal_action_invoices')
|
||||
return super(AccountInvoice, self).get_formview_action()
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
from openerp.osv import osv
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class mail_mail(osv.osv):
|
||||
class Mail(models.Model):
|
||||
_inherit = 'mail.mail'
|
||||
|
||||
def _postprocess_sent_message(self, cr, uid, mail, context=None, mail_sent=True):
|
||||
if mail_sent and mail.model == 'sale.order':
|
||||
so_obj = self.pool.get('sale.order')
|
||||
order = so_obj.browse(cr, uid, mail.res_id, context=context)
|
||||
partner = order.partner_id
|
||||
# Add the customer in the SO as follower
|
||||
if partner not in order.message_partner_ids:
|
||||
so_obj.message_subscribe(cr, uid, [mail.res_id], [partner.id], context=context)
|
||||
# Add all recipients of the email as followers
|
||||
for p in mail.partner_ids:
|
||||
if p not in order.message_partner_ids:
|
||||
so_obj.message_subscribe(cr, uid, [mail.res_id], [p.id], context=context)
|
||||
return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context, mail_sent=mail_sent)
|
||||
@api.multi
|
||||
def _postprocess_sent_message_v9(self, mail_sent=True):
|
||||
for mail in self:
|
||||
if mail_sent and mail.model == 'sale.order':
|
||||
order = self.env['sale.order'].browse(mail.res_id)
|
||||
partner = order.partner_id
|
||||
# Add the customer in the SO as follower
|
||||
if partner not in order.message_partner_ids:
|
||||
order.message_subscribe([partner.id])
|
||||
# Add all recipients of the email as followers
|
||||
for partner in mail.partner_ids:
|
||||
if partner not in order.message_partner_ids:
|
||||
order.message_subscribe([partner.id])
|
||||
return super(Mail, self)._postprocess_sent_message_v9(mail_sent=mail_sent)
|
||||
|
||||
@@ -1,41 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.osv import osv, fields
|
||||
from openerp import SUPERUSER_ID
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class sale_order(osv.Model):
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
def action_confirm(self, cr, uid, ids, context=None):
|
||||
@api.multi
|
||||
def action_confirm(self):
|
||||
# fetch the partner's id and subscribe the partner to the sale order
|
||||
if not isinstance(ids, (tuple, list)):
|
||||
ids = [ids]
|
||||
assert len(ids) == 1
|
||||
document = self.browse(cr, uid, ids[0], context=context)
|
||||
partner = document.partner_id
|
||||
if partner not in document.message_partner_ids:
|
||||
self.message_subscribe(cr, uid, ids, [partner.id], context=context)
|
||||
return super(sale_order, self).action_confirm(cr, uid, ids, context=context)
|
||||
for order in self:
|
||||
if order.partner_id not in order.message_partner_ids:
|
||||
order.message_subscribe([order.partner_id.id])
|
||||
return super(SaleOrder, self).action_confirm()
|
||||
|
||||
def get_signup_url(self, cr, uid, ids, context=None):
|
||||
if not isinstance(ids, (tuple, list)):
|
||||
ids = [ids]
|
||||
assert len(ids) == 1
|
||||
document = self.browse(cr, uid, ids[0], context=context)
|
||||
contex_signup = dict(context, signup_valid=True)
|
||||
return self.pool['res.partner']._get_signup_url_for_action(
|
||||
cr, uid, [document.partner_id.id], action='/mail/view',
|
||||
model=self._name, res_id=document.id, context=contex_signup,
|
||||
)[document.partner_id.id]
|
||||
@api.multi
|
||||
def get_signup_url(self):
|
||||
self.ensure_one()
|
||||
return self.partner_id.with_context(signup_valid=True)._get_signup_url_for_action(
|
||||
action='/mail/view',
|
||||
model=self._name,
|
||||
res_id=self.id)[self.partner_id.id]
|
||||
|
||||
def get_formview_action(self, cr, uid, id, context=None):
|
||||
context = context or {}
|
||||
user = self.pool['res.users'].browse(cr, SUPERUSER_ID, context.get('uid', uid), context=context)
|
||||
if user.share:
|
||||
document = self.browse(cr, uid, id, context=context)
|
||||
action_xmlid = 'action_quotations_portal' if document.state in ('draft', 'sent') else 'action_orders_portal'
|
||||
return self.pool['ir.actions.act_window'].for_xml_id(cr, uid, 'portal_sale', action_xmlid, context=context)
|
||||
return super(sale_order, self).get_formview_action(cr, uid, id, context=context)
|
||||
@api.multi
|
||||
def get_formview_action(self):
|
||||
# NOTE : if this method is call as sudo, the only to determine if the user is portal is to check the uid from context
|
||||
# This was introduced with https://github.com/odoo/odoo/commit/f5fedbcb18a57ee9aeab952f3ff95f692f7a863c, and should be better fixed.
|
||||
uid = self.env.context.get('uid', self.env.user.id)
|
||||
if self.env['res.users'].sudo().browse(uid).share:
|
||||
action_xmlid = 'action_quotations_portal' if self.state in ('draft', 'sent') else 'action_orders_portal'
|
||||
return self.env['ir.actions.act_window'].for_xml_id('portal_sale', action_xmlid)
|
||||
return super(SaleOrder, self).get_formview_action()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
|
||||
<!-- Sale Portal Access Rules -->
|
||||
@@ -45,4 +45,4 @@
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
<record id="view_account_invoice_filter_share" model="ir.ui.view">
|
||||
<field name="name">account.invoice.select.share</field>
|
||||
@@ -129,5 +128,4 @@
|
||||
<menuitem name="Invoices" id="portal_invoices" parent="portal.portal_orders"
|
||||
action="portal_action_invoices" sequence="30"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user