Skip to content

Commit

Permalink
[IMP] moving readonly fields mgmt to view and pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
scigghia committed Oct 26, 2024
1 parent cc54f32 commit 6252afe
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 74 deletions.
3 changes: 2 additions & 1 deletion business_requirement/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
and test cases) for your customers",
"version": "18.0.1.0.0",
"website": "https://github.com/OCA/business-requirement",
"author": "Apulia Software, Elico Corp, Tecnativa, Odoo Community Association (OCA)",
"author": "Apulia Software, Elico Corp,\
Tecnativa, Odoo Community Association (OCA)",
"depends": ["product", "portal"],
"data": [
"data/business_data.xml",
Expand Down
4 changes: 2 additions & 2 deletions business_requirement/controllers/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _prepare_home_portal_values(self, counters):
br_model = request.env["business.requirement"]
br_count = (
br_model.search_count(self._prepare_br_base_domain())
if br_model.check_access_rights("read", raise_exception=False)
if br_model.check_access("read")
else 0
)
values["business_requirement_count"] = br_count
Expand Down Expand Up @@ -62,7 +62,7 @@ def portal_my_br(self, page=1, date_begin=None, date_end=None, sortby=None, **kw
values = self._prepare_portal_layout_values()
BRObj = request.env["business.requirement"]
# Avoid error if the user does not have access.
if not BRObj.check_access_rights("read", raise_exception=False):
if not BRObj.check_access("read"):
return request.redirect("/my")

searchbar_sortings = {
Expand Down
58 changes: 16 additions & 42 deletions business_requirement/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,26 @@ class BusinessRequirement(models.Model):
_order = "name desc"

sequence = fields.Char(readonly=True, copy=False, index=True)
name = fields.Char(
readonly=True,
copy=False,
states={"draft": [("readonly", False)]},
)
description = fields.Char(
required=True,
readonly=True,
states={"draft": [("readonly", False)]},
)
business_requirement = fields.Html(
string="Customer Story", readonly=True, states={"draft": [("readonly", False)]}
)
name = fields.Char(readonly=False, copy=False, default="/")
description = fields.Char(required=True, readonly=False)
business_requirement = fields.Html(string="Customer Story", readonly=False)
scenario = fields.Html(
readonly=True,
states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]},
readonly=False,
)
gap = fields.Html(
readonly=True,
states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]},
readonly=False,
)
test_case = fields.Html(
readonly=True,
states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]},
readonly=False,
)
terms_and_conditions = fields.Html(
readonly=True,
states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]},
readonly=False,
)
category_ids = fields.Many2many(
comodel_name="business.requirement.category",
string="Categories",
relation="business_requirement_category_rel",
readonly=True,
states={"draft": [("readonly", False)]},
readonly=False,
)
state = fields.Selection(
selection=[
Expand All @@ -62,18 +47,14 @@ class BusinessRequirement(models.Model):
default="draft",
copy=False,
readonly=False,
states={"draft": [("readonly", False)]},
tracking=True,
)
change_request = fields.Boolean(
string="Change Request?", readonly=True, states={"draft": [("readonly", False)]}
)
change_request = fields.Boolean(string="Change Request?", readonly=False)
partner_id = fields.Many2one(
comodel_name="res.partner",
string="Stakeholder",
copy=False,
readonly=True,
states={"draft": [("readonly", False)]},
readonly=False,
)
priority = fields.Selection(
selection=[("0", "Low"), ("1", "Normal"), ("2", "High")],
Expand All @@ -84,9 +65,8 @@ class BusinessRequirement(models.Model):
comodel_name="res.users",
string="Requested by",
required=True,
readonly=True,
readonly=False,
default=lambda self: self.env.user,
states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]},
)
confirmation_date = fields.Datetime(copy=False, readonly=True)
confirmed_user_id = fields.Many2one(
Expand All @@ -96,16 +76,14 @@ class BusinessRequirement(models.Model):
comodel_name="res.users",
string="Responsible",
copy=False,
readonly=True,
readonly=False,
default=lambda self: self.env.user,
states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]},
)
reviewer_ids = fields.Many2many(
comodel_name="res.users",
string="Reviewers",
copy=False,
readonly=True,
states={"draft": [("readonly", False)], "confirmed": [("readonly", False)]},
readonly=False,
)
approval_date = fields.Datetime(copy=False, readonly=True)
approved_id = fields.Many2one(
Expand All @@ -115,8 +93,7 @@ class BusinessRequirement(models.Model):
comodel_name="res.company",
string="Company",
required=True,
readonly=True,
states={"draft": [("readonly", False)]},
readonly=False,
default=lambda self: self.env.company,
)
to_be_reviewed = fields.Boolean()
Expand All @@ -131,8 +108,7 @@ class BusinessRequirement(models.Model):
)
origin = fields.Char(
string="Source",
readonly=True,
states={"draft": [("readonly", False)], "confirmed": [("readonly", True)]},
readonly=False,
)
portal_published = fields.Boolean("In Portal", default=False)
user_id = fields.Many2one(
Expand Down Expand Up @@ -234,7 +210,6 @@ def message_post(
channel_ids=None,
attachments=None,
attachment_ids=None,
add_sign=True,
record_name=False,
**kwargs,
):
Expand All @@ -260,7 +235,6 @@ def message_post(
partner_ids=partner_ids,
attachments=attachments,
attachment_ids=attachment_ids,
add_sign=add_sign,
record_name=record_name,
**kwargs,
)
Expand Down Expand Up @@ -328,7 +302,7 @@ def get_portal_confirmation_action(self):
def _compute_access_url(self):
super()._compute_access_url()
for br in self:
br.access_url = "/my/business_requirement/%s" % br.id
br.access_url = f"/my/business_requirement/{br.id}"
return

def portal_publish_button(self):
Expand Down
9 changes: 3 additions & 6 deletions business_requirement/tests/test_br.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
from odoo.tests import common


class BusinessRequirementTestBase(common.SavepointCase):
class BusinessRequirementTestBase(common.TransactionCase):
@classmethod
def setUpClass(cls):
def setUpClass(self):
super().setUpClass()
# This is for reducing the diff coming from TransactionCase
self = cls
# Configure.
self.BR = self.env["business.requirement"]
self.br = self.BR.create({"description": "test"})
Expand All @@ -18,12 +16,11 @@ def setUpClass(cls):
class BusinessRequirementTest(BusinessRequirementTestBase):
def test_message_post(self):
self.message = self.br.with_context(
**{"default_model": "business.requirement", "default_res_id": self.br.id}
default_model="business.requirement", default_res_id=self.br.id
).message_post(
body=_("Test Body"),
message_type="notification",
subtype_id=self.env.ref("mail.mt_note").id,
**{},
)
self.assertEqual(self.message.subject, f"Re: {self.br.name}-test")

Expand Down
8 changes: 4 additions & 4 deletions business_requirement/views/br_portal_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
t-attf-class="tr_br_link"
>
<span t-field="br.name" /> - <span
t-field="br.description"
/>
t-field="br.description"
/>
</a>
</td>
<td class="text-right">
Expand All @@ -83,8 +83,8 @@
<h5 class="mb-1 mb-md-0">
<span t-field="br.name" />
<small class="text-muted"> (#<span
t-field="br.id"
/>)</small>
t-field="br.id"
/>)</small>
</h5>
</div>
<div class="col-md text-md-right">
Expand Down
8 changes: 4 additions & 4 deletions business_requirement/views/br_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
t-options='{"widget": "date"}'
/>
<t t-if="o.confirmed_user_id">(<span
t-field="o.confirmed_user_id.name"
/>)</t>
t-field="o.confirmed_user_id.name"
/>)</t>
</td>
</tr>
<tr t-if="o.approval_date">
Expand All @@ -82,8 +82,8 @@
t-options='{"widget": "date"}'
/>
<t t-if="o.approved_id">(<span
t-field="o.approved_id.name"
/>)</t>
t-field="o.approved_id.name"
/>)</t>
</td>
</tr>
</tbody>
Expand Down
73 changes: 58 additions & 15 deletions business_requirement/views/business_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,36 @@
/>
</div>
<h1>
<field name="name" class="oe_inline" readonly="1" /> -
<field name="description" default_focus="1" />
<field
name="name"
class="oe_inline"
readonly="state not in ['draft']"
/> -
<field
name="description"
default_focus="1"
readonly="state not in ['draft']"
/>
</h1>
<group col="4">
<field name="responsible_user_id" required="1" />
<field name="partner_id" />
<field name="origin" />
<field name="category_ids" widget="many2many_tags" />
<field
name="responsible_user_id"
required="1"
readonly="state not in ['draft', 'confirmed']"
/>
<field name="partner_id" readonly="state not in ['draft']" />
<field name="origin" readonly="state not in ['draft']" />
<field
name="category_ids"
widget="many2many_tags"
readonly="state not in ['draft']"
/>
<field name="to_be_reviewed" />
<field name="reviewer_ids" widget="many2many_tags" />
<field
name="reviewer_ids"
widget="many2many_tags"
readonly="state not in ['draft', 'confirmed']"
/>
<field
name="priority"
groups="base.group_user"
Expand All @@ -67,22 +87,39 @@
name="business_requirement"
nolabel="1"
colspan="2"
readonly="state not in ['draft']"
/>
</group>
<group string="Scenario">
<field name="scenario" nolabel="1" colspan="2" />
<field
name="scenario"
nolabel="1"
colspan="2"
readonly="state not in ['draft', 'confirmed']"
/>
</group>
<group string="Gap">
<field name="gap" nolabel="1" colspan="2" />
<field
name="gap"
nolabel="1"
colspan="2"
readonly="state not in ['draft', 'confirmed']"
/>
</group>
<group string="Test Case">
<field name="test_case" nolabel="1" colspan="2" />
<field
name="test_case"
nolabel="1"
colspan="2"
readonly="state not in ['draft', 'confirmed']"
/>
</group>
<group string="Terms and Conditions">
<field
name="terms_and_conditions"
nolabel="1"
colspan="2"
readonly="state not in ['draft', 'confirmed']"
/>
</group>
</page>
Expand All @@ -104,17 +141,24 @@
</page>
<page string="Other" name="other">
<group col="4">
<field name="requested_user_id" />
<field name="change_request" />
<field
name="requested_user_id"
readonly="state not in ['draft', 'confirmed']"
/>
<field
name="change_request"
readonly="state not in ['draft']"
/>
<field
name="company_id"
groups="base.group_multi_company"
readonly="state not in ['draft']"
/>
</group>
</page>
</notebook>
</sheet>
<chatter/>
<chatter />
</form>
</field>
</record>
Expand Down Expand Up @@ -287,8 +331,7 @@
<field name="name">Business requirement</field>
<field name="model">business.requirement</field>
<field name="arch" type="xml">
<pivot string="Business Requirement">
</pivot>
<pivot string="Business Requirement" />
</field>
</record>
<record model="ir.actions.act_window" id="action_business_requirement_tree">
Expand Down

0 comments on commit 6252afe

Please sign in to comment.