[IMP] stock_sms: Fix non admin flow and improve first confirm box
Fix: A simple user is allowed to confirm sending sms wizard. Improve SMS wizard: remove things about policiy and creation of iap account. closes odoo/odoo#37016 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
@@ -59,14 +59,14 @@ class Picking(models.Model):
|
||||
('res_id', 'in', self.ids),
|
||||
('model', '=', 'stock.picking')]).ids
|
||||
if self.env['ir.config_parameter'].sudo().get_param('stock_sms.already_notified', False):
|
||||
if self.env['sms.sms'].search_count([
|
||||
if self.env['sms.sms'].sudo().search_count([
|
||||
('mail_message_id', 'in', mail_message_ids),
|
||||
('state', '=', 'sent'),
|
||||
('error_code', '=', False)]):
|
||||
# The SMS is sent, the company has again credits
|
||||
self.env['ir.config_parameter'].sudo().set_param('stock_sms.already_notified', False)
|
||||
else:
|
||||
if self.env['sms.sms'].search_count([
|
||||
if self.env['sms.sms'].sudo().search_count([
|
||||
('mail_message_id', 'in', mail_message_ids),
|
||||
('error_code', '=', 'sms_credit')]):
|
||||
# The SMS is sent, the company has no more credits
|
||||
@@ -76,6 +76,6 @@ class Picking(models.Model):
|
||||
'model': 'res.users',
|
||||
'res_id': admin.id,
|
||||
}
|
||||
mail_template.send_mail(admin.id, email_values=email_values, notif_layout='mail.mail_notification_light')
|
||||
mail_template.sudo().send_mail(admin.id, email_values=email_values, notif_layout='mail.mail_notification_light')
|
||||
|
||||
self.env['ir.config_parameter'].sudo().set_param('stock_sms.already_notified', True)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models, exceptions
|
||||
|
||||
import requests
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ConfirmStockSms(models.TransientModel):
|
||||
@@ -12,30 +10,18 @@ class ConfirmStockSms(models.TransientModel):
|
||||
|
||||
picking_id = fields.Many2one('stock.picking', required=True)
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, related='picking_id.company_id')
|
||||
iap_account = fields.Boolean(compute='_compute_iap_account')
|
||||
|
||||
def _compute_iap_account(self):
|
||||
self.iap_account = self.env['iap.account'].get('sms', force_create=False)
|
||||
|
||||
def send_sms(self):
|
||||
self.ensure_one()
|
||||
if not self.company_id.has_received_warning_stock_sms:
|
||||
IAP = self.env['iap.account']
|
||||
if not IAP.get('sms', force_create=False):
|
||||
IAP.get('sms')
|
||||
url = IAP.get_credits_url(service_name='sms', trial=True)
|
||||
try:
|
||||
req = requests.get(url)
|
||||
req.raise_for_status()
|
||||
except (ValueError, requests.exceptions.ConnectionError, requests.exceptions.MissingSchema, requests.exceptions.Timeout, requests.exceptions.HTTPError):
|
||||
raise exceptions.AccessError('The url that this service requested returned an error. Please contact the author of the app. The url it tried to contact was ' + url)
|
||||
|
||||
self.company_id.has_received_warning_stock_sms = True
|
||||
self.company_id.sudo().write({'has_received_warning_stock_sms': True})
|
||||
return self.picking_id.button_validate()
|
||||
|
||||
def dont_send_sms(self):
|
||||
self.ensure_one()
|
||||
if not self.company_id.has_received_warning_stock_sms:
|
||||
self.company_id.has_received_warning_stock_sms = True
|
||||
self.company_id.stock_move_sms_validation = False
|
||||
self.company_id.sudo().write({
|
||||
'has_received_warning_stock_sms': True,
|
||||
'stock_move_sms_validation': False,
|
||||
})
|
||||
return self.picking_id.button_validate()
|
||||
|
||||
@@ -5,15 +5,8 @@
|
||||
<field name="model">confirm.stock.sms</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="SMS">
|
||||
<field name="iap_account" invisible="1"/>
|
||||
You are about to confirm this Delivery Order by SMS Text Message.<br/>
|
||||
This feature can easily be disabled from the Settings of Inventory or by clicking on "Disable SMS".<br/>
|
||||
<br/>
|
||||
<p attrs="{'invisible': [('iap_account', '=', True)]}">
|
||||
When confirming the sending of the SMS Text Message, you will be granted free trial credits.<br/>
|
||||
By buying a pack and using the IAP service, you accept the <a href="https://iap.odoo.com/privacy#sms" target="_blank">Privacy Policy</a> of the service provider
|
||||
and the <a href="https://www.odoo.com/privacy" target="_blank">Odoo Privacy Policy</a>.
|
||||
</p>
|
||||
<group invisible="1">
|
||||
<field name="picking_id" invisible="1"/>
|
||||
<field name="company_id" invisible="1"/>
|
||||
|
||||
Reference in New Issue
Block a user