pyvelm.fields¶
fields ¶
Field ¶
Descriptor that routes attribute access through env.cache.
A Field is declared on a model class. At class-creation time the metaclass calls bind() so the field knows its name and owning model. Reads route through the cache (loading from SQL on miss); writes update the cache and persist immediately (Stage 1 has no transaction batching — see CONTEXT.md).
Source code in pyvelm/fields.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
make
classmethod
¶
bare
classmethod
¶
Return a field instance (for tests, SQLAlchemy columns, etc.).
Char() inside a model class body starts a fluent chain; outside
a model use Char.bare() when you need a concrete descriptor.
Source code in pyvelm/fields.py
Code ¶
Bases: Text
Source-code field with a declared language.
Stored as TEXT, never sanitized — the value is the operator's
code, not HTML that will be embedded in a page. The render layer
picks the CodeMirror editor automatically based on the field
class. language seeds the editor's syntax highlighting
("python", "javascript", "json", "sql", "html",
"css", "xml", "markdown", "text") and can be
overridden per view via widget_options={"language": "..."}.
Source code in pyvelm/fields.py
Html ¶
Bases: Text
Rich-text/HTML field. Stored as TEXT; sanitized on write.
The value is run through :func:pyvelm.html_sanitizer.sanitize_html
in to_python and to_sql_param so an unsafe payload never
reaches the database. The render layer picks the HTML editor widget
automatically for this field type — no widget="html" needed in
the view arch (still accepted for back-compat).
Use it for any column that holds operator-authored HTML: email template bodies, rich chatter content, knowledge base articles.
Source code in pyvelm/fields.py
Monetary ¶
Bases: Float
A Float that carries a sibling-field reference to its currency.
currency_field names a Many2one(res.currency) on the same
record. Widgets read it to format the amount (symbol + rounding);
the model layer treats Monetary identically to Float — the value
is just a double in the column.
round_with(amount, currency) snaps an amount to the currency's
rounding step using banker's rounding via Python's built-in
round(). Use it from application code when you want stored
values normalised; the field itself does not auto-round on write
(consistent with Float — explicit is better than magic).
Source code in pyvelm/fields.py
round_with
staticmethod
¶
Round amount to currency.rounding.
Tolerates an empty-recordset currency (no rounding info) by
returning the amount unchanged. Uses decimal.Decimal to
avoid the binary-float round(12.345 / 0.01) * 0.01 ==
12.34 trap.
Source code in pyvelm/fields.py
Datetime ¶
Bases: Field
A naive (no-tzinfo) datetime, stored as timestamp.
Accepts datetime, ISO 8601 strings, or HTML datetime-local
submissions (YYYY-MM-DDTHH:MM) on write.
Source code in pyvelm/fields.py
Date ¶
Bases: Field
A calendar date, stored as date.
Accepts date, datetime (truncated to day), or
YYYY-MM-DD strings (Flowbite datepicker / ISO).
Source code in pyvelm/fields.py
Time ¶
Bases: Field
Time of day, stored as time without time zone.
Accepts time, datetime (truncated), or HH:MM strings.
Source code in pyvelm/fields.py
Many2one ¶
Bases: Field
Stores an int FK column; exposes a singleton (or empty) recordset.
The cache holds the raw int (or None). The descriptor wraps reads in
env[comodel_name].browse(id), and writes accept an int, a recordset,
or None/False. Traversal (partner.country_id.name) works because the
wrapped recordset is just another view over env.cache.
Source code in pyvelm/fields.py
One2many ¶
Bases: Field
Inverse of a Many2one. Not stored; resolves by querying the comodel.
Reads consult env.cache when a tuple of child ids is present
(populated by a prior read or eager prefetch). Otherwise queries SQL
and stores the result in the cache for the rest of the request.
On parent forms, optional list_view and form_view pin which
registered views drive the embedded sub-grid and row/dialog forms
(see docs/one2many-forms.md). Inline columns are set on
field(...) in the form arch, not on this class.
Source code in pyvelm/fields.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 | |
Many2many ¶
Bases: Field
N:N relation backed by an auto-created junction table.
Default relation is the two table names joined alphabetically with
_rel, so both sides of a symmetric pair compute the same name and
only one CREATE TABLE is emitted. Self-referential M2M must supply
relation, column1, column2 explicitly.
Reads use the same tuple-of-ids cache convention as :class:One2many.
Writes via create/write are full replacements: DELETE then INSERT.
Source code in pyvelm/fields.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 | |
resolve_spec ¶
Return (relation, col1, col2, this_table, target_table).
Source code in pyvelm/fields.py
normalize_ids
staticmethod
¶
Accept None/False, an int, a recordset, or an iterable of either.
Source code in pyvelm/fields.py
finalize_related_field ¶
Validate and wire a related= field after bind().
Related fields mirror a dotted path (company_id.currency_id):
non-stored, no SQL column, cache-invalidated when the path changes.
Writes propagate to the leaf field on the related record.
Source code in pyvelm/fields.py
spec_readonly ¶
View-level readonly wins; supports callables when ctx is passed.