How to do it...

Follow these simple steps to add stages to the library.book.rent module:

  1. Add a new model called library.rent.stage, as follows:
class LibraryRentStage(models.Model):
_name = 'library.rent.stage'
_order = 'sequence,name'

name = fields.Char()
sequence = fields.Integer()
fold = fields.Boolean()
book_state = fields.Selection(
[('available', 'Available'),
('borrowed', 'Borrowed'),
('lost', 'Lost')],
'State', default="available")
  1. Add access rights for this new module in the security/ir.model.access.csv file, as follows:
acl_book_rent_stage,library.book_rent_stage_default,model_library_rent_stage,,1,0,0,0
acl_book_rent_librarian_stage,library.book_rent_stage_librarian,model_library_rent_stage,group_librarian,1,1,1,1
  1. Remove the state field from the library.book.rent model and replace it with a new stage_id field which is a many2one field and its methods, as shown in the following example:
@api.model
def _default_rent_stage(self):
Stage = self.env['library.rent.stage']
return Stage.search([], limit=1)

stage_id = fields.Many2one(
'library.rent.stage',
default=_default_rent_stage
)
  1. Replace the state field in the form view with the stage_id field, as shown in the following example:
<header>
<field name="stage_id" widget="statusbar"
options="{'clickable': '1', 'fold_field': 'fold'}"/>
</header>
  1. Replace the state field in the tree view and replace it with the stage_id field, as follows:
<tree>
<field name="book_id"/>
<field name="borrower_id"/>
<field name="stage_id"/>
</tree>
  1. Add some initial stages from the data/library_stage.xml file. Don't forget to add this file in the manifest, as shown in the following example:
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<record id="stage_draft" model="library.rent.stage">
<field name="name">Draft</field>
<field name="sequence">1</field>
<field name="book_state">available</field>
</record>
<record id="stage_rent" model="library.rent.stage">
<field name="name">On rent</field>
<field name="sequence">5</field>
<field name="book_state">borrowed</field>
</record>
<record id="stage_due" model="library.rent.stage">
<field name="name">Due</field>
<field name="sequence">15</field>
<field name="book_state">borrowed</field>
</record>
<record id="stage_returned" model="library.rent.stage">
<field name="name">Completed</field>
<field name="sequence">25</field>
<field name="book_state">available</field>
</record>
<record id="stage_lost" model="library.rent.stage">
<field name="name">Lost</field>
<field name="sequence">35</field>
<field name="fold" eval="True"/>
<field name="book_state">lost</field>
</record>
</odoo>

After installing the module, you will see stages in the form view, as shown in the following screenshot:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset