Browse Source

[ADD] partner_password_reset: Create module (#369)

* [ADD] partner_password_reset: Create module
* Create module that allows you to send the password reset emails from the Partner view to any associated `res.users`

* [FIX] partner_password_reset: Fix view & README
* Fix domain filter for button invisibility
* Add runbot to README & Fix spelling
* Align Module name in manifest

* [IMP] partner_password_reset: Convert to Wizard
* Convert functionality from action to wizard
* Update tests

* [IMP] partner_password_reset: Changes per PR review
* Raise test coverage & simplify syntax
pull/330/head
Ted Salmon 7 years ago
committed by Rafael Blasco
parent
commit
53eff8b6c2
  1. 62
      partner_password_reset/README.rst
  2. 5
      partner_password_reset/__init__.py
  3. 23
      partner_password_reset/__openerp__.py
  4. 5
      partner_password_reset/tests/__init__.py
  5. 40
      partner_password_reset/tests/test_res_partner_password_reset_wizard.py
  6. 5
      partner_password_reset/wizard/__init__.py
  7. 42
      partner_password_reset/wizard/res_partner_password_reset_wizard.py
  8. 42
      partner_password_reset/wizard/res_partner_password_reset_wizard_view.xml

62
partner_password_reset/README.rst

@ -0,0 +1,62 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
======================
Partner Password Reset
======================
This module provides a wizard that allows users to send a password reset
email from the Partner view.
Configuration
=============
None required
Usage
=====
To use this module, simply select "Send password reset email" under the partner
view.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/9.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner-contact/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Ted Salmon <tsalmon@laslabs.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

5
partner_password_reset/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import wizard

23
partner_password_reset/__openerp__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Partner Password Reset",
"summary": "Add Wizard to allow resetting of a Partner's associated user "
"password from within the partner view.",
"version": "9.0.1.0.0",
"category": "Customer Relationship Management",
"website": "https://laslabs.com/",
"author": "LasLabs, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
'depends': [
'auth_signup',
'portal',
],
'data': [
'wizard/res_partner_password_reset_wizard_view.xml',
],
}

5
partner_password_reset/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_res_partner_password_reset_wizard

40
partner_password_reset/tests/test_res_partner_password_reset_wizard.py

@ -0,0 +1,40 @@
# -*- 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_fields_view_get(self):
""" It should return the wizard correctly """
partner = self.env.ref('portal.partner_demo_portal')
wizard = self.env['res.partner.password.reset.wizard'].with_context(
active_ids=partner.id
)
output = wizard.fields_view_get()
self.assertEquals(output.get('name'), 'Send Password Reset Email')
self.assertEquals(type(output.get('fields').get('user_ids')), dict)
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()

5
partner_password_reset/wizard/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import res_partner_password_reset_wizard

42
partner_password_reset/wizard/res_partner_password_reset_wizard.py

@ -0,0 +1,42 @@
# -*- 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 """
self.mapped('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