Skip to content

[16.0][IMP] multiple: replace attrs readonly with can_edit computed field#796

Open
madara1150 wants to merge 1 commit into
16.0from
madara1150/16.0-imp-replace-attrs-readonly-with-computed
Open

[16.0][IMP] multiple: replace attrs readonly with can_edit computed field#796
madara1150 wants to merge 1 commit into
16.0from
madara1150/16.0-imp-replace-attrs-readonly-with-computed

Conversation

@madara1150
Copy link
Copy Markdown
Collaborator

Summary

  • Refactor `attrs="{'readonly': [('state', ...)]}"\ patterns across 7 custom modules into a `can_edit` computed Boolean field on each model
  • Centralizes readonly logic in Python (model layer) instead of duplicating state conditions across every XML field
  • Future state changes only require updating a single `_compute_can_edit` method per model

Modules changed

Module Model Fields refactored
`advance_payment` `advance.payment` 4
`agx_sarabun` `sarabun.document` 5
`budget` `budget.transfer` 6
`budget_appropriation` `budget.appropriation` 2
`hr_recruitment_kmitl` `hr.onboarding` 10
`procurement_plan` `procurement.plan` 6 (reuse existing `can_edit`)
`purchase_request_approval_disbursement` `purchase.request.approval` 1
Total 34 fields

Pattern

Before (XML):
```xml

```

After (Python model):
```python
can_edit = fields.Boolean(compute="_compute_can_edit")

@api.depends("state")
def _compute_can_edit(self):
for rec in self:
rec.can_edit = rec.state == "draft"
```

After (XML):
```xml


```

Out of scope

  • `kris_project` / `kris_project_budget` — handled in a separate PR
  • `disbursement` — complex OR conditions combining state with other fields
  • `agx_approval`, `purchase_request_budget` — already use `is_budget_editable` computed field
  • Standard Odoo model inheritors (`accounting_kmitl`, `finance_kmitl`, `purchase_budget`, etc.)
  • Two fields in `advance_payment` with unique single-use conditions (`return_line_ids`, `attachment_ids`)

Test plan

  • Open each affected form view and verify fields are editable in `draft` state
  • Transition record out of `draft` and verify fields become readonly
  • Confirm `can_edit` field is not visible in the UI
  • `procurement_plan`: verify both the existing `can_edit` fields and the 6 newly migrated fields behave consistently

…ield

Refactor state-based attrs readonly conditions across 7 modules into a
centralized can_edit computed Boolean field on each model. This removes
duplicated readonly logic from XML views and makes future state changes
require only a single model-level update.

Modules affected:
- advance_payment (advance.payment)
- agx_sarabun (sarabun.document)
- budget (budget.transfer)
- budget_appropriation (budget.appropriation)
- hr_recruitment_kmitl (hr.onboarding)
- procurement_plan (reuse existing can_edit, fix remaining 6 XML fields)
- purchase_request_approval_disbursement (purchase.request.approval)
@madara1150 madara1150 added the status/ready-for-review Status: Issue is up for grabs label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/ready-for-review Status: Issue is up for grabs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant