Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons_library/library/library_extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
12 changes: 12 additions & 0 deletions addons_library/library/library_extensions/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "Library Extensions",
"version": "1.0"
"depends": ["library"],
"author": " Your Name",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put your name as the Author

"category": "Library",
"data": [
"views/library_book_views.xml",
],
"installable": True,
"application": False,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import library_book
24 changes: 24 additions & 0 deletions addons_library/library/library_extensions/models/library_book.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from odoo import models, fields, api

class LibraryBook(models.Model):
_inherit = "library.book"

author_id = fields.Many2one(
comodel_name = "res.partner",
string = "Author"
required = True
)

class LibraryBookCategory(models.Model):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to another python file called library_book_catgory.py

_name = "library.book.category"
_description = "Book Category"

name = fields.Char(string="Category Name", required=True, unique=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unique=True doesnt work, use python or database constraints to make sure name values is unique


class LibraryBook(models.Model):
_inherit = "library.book"

category_id = fields.Many2many(
comodel_name = "library.book.category",
string = "Categories"
)
Comment on lines +18 to +24
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to create another model declaration for a new field, just put it under on the original model delaration.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<odoo>
<!-- Book Form View -->
<record id="view_library_book_form_inherit" model="ir.ui.view">
<field name="name">library.book.form.inherit</field>
<field name="model">library.book</field>
<field name="inherit_id" ref="library.view_library_book_form"/>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong inherit ID

<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="author_id"/>
<field name="category_id"/>
</xpath>
</field>
</record>

<!-- Book List View -->
<record id="view_library_book_tree_inherit" model="ir.ui.view">
<field name="name">library.book.tree.inherit</field>
<field name="model">library.book</field>
<field name="inherit_id" ref="library.view_library_book_tree"/>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong inherit ID

<field name="arch" type="xml">
<xpath expr="//tree/field[@name='name']" position="after">
<field name="author_id"/>
<field name="category_id"/>
</xpath>
</field>
</record>

<!-- Book Category List View -->
<record id="view_library_book_category_tree" model="ir.ui.view">
<field name="name">library.book.category.tree</field>
<field name="model">library.book.category</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
</tree>
</field>
</record>

<!-- Book Category Form View -->
<record id="view_library_book_category_form" model="ir.ui.view">
<field name="name">library.book.category.form</field>
<field name="model">library.book.category</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
</group>
</sheet>
</form>
</field>
</record>
Comment on lines +29 to +52
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this views to a new file library_book_category_views.xml


<!-- Menu Item for Book Categories -->
<menuitem id="menu_library_book_category" name="Book Category" parent="library.menu_library_root"/>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a view action for this menuitem, wrong parent is used for this menu item. Move this views to a new file library_book_category_views.xml

</odoo>
1 change: 1 addition & 0 deletions config/odoo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
addons_path = /mnt/addons_library
data_dir = /var/lib/odoo
proxy_mode = True
admin_passwd = $pbkdf2-sha512$600000$3TtHqNX6X6tVag3B2Lt3Dg$w5No2koBUoAayDYpyqThvWw.0R1ic5w1PExEXPI0s.MBmzF5Z1aKSgajXouzR7Hw0Fs7GiQvoKrV.CUB9Rz39w