How to do it...

Follow these steps to create a new route and template page for the issue page:

  1. Add a new route in main.py, as follows:
@http.route('/books/submit_issues', type='http', auth="user", website=True)
def books_issues(self, **post):
if post.get('book_id'):
book_id = int(post.get('book_id'))
issue_description = post.get('issue_description')
request.env['book.issue'].sudo().create({
'book_id': book_id,
'issue_description': issue_description,
'submitted_by': request.env.user.id
})
return request.redirect('/books/submit_issues?submitted=1')

return request.render('my_library.books_issue_form', {
'books': request.env['library.book'].search([]),
'submitted': post.get('submitted', False)
})
  1. Add a template with an HTML form in it, as follows:
<template id="books_issue_form" name="Book Issues Form">
<t t-call="website.layout">
<div class="container mt32">
<!-- add the page elements here -->
</div>
</t>
</template>
  1. Add the conditional header for the page, as follows:
    <t t-if="submitted">
<h3 class="alert alert-success mt16 mb16">
<i class="fa fa-thumbs-up"/>
Book submitted successfully
</h3>
<h1> Report the another book issue </h1>
</t>
<t t-else="">
<h1> Report the book issue </h1>
</t>
  1. Add<form> to submit the issues as follows:
<div class="row mt16">
<div class="col-6">
<form method="post">
<input type="hidden" name="csrf_token"
t-att-value="request.csrf_token()"/>
<div class="form-group">
<label>Select Book</label>
<select class="form-control" name="book_id">
<t t-foreach="books" t-as="book">
<option t-att-value="book.id">
<t t-esc="book.name"/>
</option>
</t>
</select>
</div>
<div class="form-group">
<label>Issue Description</label>
<textarea name="issue_description"
class="form-control"
placeholder="e.g. pages are missing"/>
</div>
<button type="submit" class="btn btn-primary">
Submit
</button>
</form>
</div>
</div>

Update the module and open the /books/submit_issues URL. From this page, you will be able to submit the issues for the book. After submission, you can check them into the respective book form view in the backend.

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

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