codymaster 4.6.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -1
- package/README.md +80 -30
- package/dist/browse-server.js +251 -0
- package/dist/cli/command-registry.js +26 -0
- package/dist/cli/commands/agent.js +120 -0
- package/dist/cli/commands/dashboard.js +93 -0
- package/dist/cli/commands/design-studio.js +111 -0
- package/dist/cli/commands/distro.js +25 -0
- package/dist/cli/commands/engineering.js +488 -0
- package/dist/cli/commands/project.js +324 -0
- package/dist/cli/commands/skill-chain.js +269 -0
- package/dist/cli/commands/system.js +89 -0
- package/dist/cli/commands/task.js +254 -0
- package/dist/cli/update-check.js +83 -0
- package/dist/cm-config.js +110 -0
- package/dist/cm-suggest.js +77 -0
- package/dist/distro-validate.js +54 -0
- package/dist/guardian-core.js +74 -0
- package/dist/index.js +36 -2759
- package/dist/mcp-context-server.js +60 -1
- package/dist/mcp-skills-tools.js +81 -0
- package/dist/retro-summary.js +70 -0
- package/dist/second-opinion-providers.js +79 -0
- package/dist/sprint-pipeline.js +228 -0
- package/dist/storage-backend.js +5 -60
- package/dist/utils/cli-utils.js +76 -0
- package/dist/utils/skill-utils.js +32 -0
- package/install.sh +274 -50
- package/package.json +16 -5
- package/scripts/build-skills.mjs +51 -0
- package/scripts/gate-0-repo-hygiene.js +75 -0
- package/scripts/postinstall.js +55 -0
- package/scripts/security-scan.js +1 -1
- package/scripts/validate-skills.mjs +42 -0
- package/scripts/viking-demo.ts +105 -0
- package/skills/CLAUDE.md +2 -2
- package/skills/cm-ads-tracker/SKILL.md +3 -6
- package/skills/cm-browse/SKILL.md +28 -0
- package/skills/cm-conductor-worktrees/SKILL.md +24 -0
- package/skills/cm-content-factory/SKILL.md +1 -1
- package/skills/cm-content-factory/landing/docs/content/changelog.md +36 -0
- package/skills/cm-content-factory/landing/docs/content/deployment.md +46 -0
- package/skills/cm-content-factory/landing/docs/content/execution-flow.md +67 -0
- package/skills/cm-content-factory/landing/docs/content/openspace.md +27 -0
- package/skills/cm-content-factory/landing/docs/content/openviking.md +33 -0
- package/skills/cm-content-factory/landing/docs/content/use-cases.md +26 -0
- package/skills/cm-content-factory/landing/docs/content/v5-intro.md +28 -0
- package/skills/cm-content-factory/landing/docs/index.html +240 -0
- package/skills/cm-content-factory/landing/index.html +99 -99
- package/skills/cm-content-factory/landing/script.js +42 -0
- package/skills/cm-content-factory/landing/translations.js +400 -400
- package/skills/cm-design-studio/SKILL.md +30 -0
- package/skills/cm-ecosystem-roadmap/SKILL.md +11 -0
- package/skills/cm-engineering-meta/SKILL.md +69 -0
- package/skills/cm-growth-hacking/SKILL.md +1 -12
- package/skills/cm-guardian-runtime/SKILL.md +22 -0
- package/skills/cm-mcp-engineering/SKILL.md +18 -0
- package/skills/cm-notebooklm/SKILL.md +1 -17
- package/skills/cm-post-deploy-canary/SKILL.md +18 -0
- package/skills/cm-qa-visual-cli/SKILL.md +18 -0
- package/skills/cm-retro-cli/SKILL.md +19 -0
- package/skills/cm-second-opinion-cli/SKILL.md +19 -0
- package/skills/cm-secret-shield/SKILL.md +2 -2
- package/skills/cm-sprint-bus/SKILL.md +29 -0
- package/skills/cm-tdd/SKILL.md +61 -74
- package/skills/profiles/README.md +21 -0
- package/skills/profiles/core.txt +23 -0
- package/skills/profiles/design.txt +6 -0
- package/skills/profiles/full.txt +58 -0
- package/skills/profiles/growth.txt +10 -0
- package/skills/profiles/knowledge.txt +7 -0
- package/scripts/test-gemini.js +0 -13
- package/skills/cm-frappe-agent/SKILL.md +0 -134
- package/skills/cm-frappe-agent/agents/doctype-architect.md +0 -596
- package/skills/cm-frappe-agent/agents/erpnext-customizer.md +0 -643
- package/skills/cm-frappe-agent/agents/frappe-backend.md +0 -814
- package/skills/cm-frappe-agent/agents/frappe-custom-frontend.md +0 -557
- package/skills/cm-frappe-agent/agents/frappe-debugger.md +0 -625
- package/skills/cm-frappe-agent/agents/frappe-fixer.md +0 -275
- package/skills/cm-frappe-agent/agents/frappe-frontend.md +0 -660
- package/skills/cm-frappe-agent/agents/frappe-installer.md +0 -158
- package/skills/cm-frappe-agent/agents/frappe-performance.md +0 -307
- package/skills/cm-frappe-agent/agents/frappe-planner.md +0 -419
- package/skills/cm-frappe-agent/agents/frappe-remote-ops.md +0 -153
- package/skills/cm-frappe-agent/agents/github-workflow.md +0 -286
- package/skills/cm-frappe-agent/commands/frappe-app.md +0 -351
- package/skills/cm-frappe-agent/commands/frappe-backend.md +0 -162
- package/skills/cm-frappe-agent/commands/frappe-bench.md +0 -254
- package/skills/cm-frappe-agent/commands/frappe-debug.md +0 -263
- package/skills/cm-frappe-agent/commands/frappe-doctype-create.md +0 -272
- package/skills/cm-frappe-agent/commands/frappe-doctype-field.md +0 -310
- package/skills/cm-frappe-agent/commands/frappe-erpnext.md +0 -210
- package/skills/cm-frappe-agent/commands/frappe-fix.md +0 -59
- package/skills/cm-frappe-agent/commands/frappe-frontend.md +0 -210
- package/skills/cm-frappe-agent/commands/frappe-fullstack.md +0 -243
- package/skills/cm-frappe-agent/commands/frappe-github.md +0 -57
- package/skills/cm-frappe-agent/commands/frappe-install.md +0 -52
- package/skills/cm-frappe-agent/commands/frappe-plan.md +0 -442
- package/skills/cm-frappe-agent/commands/frappe-remote.md +0 -58
- package/skills/cm-frappe-agent/commands/frappe-test.md +0 -356
- package/skills/cm-frappe-agent/docs/README.md +0 -51
- package/skills/cm-frappe-agent/docs/agents-catalog.md +0 -113
- package/skills/cm-frappe-agent/docs/architecture.md +0 -149
- package/skills/cm-frappe-agent/docs/commands-catalog.md +0 -82
- package/skills/cm-frappe-agent/docs/resources-catalog.md +0 -66
- package/skills/cm-frappe-agent/docs/sitemap-urls.txt +0 -52
- package/skills/cm-frappe-agent/docs/sitemap.md +0 -81
- package/skills/cm-frappe-agent/docs/sop/user-guide.md +0 -178
- package/skills/cm-frappe-agent/docs/sop/vibe-coding-guide.md +0 -122
- package/skills/cm-frappe-agent/resources/7-layer-architecture.md +0 -985
- package/skills/cm-frappe-agent/resources/bench_commands.md +0 -73
- package/skills/cm-frappe-agent/resources/code-patterns-guide.md +0 -948
- package/skills/cm-frappe-agent/resources/common_pitfalls.md +0 -266
- package/skills/cm-frappe-agent/resources/doctype-registry.md +0 -158
- package/skills/cm-frappe-agent/resources/installation-guide.md +0 -289
- package/skills/cm-frappe-agent/resources/rest-api-patterns.md +0 -182
- package/skills/cm-frappe-agent/resources/scaffold_checklist.md +0 -82
- package/skills/cm-frappe-agent/resources/upgrade_patterns.md +0 -113
- package/skills/cm-frappe-agent/resources/web-form-patterns.md +0 -252
- package/skills/cm-frappe-agent/skills/bench-commands/SKILL.md +0 -621
- package/skills/cm-frappe-agent/skills/client-scripts/SKILL.md +0 -642
- package/skills/cm-frappe-agent/skills/doctype-patterns/SKILL.md +0 -576
- package/skills/cm-frappe-agent/skills/frappe-api/SKILL.md +0 -740
- package/skills/cm-frappe-agent/skills/remote-operations/SKILL.md +0 -47
- package/skills/cm-frappe-agent/skills/server-scripts/SKILL.md +0 -608
- package/skills/cm-frappe-agent/skills/web-forms/SKILL.md +0 -46
- package/skills/frappe-app-builder.zip +0 -0
|
@@ -1,576 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: doctype-patterns
|
|
3
|
-
description: Frappe DocType creation patterns, field types, controller hooks, and data modeling best practices. Use when creating DocTypes, designing data models, adding fields, or setting up document relationships in Frappe/ERPNext.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Frappe DocType Patterns
|
|
7
|
-
|
|
8
|
-
Comprehensive guide to creating and configuring DocTypes in Frappe Framework, the core building block for all Frappe applications.
|
|
9
|
-
|
|
10
|
-
## When to Use This Skill
|
|
11
|
-
|
|
12
|
-
- Creating new DocTypes
|
|
13
|
-
- Adding or modifying fields on DocTypes
|
|
14
|
-
- Designing data models and relationships
|
|
15
|
-
- Setting up naming patterns and autoname
|
|
16
|
-
- Configuring permissions and workflows
|
|
17
|
-
- Creating child tables
|
|
18
|
-
- Working with Virtual or Single DocTypes
|
|
19
|
-
|
|
20
|
-
## DocType Directory Structure
|
|
21
|
-
|
|
22
|
-
When you create a DocType named "My Custom DocType" in module "My Module":
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
my_app/
|
|
26
|
-
└── my_module/
|
|
27
|
-
└── doctype/
|
|
28
|
-
└── my_custom_doctype/
|
|
29
|
-
├── my_custom_doctype.json # DocType definition
|
|
30
|
-
├── my_custom_doctype.py # Python controller
|
|
31
|
-
├── my_custom_doctype.js # Client script
|
|
32
|
-
├── test_my_custom_doctype.py # Test file
|
|
33
|
-
└── __init__.py
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## DocType JSON Structure
|
|
37
|
-
|
|
38
|
-
```json
|
|
39
|
-
{
|
|
40
|
-
"name": "My Custom DocType",
|
|
41
|
-
"module": "My Module",
|
|
42
|
-
"doctype": "DocType",
|
|
43
|
-
"engine": "InnoDB",
|
|
44
|
-
"field_order": ["field1", "field2"],
|
|
45
|
-
"fields": [
|
|
46
|
-
{
|
|
47
|
-
"fieldname": "field1",
|
|
48
|
-
"fieldtype": "Data",
|
|
49
|
-
"label": "Field 1",
|
|
50
|
-
"reqd": 1
|
|
51
|
-
}
|
|
52
|
-
],
|
|
53
|
-
"permissions": [
|
|
54
|
-
{
|
|
55
|
-
"role": "System Manager",
|
|
56
|
-
"read": 1,
|
|
57
|
-
"write": 1,
|
|
58
|
-
"create": 1,
|
|
59
|
-
"delete": 1
|
|
60
|
-
}
|
|
61
|
-
],
|
|
62
|
-
"autoname": "naming_series:",
|
|
63
|
-
"naming_rule": "By \"Naming Series\" field",
|
|
64
|
-
"is_submittable": 0,
|
|
65
|
-
"istable": 0,
|
|
66
|
-
"issingle": 0,
|
|
67
|
-
"track_changes": 1,
|
|
68
|
-
"sort_field": "modified",
|
|
69
|
-
"sort_order": "DESC"
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Field Types Reference
|
|
74
|
-
|
|
75
|
-
### Text Fields
|
|
76
|
-
| Type | Description | Use Case |
|
|
77
|
-
|------|-------------|----------|
|
|
78
|
-
| `Data` | Single line text (140 chars) | Names, codes, short text |
|
|
79
|
-
| `Small Text` | Multi-line text | Short descriptions |
|
|
80
|
-
| `Text` | Multi-line text (unlimited) | Long descriptions |
|
|
81
|
-
| `Text Editor` | Rich text with formatting | Content, notes |
|
|
82
|
-
| `Code` | Syntax-highlighted code | Python, JS, JSON |
|
|
83
|
-
| `HTML Editor` | WYSIWYG HTML | Email templates |
|
|
84
|
-
| `Markdown Editor` | Markdown input | Documentation |
|
|
85
|
-
| `Password` | Masked input | Secrets (stored encrypted) |
|
|
86
|
-
|
|
87
|
-
### Numeric Fields
|
|
88
|
-
| Type | Description | Use Case |
|
|
89
|
-
|------|-------------|----------|
|
|
90
|
-
| `Int` | Integer | Counts, quantities |
|
|
91
|
-
| `Float` | Decimal number | Measurements |
|
|
92
|
-
| `Currency` | Money with precision | Prices, amounts |
|
|
93
|
-
| `Percent` | 0-100 percentage | Discounts, rates |
|
|
94
|
-
| `Rating` | Star rating (0-1) | Reviews, scores |
|
|
95
|
-
|
|
96
|
-
### Date/Time Fields
|
|
97
|
-
| Type | Description | Use Case |
|
|
98
|
-
|------|-------------|----------|
|
|
99
|
-
| `Date` | Date only | Birth dates, due dates |
|
|
100
|
-
| `Datetime` | Date and time | Timestamps |
|
|
101
|
-
| `Time` | Time only | Schedules |
|
|
102
|
-
| `Duration` | Time duration | Task duration |
|
|
103
|
-
|
|
104
|
-
### Selection Fields
|
|
105
|
-
| Type | Description | Use Case |
|
|
106
|
-
|------|-------------|----------|
|
|
107
|
-
| `Select` | Dropdown options | Status, type |
|
|
108
|
-
| `Check` | Boolean checkbox | Flags, toggles |
|
|
109
|
-
| `Autocomplete` | Text with suggestions | Tags |
|
|
110
|
-
|
|
111
|
-
### Link Fields
|
|
112
|
-
| Type | Description | Use Case |
|
|
113
|
-
|------|-------------|----------|
|
|
114
|
-
| `Link` | Reference to another DocType | Foreign key relationship |
|
|
115
|
-
| `Dynamic Link` | Reference based on another field | Polymorphic links |
|
|
116
|
-
| `Table` | Child table (1-to-many) | Line items, details |
|
|
117
|
-
| `Table MultiSelect` | Many-to-many via link | Multiple selections |
|
|
118
|
-
|
|
119
|
-
### Special Fields
|
|
120
|
-
| Type | Description | Use Case |
|
|
121
|
-
|------|-------------|----------|
|
|
122
|
-
| `Attach` | Single file attachment | Documents |
|
|
123
|
-
| `Attach Image` | Image with preview | Photos, logos |
|
|
124
|
-
| `Image` | Display image from URL field | Gallery |
|
|
125
|
-
| `Signature` | Signature pad | Approvals |
|
|
126
|
-
| `Geolocation` | Map coordinates | Locations |
|
|
127
|
-
| `Barcode` | Barcode/QR display | Inventory |
|
|
128
|
-
| `JSON` | JSON data | Configuration |
|
|
129
|
-
|
|
130
|
-
### Layout Fields
|
|
131
|
-
| Type | Description | Use Case |
|
|
132
|
-
|------|-------------|----------|
|
|
133
|
-
| `Section Break` | Horizontal section divider | Form organization |
|
|
134
|
-
| `Column Break` | Vertical column divider | Multi-column layout |
|
|
135
|
-
| `Tab Break` | Tab navigation | Large forms |
|
|
136
|
-
| `HTML` | Static HTML content | Instructions, headers |
|
|
137
|
-
| `Heading` | Section heading | Visual separation |
|
|
138
|
-
| `Button` | Clickable button | Actions |
|
|
139
|
-
|
|
140
|
-
## Field Options
|
|
141
|
-
|
|
142
|
-
### Common Field Properties
|
|
143
|
-
```json
|
|
144
|
-
{
|
|
145
|
-
"fieldname": "customer",
|
|
146
|
-
"fieldtype": "Link",
|
|
147
|
-
"label": "Customer",
|
|
148
|
-
"options": "Customer",
|
|
149
|
-
"reqd": 1,
|
|
150
|
-
"unique": 0,
|
|
151
|
-
"in_list_view": 1,
|
|
152
|
-
"in_standard_filter": 1,
|
|
153
|
-
"in_global_search": 1,
|
|
154
|
-
"bold": 1,
|
|
155
|
-
"read_only": 0,
|
|
156
|
-
"hidden": 0,
|
|
157
|
-
"print_hide": 0,
|
|
158
|
-
"no_copy": 0,
|
|
159
|
-
"allow_in_quick_entry": 1,
|
|
160
|
-
"translatable": 0,
|
|
161
|
-
"default": "",
|
|
162
|
-
"description": "Select the customer",
|
|
163
|
-
"depends_on": "eval:doc.is_customer",
|
|
164
|
-
"mandatory_depends_on": "eval:doc.status=='Active'",
|
|
165
|
-
"read_only_depends_on": "eval:doc.docstatus==1"
|
|
166
|
-
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### Link Field Options
|
|
170
|
-
```json
|
|
171
|
-
{
|
|
172
|
-
"fieldname": "customer",
|
|
173
|
-
"fieldtype": "Link",
|
|
174
|
-
"options": "Customer",
|
|
175
|
-
"filters": {
|
|
176
|
-
"disabled": 0,
|
|
177
|
-
"customer_type": "Company"
|
|
178
|
-
},
|
|
179
|
-
"ignore_user_permissions": 0
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### Select Field Options
|
|
184
|
-
```json
|
|
185
|
-
{
|
|
186
|
-
"fieldname": "status",
|
|
187
|
-
"fieldtype": "Select",
|
|
188
|
-
"options": "\nDraft\nPending\nApproved\nRejected",
|
|
189
|
-
"default": "Draft"
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### Dynamic Link
|
|
194
|
-
```json
|
|
195
|
-
{
|
|
196
|
-
"fieldname": "party_type",
|
|
197
|
-
"fieldtype": "Link",
|
|
198
|
-
"options": "DocType"
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
"fieldname": "party",
|
|
202
|
-
"fieldtype": "Dynamic Link",
|
|
203
|
-
"options": "party_type"
|
|
204
|
-
}
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
## Naming Patterns (autoname)
|
|
208
|
-
|
|
209
|
-
### Naming Series
|
|
210
|
-
```json
|
|
211
|
-
{
|
|
212
|
-
"autoname": "naming_series:",
|
|
213
|
-
"naming_rule": "By \"Naming Series\" field"
|
|
214
|
-
}
|
|
215
|
-
```
|
|
216
|
-
Add a naming_series field:
|
|
217
|
-
```json
|
|
218
|
-
{
|
|
219
|
-
"fieldname": "naming_series",
|
|
220
|
-
"fieldtype": "Select",
|
|
221
|
-
"options": "INV-.YYYY.-\nINV-.MM.-.YYYY.-",
|
|
222
|
-
"default": "INV-.YYYY.-"
|
|
223
|
-
}
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
### Field-Based Naming
|
|
227
|
-
```json
|
|
228
|
-
{
|
|
229
|
-
"autoname": "field:customer_code",
|
|
230
|
-
"naming_rule": "By fieldname"
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
### Expression-Based
|
|
235
|
-
```json
|
|
236
|
-
{
|
|
237
|
-
"autoname": "format:{customer_type}-{###}",
|
|
238
|
-
"naming_rule": "Expression"
|
|
239
|
-
}
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### Hash/Random
|
|
243
|
-
```json
|
|
244
|
-
{
|
|
245
|
-
"autoname": "hash",
|
|
246
|
-
"naming_rule": "Random"
|
|
247
|
-
}
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
### Prompt (Manual)
|
|
251
|
-
```json
|
|
252
|
-
{
|
|
253
|
-
"autoname": "Prompt",
|
|
254
|
-
"naming_rule": "Set by user"
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
## Controller Lifecycle Hooks
|
|
259
|
-
|
|
260
|
-
```python
|
|
261
|
-
# my_doctype.py
|
|
262
|
-
import frappe
|
|
263
|
-
from frappe.model.document import Document
|
|
264
|
-
|
|
265
|
-
class MyDocType(Document):
|
|
266
|
-
# ===== BEFORE DATABASE OPERATIONS =====
|
|
267
|
-
|
|
268
|
-
def autoname(self):
|
|
269
|
-
"""Set the document name before saving"""
|
|
270
|
-
self.name = f"{self.prefix}-{frappe.generate_hash()[:8]}"
|
|
271
|
-
|
|
272
|
-
def before_naming(self):
|
|
273
|
-
"""Called before autoname, can modify naming logic"""
|
|
274
|
-
pass
|
|
275
|
-
|
|
276
|
-
def validate(self):
|
|
277
|
-
"""Validate data before save (called on insert and update)"""
|
|
278
|
-
self.validate_dates()
|
|
279
|
-
self.calculate_totals()
|
|
280
|
-
|
|
281
|
-
def before_validate(self):
|
|
282
|
-
"""Called before validate"""
|
|
283
|
-
pass
|
|
284
|
-
|
|
285
|
-
def before_save(self):
|
|
286
|
-
"""Called before document is saved to database"""
|
|
287
|
-
self.modified_by_script = True
|
|
288
|
-
|
|
289
|
-
def before_insert(self):
|
|
290
|
-
"""Called before new document is inserted"""
|
|
291
|
-
self.set_defaults()
|
|
292
|
-
|
|
293
|
-
# ===== AFTER DATABASE OPERATIONS =====
|
|
294
|
-
|
|
295
|
-
def after_insert(self):
|
|
296
|
-
"""Called after new document is inserted"""
|
|
297
|
-
self.notify_users()
|
|
298
|
-
|
|
299
|
-
def on_update(self):
|
|
300
|
-
"""Called after document is saved (insert or update)"""
|
|
301
|
-
self.update_related_docs()
|
|
302
|
-
|
|
303
|
-
def after_save(self):
|
|
304
|
-
"""Called after on_update, always runs"""
|
|
305
|
-
pass
|
|
306
|
-
|
|
307
|
-
def on_change(self):
|
|
308
|
-
"""Called when document changes in database"""
|
|
309
|
-
pass
|
|
310
|
-
|
|
311
|
-
# ===== SUBMISSION WORKFLOW =====
|
|
312
|
-
|
|
313
|
-
def before_submit(self):
|
|
314
|
-
"""Called before document is submitted"""
|
|
315
|
-
self.validate_for_submit()
|
|
316
|
-
|
|
317
|
-
def on_submit(self):
|
|
318
|
-
"""Called after document is submitted"""
|
|
319
|
-
self.create_gl_entries()
|
|
320
|
-
|
|
321
|
-
def before_cancel(self):
|
|
322
|
-
"""Called before document is cancelled"""
|
|
323
|
-
self.validate_cancellation()
|
|
324
|
-
|
|
325
|
-
def on_cancel(self):
|
|
326
|
-
"""Called after document is cancelled"""
|
|
327
|
-
self.reverse_gl_entries()
|
|
328
|
-
|
|
329
|
-
def on_update_after_submit(self):
|
|
330
|
-
"""Called when submitted doc is updated (limited fields)"""
|
|
331
|
-
pass
|
|
332
|
-
|
|
333
|
-
# ===== DELETION =====
|
|
334
|
-
|
|
335
|
-
def before_delete(self):
|
|
336
|
-
"""Called before document is deleted"""
|
|
337
|
-
self.check_dependencies()
|
|
338
|
-
|
|
339
|
-
def after_delete(self):
|
|
340
|
-
"""Called after document is deleted"""
|
|
341
|
-
self.cleanup_attachments()
|
|
342
|
-
|
|
343
|
-
def on_trash(self):
|
|
344
|
-
"""Called when document is trashed"""
|
|
345
|
-
pass
|
|
346
|
-
|
|
347
|
-
def after_restore(self):
|
|
348
|
-
"""Called after document is restored from trash"""
|
|
349
|
-
pass
|
|
350
|
-
|
|
351
|
-
# ===== CUSTOM METHODS =====
|
|
352
|
-
|
|
353
|
-
def validate_dates(self):
|
|
354
|
-
if self.end_date and self.start_date > self.end_date:
|
|
355
|
-
frappe.throw("End date cannot be before start date")
|
|
356
|
-
|
|
357
|
-
def calculate_totals(self):
|
|
358
|
-
self.total = sum(d.amount for d in self.items)
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
## Child Table (Table Field)
|
|
362
|
-
|
|
363
|
-
### Parent DocType
|
|
364
|
-
```json
|
|
365
|
-
{
|
|
366
|
-
"fieldname": "items",
|
|
367
|
-
"fieldtype": "Table",
|
|
368
|
-
"label": "Items",
|
|
369
|
-
"options": "My DocType Item",
|
|
370
|
-
"reqd": 1
|
|
371
|
-
}
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
### Child DocType JSON
|
|
375
|
-
```json
|
|
376
|
-
{
|
|
377
|
-
"name": "My DocType Item",
|
|
378
|
-
"module": "My Module",
|
|
379
|
-
"doctype": "DocType",
|
|
380
|
-
"istable": 1,
|
|
381
|
-
"editable_grid": 1,
|
|
382
|
-
"fields": [
|
|
383
|
-
{
|
|
384
|
-
"fieldname": "item",
|
|
385
|
-
"fieldtype": "Link",
|
|
386
|
-
"options": "Item",
|
|
387
|
-
"in_list_view": 1,
|
|
388
|
-
"reqd": 1
|
|
389
|
-
},
|
|
390
|
-
{
|
|
391
|
-
"fieldname": "qty",
|
|
392
|
-
"fieldtype": "Float",
|
|
393
|
-
"in_list_view": 1
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
"fieldname": "rate",
|
|
397
|
-
"fieldtype": "Currency",
|
|
398
|
-
"in_list_view": 1
|
|
399
|
-
},
|
|
400
|
-
{
|
|
401
|
-
"fieldname": "amount",
|
|
402
|
-
"fieldtype": "Currency",
|
|
403
|
-
"in_list_view": 1,
|
|
404
|
-
"read_only": 1
|
|
405
|
-
}
|
|
406
|
-
]
|
|
407
|
-
}
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
## Single DocType (Settings)
|
|
411
|
-
|
|
412
|
-
For application settings that have only one record:
|
|
413
|
-
|
|
414
|
-
```json
|
|
415
|
-
{
|
|
416
|
-
"name": "My App Settings",
|
|
417
|
-
"module": "My Module",
|
|
418
|
-
"doctype": "DocType",
|
|
419
|
-
"issingle": 1,
|
|
420
|
-
"fields": [
|
|
421
|
-
{
|
|
422
|
-
"fieldname": "enable_feature",
|
|
423
|
-
"fieldtype": "Check",
|
|
424
|
-
"label": "Enable Feature"
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
"fieldname": "api_key",
|
|
428
|
-
"fieldtype": "Password",
|
|
429
|
-
"label": "API Key"
|
|
430
|
-
}
|
|
431
|
-
]
|
|
432
|
-
}
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
Access in code:
|
|
436
|
-
```python
|
|
437
|
-
settings = frappe.get_single("My App Settings")
|
|
438
|
-
if settings.enable_feature:
|
|
439
|
-
do_something()
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
## Virtual DocType
|
|
443
|
-
|
|
444
|
-
DocType without database table, computed on-the-fly:
|
|
445
|
-
|
|
446
|
-
```json
|
|
447
|
-
{
|
|
448
|
-
"name": "My Virtual DocType",
|
|
449
|
-
"module": "My Module",
|
|
450
|
-
"doctype": "DocType",
|
|
451
|
-
"is_virtual": 1
|
|
452
|
-
}
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
Controller:
|
|
456
|
-
```python
|
|
457
|
-
class MyVirtualDocType(Document):
|
|
458
|
-
@staticmethod
|
|
459
|
-
def get_list(args):
|
|
460
|
-
# Return list of virtual documents
|
|
461
|
-
return [{"name": "doc1", "value": 100}]
|
|
462
|
-
|
|
463
|
-
@staticmethod
|
|
464
|
-
def get_count(args):
|
|
465
|
-
return len(MyVirtualDocType.get_list(args))
|
|
466
|
-
|
|
467
|
-
@staticmethod
|
|
468
|
-
def get_stats(args):
|
|
469
|
-
return {}
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
## Permissions
|
|
473
|
-
|
|
474
|
-
```json
|
|
475
|
-
{
|
|
476
|
-
"permissions": [
|
|
477
|
-
{
|
|
478
|
-
"role": "System Manager",
|
|
479
|
-
"read": 1,
|
|
480
|
-
"write": 1,
|
|
481
|
-
"create": 1,
|
|
482
|
-
"delete": 1,
|
|
483
|
-
"submit": 1,
|
|
484
|
-
"cancel": 1,
|
|
485
|
-
"amend": 1,
|
|
486
|
-
"report": 1,
|
|
487
|
-
"export": 1,
|
|
488
|
-
"import": 1,
|
|
489
|
-
"share": 1,
|
|
490
|
-
"print": 1,
|
|
491
|
-
"email": 1
|
|
492
|
-
},
|
|
493
|
-
{
|
|
494
|
-
"role": "Sales User",
|
|
495
|
-
"read": 1,
|
|
496
|
-
"write": 1,
|
|
497
|
-
"create": 1,
|
|
498
|
-
"if_owner": 1
|
|
499
|
-
}
|
|
500
|
-
]
|
|
501
|
-
}
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
## Best Practices
|
|
505
|
-
|
|
506
|
-
### Naming Conventions (Strict English Only)
|
|
507
|
-
- **CRITICAL**: **NEVER** use non-ASCII or accented characters (e.g., Vietnamese) in DocType names or fieldnames. This causes fatal SQL parsing errors in MariaDB/Frappe Insights.
|
|
508
|
-
- **DocType Names**: English, singular, Title Case with spaces (e.g., "Sales Invoice", not "Hóa đơn bán hàng").
|
|
509
|
-
- **Fieldnames**: English, `snake_case` (e.g., `customer_name`, not `tên_khách_hàng`).
|
|
510
|
-
- **Localization**: Use the `label` field for non-English display text (e.g., `"fieldname": "violation_name", "label": "Tên vi phạm"`).
|
|
511
|
-
|
|
512
|
-
### Field Design
|
|
513
|
-
- Put most important fields first
|
|
514
|
-
- Use Section Breaks to organize
|
|
515
|
-
- Use Tab Breaks for complex forms
|
|
516
|
-
- Set `in_list_view` for key fields
|
|
517
|
-
- Set `in_standard_filter` for filterable fields
|
|
518
|
-
|
|
519
|
-
### Performance
|
|
520
|
-
- Index frequently queried fields with `search_index: 1`
|
|
521
|
-
- Use `read_only` to prevent unnecessary validation
|
|
522
|
-
- Limit child table rows with `max_attachments`
|
|
523
|
-
|
|
524
|
-
### Data Integrity
|
|
525
|
-
- Use `unique: 1` for unique constraints
|
|
526
|
-
- Set appropriate `reqd` (required) flags
|
|
527
|
-
- Use `depends_on` for conditional visibility
|
|
528
|
-
- Use `mandatory_depends_on` for conditional requirements
|
|
529
|
-
|
|
530
|
-
## Common Patterns
|
|
531
|
-
|
|
532
|
-
### Status Field Pattern
|
|
533
|
-
```json
|
|
534
|
-
{
|
|
535
|
-
"fieldname": "status",
|
|
536
|
-
"fieldtype": "Select",
|
|
537
|
-
"options": "\nDraft\nPending Approval\nApproved\nRejected",
|
|
538
|
-
"default": "Draft",
|
|
539
|
-
"in_list_view": 1,
|
|
540
|
-
"in_standard_filter": 1,
|
|
541
|
-
"read_only": 1,
|
|
542
|
-
"allow_on_submit": 1
|
|
543
|
-
}
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
### Amount Calculation Pattern
|
|
547
|
-
```json
|
|
548
|
-
[
|
|
549
|
-
{"fieldname": "qty", "fieldtype": "Float"},
|
|
550
|
-
{"fieldname": "rate", "fieldtype": "Currency"},
|
|
551
|
-
{"fieldname": "amount", "fieldtype": "Currency", "read_only": 1}
|
|
552
|
-
]
|
|
553
|
-
```
|
|
554
|
-
With controller:
|
|
555
|
-
```python
|
|
556
|
-
def validate(self):
|
|
557
|
-
for item in self.items:
|
|
558
|
-
item.amount = flt(item.qty) * flt(item.rate)
|
|
559
|
-
self.total = sum(item.amount for item in self.items)
|
|
560
|
-
```
|
|
561
|
-
|
|
562
|
-
### Linked Document Pattern
|
|
563
|
-
```json
|
|
564
|
-
{
|
|
565
|
-
"fieldname": "customer",
|
|
566
|
-
"fieldtype": "Link",
|
|
567
|
-
"options": "Customer",
|
|
568
|
-
"reqd": 1
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
"fieldname": "customer_name",
|
|
572
|
-
"fieldtype": "Data",
|
|
573
|
-
"fetch_from": "customer.customer_name",
|
|
574
|
-
"read_only": 1
|
|
575
|
-
}
|
|
576
|
-
```
|