I want to add, edit, upload pdf file and delete notice element in Odoo website module. But how can I do this?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
Hii,
Create a New Model for Notices
Model: website.notice
from odoo import models, fields
class WebsiteNotice(models.Model):
_name = 'website.notice'
_description = 'Website Notice'
_order = 'date desc'
name = fields.Char(string='Title', required=True)
date = fields.Date(string='Date', default=fields.Date.context_today)
pdf_file = fields.Binary(string='PDF File', attachment=True, required=True)
pdf_filename = fields.Char(string='Filename')
active = fields.Boolean(default=True)
Define Access Rights
Create security/ir.model.access.csv :
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_website_notice_user,access_website_notice_user,model_website_notice,base.group_user,1,1,1,1
Add Backend Views
<odoo>
<record id="view_website_notice_form" model="ir.ui.view">
<field name="name">website.notice.form</field>
<field name="model">website.notice</field>
<field name="arch" type="xml">
<form string="Website Notice">
<sheet>
<group>
<field name="name"/>
<field name="date"/>
<field name="pdf_file" filename="pdf_filename"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="view_website_notice_tree" model="ir.ui.view">
<field name="name">website.notice.tree</field>
<field name="model">website.notice</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="date"/>
<field name="pdf_filename"/>
</tree>
</field>
</record>
<record id="action_website_notice" model="ir.actions.act_window">
<field name="name">Notices</field>
<field name="res_model">website.notice</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_website_notice_root" name="Notice Board" parent="website.menu_website_configuration" sequence="20"/>
<menuitem id="menu_website_notice" name="Notices" parent="menu_website_notice_root" action="action_website_notice"/>
</odoo>
Show Notices on the Website
Add a Controller and Template to render PDF links on the website.
Python Controller
from odoo import http
from odoo.http import request
class WebsiteNoticeController(http.Controller):
@http.route('/notices', type='http', auth='public', website=True)
def notice_board(self, **kwargs):
notices = request.env['website.notice'].sudo().search([('active', '=', True)], limit=50)
return request.render('your_module.notice_board_template', {
'notices': notices
})
QWeb Template
Now, visiting /notices on your website will show a list of notices with downloadable PDFs.
<odoo>
<template id="notice_board_template" name="Notice Board">
<t t-call="website.layout">
<div class="container my-5">
<h2>Notice Board</h2>
<ul>
<t t-foreach="notices" t-as="notice">
<li>
<span><t t-esc="notice.name"/> (<t t-esc="notice.date"/>)</span>
<a t-att-href="'/web/content/%s?download=true' % notice.id " t-att-download="notice.pdf_filename">
Download PDF
</a>
</li>
</t>
</ul>
</div>
</t>
</template>
</odoo>
Now, visiting /notices on your website will show a list of notices with downloadable PDFs.
i hope it is usefull
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden