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
3 changes: 3 additions & 0 deletions addons_library/library_extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
27 changes: 27 additions & 0 deletions addons_library/library_extensions/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
{
"name": "Library Extensions", #Changed from Library
"version": "17.0.1.0",
"depends": [
"base",
"library"

],
"external_dependencies": {},
"author": "Odev Solutions",
"website": "https://www.odevsolutions.com",
"summary": """Library""",
"description": """
Library
""",
"category": "Extra Tools",
"data": [
"security/ir.model.access.csv",
"views/library_book_category_views.xml", # Added
"views/library_book_views.xml",
"views/library_menus.xml",

],
"installable": True,
"application": False,
}
4 changes: 4 additions & 0 deletions addons_library/library_extensions/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-

from . import library_book
from . import library_book_category
44 changes: 44 additions & 0 deletions addons_library/library_extensions/models/library_book.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-

from odoo import models, fields, api


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

# Task 2: Added Author field
author_id = fields.Many2one(
'res.partner',
string="Author",
required=True
)

# Task 3: Added Category field
category_ids = fields.Many2many(
'library.book.category',
string="Categories"
)

######################
# Fields declaration #
######################

##############################
# Compute and search methods #
##############################

############################
# Constrains and onchanges #
############################

#########################
# CRUD method overrides #
#########################

##################
# Action methods #
##################

####################
# Business methods #
####################
18 changes: 18 additions & 0 deletions addons_library/library_extensions/models/library_book_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
import random # <--- #Newly Added Import
from odoo import models, fields

class LibraryBookCategory(models.Model):
_name = "library.book.category"
_description = "Book Category"

name = fields.Char(string="Name", required=True)
# Added to fix error when adding category for adding a book entry.
color = fields.Integer(
string="Color Index",
default=lambda self: random.randint(1, 11)
)

_sql_constraints = [
('name_unique', 'unique(name)', 'The category name must be unique!')
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_library_book_admin,access.library.book.admin,model_library_book,base.group_system,1,1,1,1
access_library_book_category_admin,access.library.book.category.admin,model_library_book_category,base.group_system,1,1,1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="library_book_category_view_tree" model="ir.ui.view">
<field name="name">library.book.category.view.tree</field>
<field name="model">library.book.category</field>
<field name="arch" type="xml">
<tree string="Categories" editable="bottom">
<field name="name"/>
</tree>
</field>
</record>

<record id="library_book_category_action" model="ir.actions.act_window">
<field name="name">Book Categories</field>
<field name="res_model">library.book.category</field>
<field name="view_mode">tree,form</field>
</record>
</odoo>
26 changes: 26 additions & 0 deletions addons_library/library_extensions/views/library_book_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="library_book_view_tree_inherit" model="ir.ui.view">
<field name="name">library.book.view.tree.inherit</field>
<field name="model">library.book</field>
<field name="inherit_id" ref="library.library_book_view_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='isbn_13']" position="after">
<field name="author_id"/>
<field name="category_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
</xpath>
</field>
</record>

<record id="library_book_view_form_inherit" model="ir.ui.view">
<field name="name">library.book.view.form.inherit</field>
<field name="model">library.book</field>
<field name="inherit_id" ref="library.library_book_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='isbn_13']" position="after">
<field name="author_id"/>
<field name="category_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
</xpath>
</field>
</record>
</odoo>
9 changes: 9 additions & 0 deletions addons_library/library_extensions/views/library_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<menuitem
id="library_book_category_menu"
name="Book Categories"
parent="library.library_menu_main"
action="library_book_category_action"
sequence="20"/>
</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$qzVGiBFCKGXs/d8bw7hXSg$UGyJ64Y/mFFkfgR3anPkDmOeX5CSoOHSogy5dEEnUz96zpW5q34gTPr21/SAka/5XFPpTlfpdo0E9VWqXjjA4w