From 6252afeea1c088ef235d3985db244b9610ee2f1a Mon Sep 17 00:00:00 2001 From: Andrea Cometa Date: Fri, 25 Oct 2024 18:04:50 +0200 Subject: [PATCH] [IMP] moving readonly fields mgmt to view and pep8 --- business_requirement/__manifest__.py | 3 +- business_requirement/controllers/portal.py | 4 +- business_requirement/models/business.py | 58 ++++----------- business_requirement/tests/test_br.py | 9 +-- .../views/br_portal_templates.xml | 8 +- business_requirement/views/br_report.xml | 8 +- business_requirement/views/business_view.xml | 73 +++++++++++++++---- 7 files changed, 89 insertions(+), 74 deletions(-) diff --git a/business_requirement/__manifest__.py b/business_requirement/__manifest__.py index 7b1dd182..69d21f40 100644 --- a/business_requirement/__manifest__.py +++ b/business_requirement/__manifest__.py @@ -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", diff --git a/business_requirement/controllers/portal.py b/business_requirement/controllers/portal.py index a93b62ce..4e65ee4b 100644 --- a/business_requirement/controllers/portal.py +++ b/business_requirement/controllers/portal.py @@ -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 @@ -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 = { diff --git a/business_requirement/models/business.py b/business_requirement/models/business.py index c7065a39..a322da54 100644 --- a/business_requirement/models/business.py +++ b/business_requirement/models/business.py @@ -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=[ @@ -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")], @@ -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( @@ -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( @@ -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() @@ -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( @@ -234,7 +210,6 @@ def message_post( channel_ids=None, attachments=None, attachment_ids=None, - add_sign=True, record_name=False, **kwargs, ): @@ -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, ) @@ -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): diff --git a/business_requirement/tests/test_br.py b/business_requirement/tests/test_br.py index 0b53d5b6..bee4bd3b 100644 --- a/business_requirement/tests/test_br.py +++ b/business_requirement/tests/test_br.py @@ -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"}) @@ -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") diff --git a/business_requirement/views/br_portal_templates.xml b/business_requirement/views/br_portal_templates.xml index 87743ff5..87f63c0d 100644 --- a/business_requirement/views/br_portal_templates.xml +++ b/business_requirement/views/br_portal_templates.xml @@ -61,8 +61,8 @@ t-attf-class="tr_br_link" > - + t-field="br.description" + /> @@ -83,8 +83,8 @@
(#) + t-field="br.id" + />)
diff --git a/business_requirement/views/br_report.xml b/business_requirement/views/br_report.xml index 70168148..465afe56 100644 --- a/business_requirement/views/br_report.xml +++ b/business_requirement/views/br_report.xml @@ -68,8 +68,8 @@ t-options='{"widget": "date"}' /> () + t-field="o.confirmed_user_id.name" + />) @@ -82,8 +82,8 @@ t-options='{"widget": "date"}' /> () + t-field="o.approved_id.name" + />) diff --git a/business_requirement/views/business_view.xml b/business_requirement/views/business_view.xml index f3887ea4..9383f6ea 100644 --- a/business_requirement/views/business_view.xml +++ b/business_requirement/views/business_view.xml @@ -44,16 +44,36 @@ />

- - - + - +

- - - - + + + + - + - + - + - + @@ -104,17 +141,24 @@ - - + + - + @@ -287,8 +331,7 @@ Business requirement business.requirement - - +