Browse Source

[IMP] portal_partner_select_all: black, isort, prettier

14.0
Stephan Keller 4 years ago
committed by skeller1
parent
commit
670ccf6c47
  1. 21
      portal_partner_select_all/__manifest__.py
  2. 31
      portal_partner_select_all/tests/test_portal_partner_select_all.py
  3. 16
      portal_partner_select_all/wizard/portal_wizard.py
  4. 17
      portal_partner_select_all/wizard/portal_wizard.xml

21
portal_partner_select_all/__manifest__.py

@ -1,18 +1,13 @@
# Copyright 2018 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'Portal Partner Select All',
'version': '12.0.1.0.2',
'category': 'Custom',
'author': 'Tecnativa,'
'Odoo Community Association (OCA)',
'website': 'https://www.github.com/OCA/partner-contact',
"name": "Portal Partner Select All",
"version": "12.0.1.0.2",
"category": "Custom",
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://www.github.com/OCA/partner-contact",
"license": "AGPL-3",
'depends': [
'portal',
],
'data': [
'wizard/portal_wizard.xml',
],
'installable': True,
"depends": ["portal",],
"data": ["wizard/portal_wizard.xml",],
"installable": True,
}

31
portal_partner_select_all/tests/test_portal_partner_select_all.py

@ -1,22 +1,27 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tests import common, Form
from odoo.tests import Form, common
class TestPortalPartnerSelctAll(common.TransactionCase):
def setUp(self):
super().setUp()
Partner = self.env["res.partner"]
self.partner1 = Partner.create({'name': 'P1', 'email': 'p1@p1'})
self.partner2 = Partner.create({'name': 'P2', 'email': 'p2@p2'})
self.partner3 = Partner.create({'name': 'P3', 'email': 'p3@p3'})
self.wizard_all = self.env["portal.wizard"].with_context({
'active_ids': [self.partner1.id, self.partner2.id]
}).create({})
self.wizard_default = self.env["portal.wizard"].with_context({
'active_ids': [self.partner1.id, self.partner2.id, self.partner3.id]
}).create({})
self.partner1 = Partner.create({"name": "P1", "email": "p1@p1"})
self.partner2 = Partner.create({"name": "P2", "email": "p2@p2"})
self.partner3 = Partner.create({"name": "P3", "email": "p3@p3"})
self.wizard_all = (
self.env["portal.wizard"]
.with_context({"active_ids": [self.partner1.id, self.partner2.id]})
.create({})
)
self.wizard_default = (
self.env["portal.wizard"]
.with_context(
{"active_ids": [self.partner1.id, self.partner2.id, self.partner3.id]}
)
.create({})
)
def test_portal_partner_select_all_wizard(self):
# check selecting all
@ -27,8 +32,8 @@ class TestPortalPartnerSelctAll(common.TransactionCase):
# partner should have user records with assigned portal group
self.assertTrue(self.partner1.user_ids, "Partner should have user")
self.assertTrue(self.partner2.user_ids, "Partner should have user")
self.assertTrue(self.partner1.user_ids[0].has_group('base.group_portal'))
self.assertTrue(self.partner2.user_ids[0].has_group('base.group_portal'))
self.assertTrue(self.partner1.user_ids[0].has_group("base.group_portal"))
self.assertTrue(self.partner2.user_ids[0].has_group("base.group_portal"))
# checking toogle
wizard_default_form = Form(self.wizard_default)

16
portal_partner_select_all/wizard/portal_wizard.py

@ -6,20 +6,16 @@ from odoo import api, fields, models
class PortalWizard(models.TransientModel):
_inherit = "portal.wizard"
set_all_users = fields.Boolean(
string="Invite all the contacts",
default=False,
)
set_all_users = fields.Boolean(string="Invite all the contacts", default=False,)
@api.onchange('set_all_users')
@api.onchange("set_all_users")
def onchange_set_all_users(self):
"""Toggle between select all partners and the default"""
if not self.set_all_users:
for user in self.user_ids:
user.in_portal = (
user.partner_id.user_ids and
user.partner_id.user_ids[0].has_group("base.group_portal")
)
user.in_portal = user.partner_id.user_ids and user.partner_id.user_ids[
0
].has_group("base.group_portal")
else:
not_in_portal = self.user_ids.filtered(lambda x: not x.in_portal)
not_in_portal.update({'in_portal': True})
not_in_portal.update({"in_portal": True})

17
portal_partner_select_all/wizard/portal_wizard.xml

@ -1,21 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="ir.ui.view" id="portal_wizard">
<field name="model">portal.wizard</field>
<field name="inherit_id" ref="portal.wizard_view"/>
<field name="inherit_id" ref="portal.wizard_view" />
<field name="arch" type="xml">
<field name="user_ids" position="before">
<group>
<field name="set_all_users" string="Invite all the contacts"/>
<field name="set_all_users" string="Invite all the contacts" />
</group>
<div class="card bg-warning mb8" attrs="{'invisible': [('set_all_users', '=', False)]}">
<div
class="card bg-warning mb8"
attrs="{'invisible': [('set_all_users', '=', False)]}"
>
<div class="card-body bg-warning">
<i class="fa fa-warning"/> You're about to invite to portal all the contacts list below.
<i
class="fa fa-warning"
/> You're about to invite to portal all the contacts list below.
</div>
</div>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save