8000 move chap4-O2M's default exercise to chap5-defaults section · odoo/documentation@5713223 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5713223

Browse files
committed
move chap4-O2M's default exercise to chap5-defaults section
1 parent 396aeee commit 5713223

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

content/developer/tutorials/server_framework_101/04_relational_fields.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ to a list of offers received from potential buyers.
662662

663663
- :guilabel:`Amount` (required): The amount offered to buy the property.
664664
- :guilabel:`Buyer` (required): The person making the offer.
665-
- :guilabel:`Date` (required; defaults to the creation date): When the offer was made.
665+
- :guilabel:`Date` (required): When the offer was made.
666666
- :guilabel:`Validity` (defaults to 7): The number of days before the offer expires.
667667
- :guilabel:`State` (required): Either :guilabel:`Waiting`, :guilabel:`Accepted`, or
668668
:guilabel:`Refused`.
@@ -674,10 +674,7 @@ to a list of offers received from potential buyers.
674674
#. Modify the form view of properties to display offers in a new notebook page titled
675675
:guilabel:`Offers`.
676676

677-
.. tip::
678-
The `default` field argument expects a callable function, not a precalculated value. If you
679-
mistakenly pass the result of calling the `fields.Date.today` helper function, the field's
680-
default value will be set to the server's start-up time, not the correct date at runtime.
677+
681678

682679
.. spoiler:: Solution
683680

@@ -693,7 +690,7 @@ to a list of offers received from potential buyers.
693690
694691
amount = fields.Float(string="Amount", required=True)
695692
buyer_id = fields.Many2one(string="Buyer", comodel_name='res.partner', required=True)
696-
date = fields.Date(string="Date", required=True, default=fields.Date.today)
693+
date = fields.Date(string="Date", required=True)
697694
validity = fields.Integer(
698695
string="Validity", help="The number of days before the offer expires.", default=7
699696
)

content/developer/tutorials/server_framework_101/05_connect_the_dots.rst

Expand all lines: content/developer/tutorials/server_framework_101/05_connect_the_dots.rst
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,9 @@ the system or context, such as the current date, time, or logged-in user.
930930

931931
Fields can be assigned a default value by including the `default` argument in their declaration.
932932
This argument can be set to a static value or dynamically generated using a callable function, such
933-
as a model method or a lambda function. In both cases, the `self` argument provides access to the
934-
environment but does not represent the current record, as no record exists yet during the creation
935-
process.
933+
as a model method reference or a lambda function. In both cases, the `self` argument provides access
934+
to the environment but does not represent the current record, as no record exists yet during the
935+
creation process.
936936

937937
.. example::
938938
In the following example, a default value is assigned to the `price` and `category_id` fields.
@@ -959,16 +959,25 @@ To make our real estate app more user-friendly, we can help with data entry by p
959959
fields with default values.
960960

961961
.. exercise::
962+
#. Set the default date of offers to today.
962963
#. Set the current user as the default salesperson for new properties.
963964
#. Set the default availability date of properties to two months from today.
964965
#. Assign a random default color to property tags.
965966

966967
.. tip::
968+
- Ensure you pass callable function references as default values, and not the result of
969+
function calls, to avoid setting fixed defaults.
967970
- The current user can be accessed through the `user` environment property.
968971
- Color codes range from 1 to 11.
969972

970973
.. spoiler:: Solution
971974

975+
.. code-block:: python
976+
:caption: `real_estate_offer.py`
977+
:emphasize-lines: 1
978+
979+
date = fields.Date(string="Date", required=True, default=fields.Date.today)
980+
972981
.. code-block:: python
973982
:caption: `real_estate_property.py`
974983
:emphasize-lines: 1-4,6-8

0 commit comments

Comments
 (0)
0