YouTube2Text

Relational, Computed, Related, Many2one, One2Many, Many2many Fields, Odoo 17: Days6: #1 #1million — Transcript

by Odoo Tech · 2,665 words · 377 segments · language en · Watch on YouTube

Full transcript

  1. 0:01Hello, welcome to my YouTube channel.
  2. 0:03So, in today's video, we are going to
  3. 0:06look at relational fields. Relational
  4. 0:08fields are basically your Many2one,
  5. 0:11One2many, and Many2many. Okay? How we
  6. 0:14can add them in the form. Okay? And we
  7. 0:16have to show them in the tree view.
  8. 0:18Okay? Relational fields, and we also
  9. 0:21know how to add computed fields in the
  10. 0:24form view. Okay? And related fields. So
  11. 0:27today, we will see how to add computed
  12. 0:29fields. Related fields and relational
  13. 0:32fields. Okay? Basically, first,
  14. 0:35understand what exactly these
  15. 0:37relational fields are. Right? For
  16. 0:40example, there is a class. Right? A
  17. 0:43teacher comes from outside and says, "I
  18. 0:46need one student." So, he only needs
  19. 0:50one student for some work. So, he is
  20. 0:52picking just one student. So that means
  21. 0:55Many2one. Meaning, he is picking one
  22. 0:57record. He is selecting one record. He
  23. 0:59is selecting one student. So it is
  24. 1:01called a Many2one relational field.
  25. 1:04Okay. Next one comes One2many. So in
  26. 1:07One2many, what happens is, like there
  27. 1:10is a student, he picked one student.
  28. 1:14Then all the details of that student,
  29. 1:16like the student's name, student's
  30. 1:18father's name, student's class, info
  31. 1:20about the subjects, study in the class.
  32. 1:23Okay? Everything about the student.
  33. 1:25Only a single person. Right? To show
  34. 1:28complete information about one product,
  35. 1:30we have to add a One2many field. Okay?
  36. 1:33Right? So in this way, we use the
  37. 1:35One2many field. And Many2many is when
  38. 1:38we need multiple records together. We
  39. 1:42need multiple records together. To
  40. 1:44select them all at once and show them
  41. 1:47together, we use the Many2many field.
  42. 1:49Right? And in One2many, you show all
  43. 1:52the details of one product. But in
  44. 1:55Many2many, you can only show their
  45. 1:57names, in a way. But there, for example
  46. 2:00, you selected five records. Picked
  47. 2:03five products from the system. Right?
  48. 2:05So, the names of those five products
  49. 2:06will be visible. But their full details
  50. 2:08won't be visible, like what type of
  51. 2:10product it is, what the cost is, or the
  52. 2:12sales. Right? Like for a student, what
  53. 2:15is their name, address, what do they
  54. 2:17study, which class are they in? So all
  55. 2:19those things will not be visible. There
  56. 2:20, you will only see selected students
  57. 2:22or selected product records. And in
  58. 2:24Many-to-Many, you can see all this
  59. 2:26information. Sorry, in a One-to-Many
  60. 2:28field, you can see all this information
  61. 2:30. So, this is a difference between them
  62. 2:33. Okay? Also, what is a computed field?
  63. 2:37It's based on a field when we save a
  64. 2:39form. Right? Based on saving the form,
  65. 2:42you need to perform some calculations
  66. 2:44in a field. Like, you need to calculate
  67. 2:47age or show the sum of two numbers in a
  68. 2:50third field. Right? This is your
  69. 2:52computed field. What is a related field
  70. 2:54? As you might have seen while filling
  71. 2:58out a form on a website, you write your
  72. 3:01name here, and below it, there is a
  73. 3:03confirmation field, another column
  74. 3:05where you enter your name again, and in
  75. 3:08a third place, it automatically shows
  76. 3:11the name you entered. Actually, what
  77. 3:14happens there is that it is related to
  78. 3:16another field. Meaning, you enter a
  79. 3:17value in one field, and it
  80. 3:18automatically appears in the other.
  81. 3:20Okay. So, let's start with our code.
  82. 3:24Let's go. I will close all my tabs for
  83. 3:28now. Go to the custom and run the
  84. 3:39server. Server run. It's my localhost.
  85. 3:58Invalid manifest abs model. Wait, in
  86. 4:12the custom module, remove this. Working
  87. 4:24. Okay, so our module was 'Student
  88. 4:27Management', which we were working on.
  89. 4:32Right, so today we will add fields to
  90. 4:34the relations in it. So now, what I
  91. 4:37want is that here, like for the student
  92. 4:40, I should create a subject object
  93. 4:44relation. Subject, like our subject, we
  94. 4:47create subjects here. So I want to show
  95. 4:49these same subjects here in the form,
  96. 4:51that hey, this student studies these
  97. 4:53many subjects. All those...sorry, all
  98. 4:56those subjects can be selected here.
  99. 5:00Right? For this student, for example,
  100. 5:02this is the student. They study these
  101. 5:04subjects, or right? So all of them will
  102. 5:08show here. Now let's go to the student.
  103. 5:20Here, One-to-Many. Let's do one thing.
  104. 5:30Before One-to-Many, let's add
  105. 5:31Many-to-One. Okay, here we will select
  106. 5:35the class first. Sorry, we will add '
  107. 5:44class_id' in it and 'Many-to-One' will
  108. 5:48go here. So in this, we have to provide
  109. 5:51the first parameter, which is which
  110. 5:53object to relate with, meaning which
  111. 5:55table you need to relate it to. I need
  112. 5:58to create a relation with this table '
  113. 6:00subject.subject', so I will copy this,
  114. 6:03put it here, what will be its string,
  115. 6:05and I will put 'class' here. Okay, I
  116. 6:08will add this field to the form view as
  117. 6:12well. Okay? This is my tree view. So I
  118. 6:16will put it here after the user ID.
  119. 6:23Name and paste here. Okay. I reload the
  120. 6:28page and upgrade the model. I copied
  121. 6:32the model name from the backend and
  122. 6:35pasted it here. Then run. Now I go here
  123. 6:40and refresh. So my field will appear
  124. 6:43here. Sorry, it appeared here. Okay? So
  125. 6:45as you can see here, as soon as I
  126. 6:47select it here, you have selected only
  127. 6:50Hindi here. Okay? And I saved it. I
  128. 6:53have only selected Hindi here. If I go
  129. 6:55and look at the record subject records
  130. 6:58here, there is another field called
  131. 7:00subject ID. I am not able to see this
  132. 7:02field there. Now, as I put Hindi here,
  133. 7:06you can only select one record out of
  134. 7:08multiple records here. This is called
  135. 7:12Many2one. Now we will add One2many.
  136. 7:18Before One2many, let's add. Let's add
  137. 7:21Many2many. Okay? We will add Many2many
  138. 7:24inside the class. Okay? This same field
  139. 7:27we will make Many2many. After this, we
  140. 7:29will add subjects. We will create a
  141. 7:32field named subjects inside this for
  142. 7:34Many2many. Okay? So here we will name
  143. 7:41it subjects_ids. Okay? Fields, this
  144. 7:47field of mine will be of Many2many type
  145. 7:50. It will be Many2many. It is the same
  146. 7:52thing in this as well. You have to give
  147. 7:56a relation and then the string. I will
  148. 8:00go and add this field to my sub-class.
  149. 8:07I will add it after the teacher ID.
  150. 8:14Okay? I put it here, my field name was
  151. 8:18subject_ids and I have to give a widget
  152. 8:21here too. This is a widget where we
  153. 8:25have to provide the widget '
  154. 8:29many2many_tags'. What this does is that
  155. 8:32those attributes appear in it. Okay?
  156. 8:35Now you see for yourself what it looks
  157. 8:38like. Now I refresh here. So as I
  158. 8:42select here. Like I selected Hindi. A
  159. 8:44tag-like thing appears. Okay? Here you
  160. 8:47can select multiple, like in 10th grade
  161. 8:50, three subjects are taught. You can
  162. 8:53define it in this way here. And here
  163. 8:56you will create a class, like if you
  164. 8:59created 12th, you can select how many
  165. 9:01subjects can be taught in 12th grade,
  166. 9:04and you can create subjects over here.
  167. 9:07So, this is your Many-to-Many. I will
  168. 9:09rename this now. You can change the
  169. 9:11string from here too. Or else, you can
  170. 9:13change it from Python. I will make this
  171. 9:17"Subject" into "Subjects". So that it
  172. 9:19looks better that there are multiple
  173. 9:22subjects in "Subjects". Okay, I have
  174. 9:25made it "Subjects". Now we go to Akash.
  175. 9:29So, what did we see just now?
  176. 9:31Many-to-One and Many-to-Many. And
  177. 9:33lastly, here is One-to-Many. The method
  178. 9:36for One-to-Many is a bit different. To
  179. 9:38add a One-to-Many field, we will have
  180. 9:40to do something a bit different. Okay.
  181. 9:45What will we have to do? First, we will
  182. 9:47have to create a new class here. For
  183. 9:50One-to-Many. Let's do one thing in the
  184. 9:55class. Let's show that itself. Okay.
  185. 10:03Class is fine. Let's just create the
  186. 10:05class. So it will be clearly understood
  187. 10:07. We will create the class here. I will
  188. 10:11define the class here. I will name it
  189. 10:16something like Subject Line. Subject
  190. 10:21Line, created its object, put the model
  191. 10:26in it. Subject Line, so what will be in
  192. 10:30this? One will be mine. Okay? Here, one
  193. 10:35will be my subject. Subject, which will
  194. 10:39be Many-to-One. It will be Many-to-One.
  195. 10:49Its relation will be with
  196. 10:51subject.subject. Subject.subject, its
  197. 10:59string will be. Subject. Okay. This is
  198. 11:14my subject, okay? And we have to give
  199. 11:17one more thing here. We can call this
  200. 11:20an inverse field, or okay, we call it
  201. 11:22an inverse field or a linking field. It
  202. 11:25is a connection field, basically, with
  203. 11:26which field do we have to make the
  204. 11:28connection? With this object, because
  205. 11:31we are going to add One-to-Many here,
  206. 11:32actually we are going to add it inside
  207. 11:34this object. So for that, we will have
  208. 11:38to create a connection field inside
  209. 11:40this object. We will have to create an
  210. 11:42inverse field. Student, by doing that.
  211. 11:46I will create it by ID. This is always
  212. 11:49Many-to-One. Okay? Our connection field
  213. 11:52, sorry, is Many-to-One. Which is used
  214. 11:55in One-to-Many. Okay? And here we will
  215. 11:58give the name of this object. And here
  216. 12:00we will give this to it. Student Okay?
  217. 12:08So I have a subject here and this here.
  218. 12:11Okay? So now I What I do is? I grant
  219. 12:20access to this sub-object in my
  220. 12:22security file. Go first so that there
  221. 12:25are no errors. Give it maximum in
  222. 12:33security. I have granted access in the
  223. 12:42security file. Now let's go to the
  224. 12:44student form. After the student form,
  225. 12:46if we look here, there is a notebook
  226. 12:49tag. Okay? There is a notebook tag.
  227. 12:52Inside this notebook, we start a page.
  228. 12:55Okay? A page starts inside this. We can
  229. 12:57give a string to this page here. A
  230. 13:01string like, well, subject subject.
  231. 13:05Okay? Let's call it subject details.
  232. 13:09Subject details. Okay? Inside this, we
  233. 13:14also need to provide our one-to-many
  234. 13:18field. Okay? Let's do this much first.
  235. 13:22After this, we go to student. Now we
  236. 13:26add a one-to-many relation to our
  237. 13:28subject form. So here we will do
  238. 13:33subject line. Okay? In that, we will
  239. 13:36add a line, in a way, make it line ID.
  240. 13:39And here field dot one-to-many, inside
  241. 13:42this we have to give one object. We
  242. 13:45will create a relation with this. The
  243. 13:48second is the universal one we created
  244. 13:50in the name of student. We created it
  245. 13:53in the name of student ID. Then after
  246. 13:55this, we give a string. Here we have to
  247. 14:00provide the string subject details.
  248. 14:06Okay? This field that I have created,
  249. 14:08many-to-one, we have created it inside
  250. 14:11this object, so that all the fields I
  251. 14:13have inside this object are these. So
  252. 14:16that I can access them there. Okay? So
  253. 14:20now I will add its fields there. These
  254. 14:25are my fields. I will enter the name
  255. 14:29here. Entered field. Inside this, I
  256. 14:32started the tree view tag. Inside this,
  257. 14:35I will put my field. Name and here I
  258. 14:39will put subject ID and I closed it.
  259. 14:45Once this is done, understand that your
  260. 14:47one-to-many has been added. Look,
  261. 14:52subject details have appeared here now.
  262. 14:54So now you can choose from here. Look,
  263. 14:57a popup has appeared here now. Okay?
  264. 14:59You can go here and save and close it.
  265. 15:02You will enter the subject here, Hindi,
  266. 15:04and what is its student ID? One, and I
  267. 15:06will close it, save. Now what I want is
  268. 15:09that when I click on this, a popup
  269. 15:10appears. This popup is asking me to
  270. 15:13select here, but I don't want it to
  271. 15:15keep adding as soon as I click. So, for
  272. 15:18this, there is an attribute. For this,
  273. 15:21we need to add 'editable top'. There is
  274. 15:25top, there is bottom; it depends on
  275. 15:28where you want to edit from. You can
  276. 15:31also set it to bottom. So, let's see
  277. 15:33what happens with this. As I click on
  278. 15:37it, the popup didn't appear for me now.
  279. 15:41I will click here and can select from
  280. 15:42here. Alright? So, this is how we can
  281. 15:46add one-to-many fields. Currently, it
  282. 15:48is showing only one field here. And if
  283. 15:50we look into our subject, there are two
  284. 15:53fields. Right? There is also a subject
  285. 15:55ID. So, now we will also show the
  286. 15:57subject ID here. Right? Let's show the
  287. 15:59subject ID. We will go inside this. So
  288. 16:05now, you see, the related field will
  289. 16:07also be used here. Our field was about
  290. 16:09how the related field will be used? So,
  291. 16:12we will add the related field here as
  292. 16:13well. Subject ID, let me see what the
  293. 16:18name of that field is. Let me go and
  294. 16:22open one more tab here. I'll go there.
  295. 16:26What is this field? Developer mode is
  296. 16:31turned on. Subject ID, Subject, okay.
  297. 16:40Character type, okay. I have already
  298. 16:44used subject name/ID above, so I will
  299. 16:47name this one. Subject code, let's name
  300. 16:51it code, okay. Code, okay, fine. Fields
  301. 16:55dot, we will make it of character type
  302. 16:57because it is a character type there,
  303. 17:00and for this, there is an attribute
  304. 17:02called 'related', okay? Inside this, we
  305. 17:06need to start a string, so which field
  306. 17:08do we want to make it related to? We
  307. 17:10want to make it for subject ID. Now I
  308. 17:12have entered inside this. It means I
  309. 17:15have come inside this object. Inside
  310. 17:17this object, there is a field, the same
  311. 17:19subject ID. So here, I will put a dot
  312. 17:23and write subject dot subject ID. And I
  313. 17:28will add a string here. Subject Let's
  314. 17:35make it subject code. Okay? I made it
  315. 17:41subject code and I will also show the
  316. 17:44field here. After this After this, I
  317. 17:52showed it here. And now I have
  318. 17:55restarted it and I will refresh it over
  319. 17:58here. Let's see what happens. So you
  320. 18:01see, the value came automatically. If I
  321. 18:03do what here? Look, I change this. I'll
  322. 18:06select English and the English code
  323. 18:08will come here automatically. It came,
  324. 18:09the English code has even appeared. Now
  325. 18:11, if I select Math here, the Math code
  326. 18:13will appear automatically. So, this is
  327. 18:16the function of our related field. Okay
  328. 18:19? That's how we use the related field.
  329. 18:22Now comes our computed field. How do we
  330. 18:25use computed fields? We can use
  331. 18:29computed fields to count how many
  332. 18:30records are selected here. We have
  333. 18:33selected three records. So, I want to
  334. 18:35show the number of subjects counted
  335. 18:38here. Okay? I will add one more field
  336. 18:41here, a subject count field. Okay? In
  337. 18:44that field, I will ensure that for
  338. 18:46however many subjects are selected, I
  339. 18:48display the count of records here. Like
  340. 18:50here there are three, so the count
  341. 18:51there will be three. Okay? So, let's
  342. 18:54add it to our object this way. In the
  343. 18:58student model, let's call it
  344. 19:00total_subject. Total subject, and then
  345. 19:12we set it to integer type. Okay? We
  346. 19:18give it a string "Subject" and it has
  347. 19:21an attribute called compute. Okay? This
  348. 19:24is an attribute. Inside this, there is
  349. 19:27a string, and we write here that the
  350. 19:30total subjects should appear. Okay? We
  351. 19:33provide a function inside this.
  352. 19:35Basically, we create a function and
  353. 19:38assign its name here. Okay? So look, it
  354. 19:44automatically showed me that you can do
  355. 19:47it like this in self.total_subject,
  356. 19:50where whatever the length is, that
  357. 19:53count will appear here. So let's see,
  358. 19:57first let's add this field here. Going
  359. 20:00into student, we add it—not here,
  360. 20:04let's add it after class_id. And I will
  361. 20:12make it invisible. We have an attribute
  362. 20:15for that, invisible. Okay? Invisible
  363. 20:19means what you see right now will
  364. 20:21disappear. It won't be visible. Okay?
  365. 20:24So look, as soon as I refreshed, it
  366. 20:26automatically showed three here. If I
  367. 20:28add one more here. Look, I added one
  368. 20:31more subject here, and as soon as I
  369. 20:34save it, it will become four. See, it
  370. 20:36became four automatically. This is how
  371. 20:39you can create a computed field. Okay.
  372. 20:43So, today we saw how to add relational
  373. 20:47fields. How we can use computed fields
  374. 20:51and how to use related fields. Okay? If
  375. 20:55you have any queries or issues, you can
  376. 20:58comment on the video. Okay? So thank
  377. 21:01you.

About this transcript

This page contains the full transcript of Relational, Computed, Related, Many2one, One2Many, Many2many Fields, Odoo 17: Days6: #1 #1million by Odoo Tech , generated from the public captions YouTube serves with the video. The transcript has 2,665 words across 377 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.