KEMBAR78
Tips On Trick Odoo Add-On.pptx
Tips On Trick
on
Odoo Development
By Agusto Xaverius PS
Background Scenario
1. Infinys already have 3 (three) successfully go-live and still on-going projects that
using Odoo ERP as backend system
2. Meanwhile on development process. We are fun to meet all the new stuff around
developing using Odoo ERP and keep always learning by doing
3. Within this slide, we will try to cover all that we know about tips on trick how to
develop on Odoo, like how to create a module, create a view, button, and etc.
4. All this development on this slide will be using Phyton as language
TOC
1. Module Structure
2. Create a new Table / Inherit Table in database
3. Create Menu Items CRUD for our model
4. Create master-detail
5. Create model from multiple models
6. Create Button
7. Send Email via API and using Odoo Email Template
Module Structure
Module Structure
• data folder: it contains css and xml files which hold to predefined
information into the system like a list of colours, counties, states name
data.
• models folder: it contains all python (.py) files. These hold models that
newly created or inherit from other existing models, objects and the
business logic as well. In part 2, we will introduce it more detail.
• security directory: it contains two files, Access control .csv file, Record rule
.xml files. Access control: ir.model.access.csv must be there and used for
holding access rights of model. Record Rules: security.xml that can declare
the the prohibited operations like create, update and delete. This access
control is applied in single record, so you need to specify which record is
going to be applied.
• views directory: it contains all .xml files where we declare the form views,
menu, action, Qweb template and so on for our business objects.
•_init__.py it is utilized to specify the directories or packages need to
imported.
Module Structure
• __manifest__.py this file is crucial in Odoo module. This module should be
located at the root of the module. It lets you describe essential information
of your module like name, version, description, dependencies, data files,
etc.
– Name – module name
– Description – Brief description of your module
– Version – Version of your module
– License – License of your module
– Author – Author name of your module
– Website – Website URL of your module author or company
– Category – Indicate the category name.
– Depends – Specifies a list of modules which need to install before this module. This is
important. Without this declaration, you may get warning or error during module
installation
– Data – Data files which are always installed or updated with the module.
– demo – Data files which are installed or updated in active demonstration mode.
Sample
Module
Structure
Create a new Table /
Inherit Table in
database
Create a new table in database
1. Create a ClassName make sure using Camel namespace
2. _name , representative to the table name that will be stored in database
_description = “the table description”
3. All that fields that belong to this table
This below how will be look like in odoo database once this module installed
Create extra fields in existing module
Make sure put _Inherit for extend the
existing table
Create Menu Items
CRUD for our model
Menu CRUD for our model
Todo :
1. Create a model
2. Create a permission level on the folder security
3. Create a view for the model, tree view and form
view (optional)
1. Model – event.log.bytrack
2. Permission
access_event_log_bytrack_all,event_log_bytrack,model_event_log_bytrack,,1,1,1,1
access_event_chat_bytrack,event_chat_bytrack,model_event_chat_bytrack,base.group_user,1
,1,1,1
3. Create View
1)
<record id="action_event_log_bytrack" model="ir.actions.act_window">
<field name="name">List Of Event Log By Track action</field>
<field name="res_model">event.log.bytrack</field>
<field name="view_mode">tree,form</field>
</record>
2)
<!-- explicit list menuitem definition -->
<menuitem id="event_main_register" name="Register"
parent="event.event_main_menu" sequence="50">
<menuitem id="event_log_bytrack" name="List Of Event Log By Track"
sequence="3" action="action_event_log_bytrack" />
</menuitem>
3)
<record model="ir.ui.view" id="event_log_bytrack_view">
<field name="name">event_log_bytrack_view.form</field>
<field name="model">event.log.bytrack</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="eventid"/>
<field name="trackid"/>
<field name="partnerid"/>
<field name="submitteddate"/>
<field name="is_active"/>
</group>
</sheet>
</form>
</field>
</record>
Create master-detail
Sample Master-Detail
Todo :
1. Create model for detail
2. Create permission on security
folder
3. Create View, inherit from master
view
1. Create model for table detail
document_id = fields.Many2one('event.sponsor', string='Documents', required=True,
ondelete='cascade')
2. Create Permission
access_infinys_event_organization_event_sponsor_document,event.sponsor.document,infinys
_event_organization.model_event_sponsor_document,,1,1,1,1
3. Update the view
<page string="Videos" name="video_kits">
<field name ="video_line_ids">
<tree>
<field name="name" />
<field name="is_document_file" />
<field name="document_file_name" />
<field name="document_link" widget="url" />
<field name="create_date" />
</tree>
<form>
<group>
<field name="name" />
<field name="is_document_file" />
<field name="document_file" filename="document_file_name" />
<field name="document_file_name" invisible="1"/>
<field name="document_link" widget="url"
placeholder="Youtube / Web Video Link Link..." />
</group>
</form>
</field>
</page>
Create model from
multiple models
Sample Query
SELECT
ROW_NUMBER () OVER (ORDER BY eq.id) AS id,
eq.event_id AS event_id,
eq.id AS question_id,
eq.title AS name,
eq.question_type AS question_type,
eq.sequence AS question_sequence,
eq.once_per_order AS once_per_order,
eqa.id AS answer_id,
eqa.name AS answer_name,
eqa.sequence AS sequence_choice
FROM event_question AS eq
LEFT JOIN event_question_answer AS eqa ON eq.id = eqa.question_id
Todo :
1. Create a new model
2. Create permission
3. Create View (if needed)
4. Then you able to using this
model, on you view, odoo report,
or API
1. Create Model
ROW_NUMBER () OVER
(ORDER BY eq.id) AS id
Because we need to access
via API, makes sure the ID is
unique
2. Create Permission
access_contact_cv_verification,contact_cv_verification,model_contact_cv_verification,bas
e.group_user,1,1,1,1
access_contact_cv_verification_all,contact_cv_verification,model_contact_cv_verification
,,1,0,0,0
Testing On API
Create button
Sample
Todo :
1. Create button on the view
2. Create function on the model, since the
button type using object
1. Create button on view
<xpath expr="//field[@name='stage_id']" position="before">
<button type="object" name="action_generate_certification" string="Test Certification" class="btn btn-secondary"
attrs="{'invisible': [('is_certificate', '=', False)]}"/>
</xpath>
2. Create Function
def action_generate_certification(self):
return {
'type': 'ir.actions.act_url',
'target': 'new',
'url': "/api/certificate/generate/test?event_id=" + str(self.id) + "&partner_id=" + str(self.env.user.partner_id.id),
}
Send Email via API and
using Odoo Email
Template
Sample
Todo :
1. Email template and
choose the model will
applies to
2. Testing using API
Access template email using API
#Send Email Registration
email_template_obj = request.env['mail.template']
template_id = email_template_obj.sudo().search([('name','=','Registration Acqalm Account Created'),('model_id.model',
'=', 'res.partner')])
template_id.send_mail(_partner_id, force_send=True)
_logger.info("send Email Succeed")
Demo
Knowledge Base
1. https://www.odoo.com/
2. https://www.genkiware.com/2020/05/03/how-to-write-a-module-in-odoo-part-i-
module-structure/
3. https://en.ngasturi.id/
4. https://www.youtube.com/c/OdooMates

Tips On Trick Odoo Add-On.pptx

  • 1.
    Tips On Trick on OdooDevelopment By Agusto Xaverius PS
  • 2.
    Background Scenario 1. Infinysalready have 3 (three) successfully go-live and still on-going projects that using Odoo ERP as backend system 2. Meanwhile on development process. We are fun to meet all the new stuff around developing using Odoo ERP and keep always learning by doing 3. Within this slide, we will try to cover all that we know about tips on trick how to develop on Odoo, like how to create a module, create a view, button, and etc. 4. All this development on this slide will be using Phyton as language
  • 3.
    TOC 1. Module Structure 2.Create a new Table / Inherit Table in database 3. Create Menu Items CRUD for our model 4. Create master-detail 5. Create model from multiple models 6. Create Button 7. Send Email via API and using Odoo Email Template
  • 4.
  • 5.
    Module Structure • datafolder: it contains css and xml files which hold to predefined information into the system like a list of colours, counties, states name data. • models folder: it contains all python (.py) files. These hold models that newly created or inherit from other existing models, objects and the business logic as well. In part 2, we will introduce it more detail. • security directory: it contains two files, Access control .csv file, Record rule .xml files. Access control: ir.model.access.csv must be there and used for holding access rights of model. Record Rules: security.xml that can declare the the prohibited operations like create, update and delete. This access control is applied in single record, so you need to specify which record is going to be applied. • views directory: it contains all .xml files where we declare the form views, menu, action, Qweb template and so on for our business objects. •_init__.py it is utilized to specify the directories or packages need to imported.
  • 6.
    Module Structure • __manifest__.pythis file is crucial in Odoo module. This module should be located at the root of the module. It lets you describe essential information of your module like name, version, description, dependencies, data files, etc. – Name – module name – Description – Brief description of your module – Version – Version of your module – License – License of your module – Author – Author name of your module – Website – Website URL of your module author or company – Category – Indicate the category name. – Depends – Specifies a list of modules which need to install before this module. This is important. Without this declaration, you may get warning or error during module installation – Data – Data files which are always installed or updated with the module. – demo – Data files which are installed or updated in active demonstration mode.
  • 7.
  • 8.
    Create a newTable / Inherit Table in database
  • 9.
    Create a newtable in database
  • 10.
    1. Create aClassName make sure using Camel namespace 2. _name , representative to the table name that will be stored in database _description = “the table description” 3. All that fields that belong to this table This below how will be look like in odoo database once this module installed
  • 11.
    Create extra fieldsin existing module Make sure put _Inherit for extend the existing table
  • 13.
  • 14.
    Menu CRUD forour model Todo : 1. Create a model 2. Create a permission level on the folder security 3. Create a view for the model, tree view and form view (optional)
  • 15.
    1. Model –event.log.bytrack
  • 16.
  • 17.
  • 18.
    1) <record id="action_event_log_bytrack" model="ir.actions.act_window"> <fieldname="name">List Of Event Log By Track action</field> <field name="res_model">event.log.bytrack</field> <field name="view_mode">tree,form</field> </record> 2) <!-- explicit list menuitem definition --> <menuitem id="event_main_register" name="Register" parent="event.event_main_menu" sequence="50"> <menuitem id="event_log_bytrack" name="List Of Event Log By Track" sequence="3" action="action_event_log_bytrack" /> </menuitem>
  • 19.
    3) <record model="ir.ui.view" id="event_log_bytrack_view"> <fieldname="name">event_log_bytrack_view.form</field> <field name="model">event.log.bytrack</field> <field name="arch" type="xml"> <form> <sheet> <group> <field name="eventid"/> <field name="trackid"/> <field name="partnerid"/> <field name="submitteddate"/> <field name="is_active"/> </group> </sheet> </form> </field> </record>
  • 20.
  • 21.
    Sample Master-Detail Todo : 1.Create model for detail 2. Create permission on security folder 3. Create View, inherit from master view
  • 22.
    1. Create modelfor table detail document_id = fields.Many2one('event.sponsor', string='Documents', required=True, ondelete='cascade')
  • 23.
  • 24.
    3. Update theview <page string="Videos" name="video_kits"> <field name ="video_line_ids"> <tree> <field name="name" /> <field name="is_document_file" /> <field name="document_file_name" /> <field name="document_link" widget="url" /> <field name="create_date" /> </tree> <form> <group> <field name="name" /> <field name="is_document_file" /> <field name="document_file" filename="document_file_name" /> <field name="document_file_name" invisible="1"/> <field name="document_link" widget="url" placeholder="Youtube / Web Video Link Link..." /> </group> </form> </field> </page>
  • 25.
  • 26.
    Sample Query SELECT ROW_NUMBER ()OVER (ORDER BY eq.id) AS id, eq.event_id AS event_id, eq.id AS question_id, eq.title AS name, eq.question_type AS question_type, eq.sequence AS question_sequence, eq.once_per_order AS once_per_order, eqa.id AS answer_id, eqa.name AS answer_name, eqa.sequence AS sequence_choice FROM event_question AS eq LEFT JOIN event_question_answer AS eqa ON eq.id = eqa.question_id Todo : 1. Create a new model 2. Create permission 3. Create View (if needed) 4. Then you able to using this model, on you view, odoo report, or API
  • 27.
    1. Create Model ROW_NUMBER() OVER (ORDER BY eq.id) AS id Because we need to access via API, makes sure the ID is unique
  • 28.
  • 29.
  • 30.
  • 31.
    Sample Todo : 1. Createbutton on the view 2. Create function on the model, since the button type using object 1. Create button on view <xpath expr="//field[@name='stage_id']" position="before"> <button type="object" name="action_generate_certification" string="Test Certification" class="btn btn-secondary" attrs="{'invisible': [('is_certificate', '=', False)]}"/> </xpath>
  • 32.
    2. Create Function defaction_generate_certification(self): return { 'type': 'ir.actions.act_url', 'target': 'new', 'url': "/api/certificate/generate/test?event_id=" + str(self.id) + "&partner_id=" + str(self.env.user.partner_id.id), }
  • 33.
    Send Email viaAPI and using Odoo Email Template
  • 34.
    Sample Todo : 1. Emailtemplate and choose the model will applies to 2. Testing using API
  • 35.
    Access template emailusing API #Send Email Registration email_template_obj = request.env['mail.template'] template_id = email_template_obj.sudo().search([('name','=','Registration Acqalm Account Created'),('model_id.model', '=', 'res.partner')]) template_id.send_mail(_partner_id, force_send=True) _logger.info("send Email Succeed")
  • 36.
  • 37.
    Knowledge Base 1. https://www.odoo.com/ 2.https://www.genkiware.com/2020/05/03/how-to-write-a-module-in-odoo-part-i- module-structure/ 3. https://en.ngasturi.id/ 4. https://www.youtube.com/c/OdooMates