Skip to content

Commit

Permalink
Update good_practices.md
Browse files Browse the repository at this point in the history
  • Loading branch information
altela authored Jul 18, 2024
1 parent 4d38339 commit 4c4fc0b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/good_practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Why?

Also, avoid naming field via .xml because it will make user confused. Declaring in .xml will only appear on XML level so when user exporting records to .xlsx (Excel File) they fill have a hard time.

---

## Never Use `store=True` For Computed Fields
Never declare a computed field with parameter `store=True`.

Expand All @@ -46,12 +48,16 @@ def compute_money_count(self):

That's because it will lead to a consistency issue. `money_count` above is supposed to keep calculation when certain condition are met. If the `@api.depends()` decorator are triggered, the first calculation will be saved into the database. However, the second or third may not (at it will still use the first calculation result) and it's really dangerous. Make sure to never store any calculated field into database.

---

## Always Define `company_id` field to support multicompany
The title says it all. Just do it.
```python
company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company)
```

---

## Always Broke Your Code Into Parts
Split your code into different method. This will ensure the code is reusable.
- Using single parameter like `self` is fine.
Expand Down

0 comments on commit 4c4fc0b

Please sign in to comment.