Browse Source

[IMP] partner_password_reset: Convert to Wizard

* Convert functionality from action to wizard
* Update tests
pull/383/head
Ted Salmon 8 years ago
parent
commit
bda50f100e
No known key found for this signature in database GPG Key ID: 1E92222DD9AF3435
  1. 4
      partner_password_reset/README.rst
  2. 2
      partner_password_reset/__init__.py
  3. 5
      partner_password_reset/__manifest__.py
  4. 13
      partner_password_reset/models/res_partner.py
  5. 2
      partner_password_reset/tests/__init__.py
  6. 23
      partner_password_reset/tests/test_res_partner.py
  7. 30
      partner_password_reset/tests/test_res_partner_password_reset_wizard.py
  8. 20
      partner_password_reset/views/res_partner_view.xml
  9. 2
      partner_password_reset/wizard/__init__.py
  10. 43
      partner_password_reset/wizard/res_partner_password_reset_wizard.py
  11. 42
      partner_password_reset/wizard/res_partner_password_reset_wizard_view.xml

4
partner_password_reset/README.rst

@ -6,8 +6,8 @@
Partner Password Reset Partner Password Reset
====================== ======================
This module provides an action that allows users to send a password reset
email from the Partner view.
This module provides a wizard that allows users to send a password reset email
from the Partner view.
Configuration Configuration
============= =============

2
partner_password_reset/__init__.py

@ -2,4 +2,4 @@
# Copyright 2017 LasLabs Inc. # Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
from . import wizard

5
partner_password_reset/__manifest__.py

@ -4,7 +4,7 @@
{ {
"name": "Partner Password Reset", "name": "Partner Password Reset",
"summary": "Add Action to allow resetting of a Partner's associated user "
"summary": "Add Wizard to allow resetting of a Partner's associated user "
"password from within the partner view.", "password from within the partner view.",
"version": "10.0.1.0.0", "version": "10.0.1.0.0",
"category": "Customer Relationship Management", "category": "Customer Relationship Management",
@ -15,8 +15,9 @@
"installable": True, "installable": True,
'depends': [ 'depends': [
'auth_signup', 'auth_signup',
'portal',
], ],
'data': [ 'data': [
'views/res_partner_view.xml',
'wizard/res_partner_password_reset_wizard_view.xml',
], ],
} }

13
partner_password_reset/models/res_partner.py

@ -1,13 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models
class ResPartner(models.Model):
_inherit = 'res.partner'
@api.multi
def action_reset_user_password(self):
self.mapped('user_ids').action_reset_password()

2
partner_password_reset/tests/__init__.py

@ -2,4 +2,4 @@
# Copyright 2017 LasLabs Inc. # Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_res_partner
from . import test_res_partner_password_reset_wizard

23
partner_password_reset/tests/test_res_partner.py

@ -1,23 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from mock import MagicMock
from odoo.tests.common import TransactionCase
class TestResPartner(TransactionCase):
def setUp(self):
super(TestResPartner, self).setUp()
self.partner = self.env['res.partner'].search([
('user_ids', '!=', ''),
], limit=1)
def test_action_reset_user_password(self):
""" It should call user_ids.action_reset_password """
self.env['res.users']._patch_method(
'action_reset_password', MagicMock()
)
self.partner.action_reset_user_password()
self.env['res.users'].action_reset_password.assert_called_once()

30
partner_password_reset/tests/test_res_partner_password_reset_wizard.py

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from mock import MagicMock
from openerp.exceptions import Warning
from openerp.tests.common import TransactionCase
class TestResPartnerPasswordResetWizard(TransactionCase):
def test_exception_no_users(self):
""" It should raise `Warning` when there are no associated users """
wizard = self.env['res.partner.password.reset.wizard'].with_context(
active_ids=[]
)
with self.assertRaises(Warning):
wizard.fields_view_get()
def test_action_submit(self):
""" It should call user_ids.action_reset_password """
self.env['res.users']._patch_method(
'action_reset_password', MagicMock()
)
partners = self.env.ref('portal.partner_demo_portal')
wizard = self.env['res.partner.password.reset.wizard'].with_context(
active_ids=partners.ids
)
wizard.action_submit()
self.env['res.users'].action_reset_password.assert_called_once()

20
partner_password_reset/views/res_partner_view.xml

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_partner_reset_user_password" model="ir.ui.view">
<field name="name">Partner Reset User Password</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet" position="before">
<header>
<button name="action_reset_user_password" type="object"
string="Send Password Reset Email"
attrs="{'invisible': [('user_ids', '=', [])]}"
groups="base.group_user" />
</header>
</xpath>
</field>
</record>
</odoo>

2
partner_password_reset/models/__init__.py → partner_password_reset/wizard/__init__.py

@ -2,4 +2,4 @@
# Copyright 2017 LasLabs Inc. # Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import res_partner
from . import res_partner_password_reset_wizard

43
partner_password_reset/wizard/res_partner_password_reset_wizard.py

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import _, api, exceptions, fields, models
class ResPartnerPasswordResetWizard(models.TransientModel):
_name = 'res.partner.password.reset.wizard'
user_ids = fields.Many2many(
comodel_name='res.users',
default=lambda s: s._default_user_ids(),
required=True,
readonly=True,
)
@api.multi
def _default_user_ids(self):
""" Return a RecordSet of `res.users` associated to the active IDs """
partner_ids = self.env['res.partner'].browse(
self.env.context.get('active_ids')
)
return partner_ids.mapped('user_ids')
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
submenu=False):
""" Override to check that there are associated users when called """
res = super(ResPartnerPasswordResetWizard, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=False)
if not self._default_user_ids():
raise exceptions.Warning(
_('The selected partners have no associated portal users')
)
return res
@api.multi
def action_submit(self):
""" Reset the user passwords on submission """
for rec in self:
rec.user_ids.action_reset_password()

42
partner_password_reset/wizard/res_partner_password_reset_wizard_view.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 LasLabs Inc.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_partner_password_reset_wizard" model="ir.ui.view">
<field name="name">Send Password Reset Email</field>
<field name="model">res.partner.password.reset.wizard</field>
<field name="arch" type="xml">
<form string="Send Password Reset Email(s)">
<h3>Are you sure you want to reset the password for
the following Users?</h3>
<field name="user_ids">
<tree create="false" delete="false">
<field name="partner_id"/>
<field name="email"/>
</tree>
</field>
<footer>
<button name="action_submit"
string="Confirm"
type="object"
class="oe_highlight" />
or
<button string="Cancel" special="cancel" />
</footer>
</form>
</field>
</record>
<act_window id="action_view_partner_password_reset_wizard"
name="Send Password Reset Email"
src_model="res.partner"
res_model="res.partner.password.reset.wizard"
view_type="form"
view_mode="form"
key2="client_action_multi"
target="new"
groups="base.group_user" />
</odoo>
Loading…
Cancel
Save