logo资料库

odoo12开发手册.pdf

第1页 / 共395页
第2页 / 共395页
第3页 / 共395页
第4页 / 共395页
第5页 / 共395页
第6页 / 共395页
第7页 / 共395页
第8页 / 共395页
资料共395页,剩余部分请下载后查看
Cover
Title Page
Copyright and Credits
Packt Upsell
Foreword
Contributors
Table of Contents
Preface
Chapter 1: Quick Start Using the Developer Mode
Technical requirements
Introducing the to-do list project
Basic concepts
The Odoo architecture
Odoo community versus Odoo enterprise
Odoo version policy
Preparing a basic work environment
Using an Odoo SaaS trial database
Installing Odoo on Windows
Installing Odoo using Docker containers
Other installation options
Creating a work database
Enabling the developer mode
Modifying an existing model to add a field
Adding a field to a Model
Adding a field to a form view
Creating a new Model
Configuring access control security
Security groups
Security access control lists
Security record rules
The superuser account
Creating menu items
Creating views
List views
Form views
Search views
Summary
Questions
Chapter 2: Preparing the Development Environment
Technical requirements
Setting up a host for the Odoo server
Installing the Windows Subsystem for Linux
Installing a Linux server
Installing Odoo from source
Installing the PostgreSQL database
Installing Odoo system dependencies
Installing Odoo from source
Initializing a new Odoo database
Managing Odoo databases
More server configuration options
Odoo server configuration files
Changing the listening port
Database selection options
Managing server log messages
Installing additional modules
Finding community modules
Configuring the add-ons path
Installing Odoo in a Python virtual environment
Downloading and installing add-on modules from PyPI
The server development mode
Summary
Chapter 3: Your First Odoo Application
Technical requirements
Overview of the library project
Creating a new addon module
Preparing the addons path
Creating the module directory and manifest
Adding an icon
Choosing a license
Installing a new module
Upgrading modules
Creating a new application
Adding the app's top menu item
Adding security groups
Adding automated tests
Testing business logic
Testing access security
The model layer
Creating the data model
Setting up access security
Adding access control security
Row-level access rules
The view layer
Adding menu items
Creating the form view
Business document form views
Adding action buttons
Using groups to organize forms
The complete form view
Adding list and search views
The business logic layer
Adding business logic
Web pages and controllers
Summary
Questions
Further Reading
Chapter 4: Extending Modules
Technical requirements
Learning project – extending the Library app
In-place Model extension
Adding fields to a Model
Modifying existing fields
Modifying Views and data
Extending Views
Selecting extension points with XPath
Modifying data
More Model inheritance mechanisms
Copying features with prototype inheritance
Embedding Models using delegation inheritance
Extending Models using mixin classes
Extending Python methods
Extending web controllers and templates
Extending Web Controllers
Extending QWeb Templates
Summary
Questions
Further reading
Chapter 5: Import, Export, and Module Data
Technical requirements
Understanding the external identifier concept
How external identifiers work
Finding external identifiers
Exporting and importing CSV data files
Exporting data
Importing data
Related records in CSV data files
Adding module data
Demonstration data
Using XML data files
The noupdate data attribute
Defining records in XML
Setting field values directly
Setting values using expressions
Setting values on many-to-one relation fields
Setting values on to-many relation fields
Shortcuts for frequently used models
Other actions in XML data files
Deleting records
Calling model methods
Summary
Questions
Further reading
Chapter 6: Models – Structuring the Application Data
Technical requirements
Learning project – improving the Library app
Creating models
Model attributes
Models and Python classes
Transient and abstract models
Inspecting existing models
Creating fields
Basic field types
Common field attributes
Special field names
Relationships between models
Many-to-one relationships
One-to-many inverse relationships
Many-to-many relationships
Hierarchical relationships
Flexible relationships using Reference fields
Computed fields
Searching and writing to computed fields
Storing computed fields
Related fields
Model constraints
SQL model constraints
Python model constraints
About the Odoo base Models
Summary
Chapter 7: Recordsets – Working with Model Data
Technical requirements
Using the shell command
The execution environment
Environment attributes
The environment context
Modifying the recordset execution environment
Querying data with recordsets and domains
Creating recordsets
Domain expressions
Accessing data on recordsets
Accessing data on records
Accessing relational fields
Accessing date and time values
Converting text-represented dates and times
Writing on records
Writing with object-style value assignment
Writing with the write() method
Writing date and time values
Creating and deleting records
Composing recordsets
Low-level SQL and database transactions
Summary
Chapter 8: Business Logic – Supporting Business Processes
Technical requirements
Learning project – the library_checkout module
Using stages for document-centered workflows
The ORM method decorators
Methods for recordsets – @api.multi
Methods for singleton records – @api.one
Class static methods – @api.model
On change methods
Other model method decorators
Using the ORM built-in methods
Methods for writing model data
Methods for data import and export
Methods to support the user interface
The message and activity features
Message subtypes
Posting messages
Adding followers
Creating a wizard
The wizard model
The wizard form
The wizard business logic
Using log messages
Raising exceptions
Unit tests
Adding unit tests
Running tests
Setting up tests
Writing test cases
Testing exceptions
Development tools
Server development options
Debugging
The Python debugger  
A sample debugging session
Alternative Python debuggers
Printing messages and logging 
Inspecting and killing running processes
Summary
Further reading
Chapter 9: External API – Integrating with Other Systems
Technical requirements
Learning project – a client to catalogue books
Setting up Python on the client machine
Connecting to Odoo API using XML-RPC
Running server methods using XML-RPC
Search and read API methods
The Library client XML-RPC interface
The Library client user interface
Using the OdooRPC library
About the ERPpeek client
Summary
Further reading
Chapter 10: Backend Views – Designing the User Interface
Technical requirements
Menu items
Window Actions
Form view structure
Business document views
The header
Header buttons
The stage pipeline
Using states instead of stages
The document sheet
Title and subtitle
Grouping the form content
Tabbed notebooks
Fields
Labels for fields
Field widgets
Relational fields
Buttons
Smart buttons
Dynamic view elements
On-change events
Dynamic attributes
List views
Search views
Other view types
Activity views
Calendar views
Pivot views
Graph views
Summary
Further reading
Chapter 11: Kanban Views and Client-Side QWeb
Technical requirements
About Kanban boards
Kanban views
Designing Kanban views
Priority, Kanban state, and color
Kanban card elements
The Kanban card layout
Adding a Kanban card option menu
Actions in Kanban views
The QWeb template language
The QWeb JavaScript evaluation context
Dynamic attributes by string substitution – t-attf
Dynamic attributes by expressions – t-att
Loops – t-foreach
Conditionals – t-if
Rendering values – t-esc and t-raw
Set values on variables – t-set
Call and reuse other templates – t-call
Dynamic attributes using dictionaries and lists
Inheritance on Kanban views
Custom CSS and JavaScript assets
Summary
Further reading
Chapter 12: Reports and Server-Side QWeb
Technical requirements
Installing wkhtmltopdf
Creating business reports
QWeb report templates
Presenting data in reports
Rendering images
Report totals
Defining paper formats
Enabling language translation in reports
Reports based on custom SQL
Summary
Further reading
Chapter 13: Creating Website Frontend Features
Technical requirements
Learning project – the Library self-service
Our first web page
Hello World using a QWeb template
HelloCMS!
Building websites
Adding CSS and JavaScript assets
The checkout-list controller
The checkout QWeb template
The checkout detail page
Summary
Further reading
Chapter 14: Deploying and Maintaining Production Instances
Technical requirements
Installing Odoo from source code
Installing dependencies
Preparing a dedicated system user
Installing from the source code
Setting up the configuration file
Multiprocessing workers
Setting up Odoo as a system service
Creating a systemd service
Creating an Upstart or sysvinit service
Checking the Odoo service from the command line
Setting up an nginx reverse proxy
Configuring and enforcing HTTPS
Creating a self-signed SSL certificate
Configuring HTTPS access on nginx
Caching static content
Server and module updates
Creating a staging environment
Updating Odoo source code
Summary
Further reading
Assessments
Other Books You May Enjoy
Index
Odoo 12 Development Essentials Fourth Edition Fast-track your Odoo development skills to build powerful business applications Daniel Reis BIRMINGHAM - MUMBAI
Odoo 12 Development Essentials Fourth Edition Copyright © 2018 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Pavan Ramchandani Acquisition Editor: Alok Dhuri Content Development Editor: Manjusha Mantri Technical Editor: Abin Sebastian Copy Editor: Safis Editing Project Coordinator: Prajakta Naik Proofreader: Safis Editing Indexer: Priyanka Dhadke Graphics: Jisha Chirayil Production Coordinator: Shraddha Falebhai First published: April 2015 Second edition: November 2016 Third edition: March 2018 Fourth edition: December 2018 Production reference: 1271218 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78953-247-0 www.packtpub.com
mapt.io Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website. Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Mapt is fully searchable Copy and paste, print, and bookmark content Packt.com Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details. At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Foreword When I joined Odoo (a long time ago!), my first challenge was to deliver training courses for consultants, including technical sessions for new Odoo developers. Daniel's Odoo Development Essentials is the realization of my wishes from these sessions; the companion book I wish I could have given to the participants to kick-start their first contact with Odoo. Chapter after chapter, he walks you through the creation of your first Odoo app, following best practices at every step. Starting with a solid development environment, you'll soon feel comfortable with your Odoo system, and quickly shape up a typical app. From the model groundwork upwards, you'll learn about each framework layer, including the latest frontend features and the RPC API. In this cloud era, integration is key, and Odoo features a very comprehensive API, opening up endless integration options. Daniel also includes reference documentation for the most important API areas, and before you know it, you will have grasped the fundamental design properties of Odoo—minimalism, modularity, extensibility, and scalability. Understanding this will be invaluable for any task you set out to accomplish. It is what sets apart good Odoo developers. Thanks to the yearly updates, the book is great even for more experienced developers, highlighting new features and changes in the Odoo framework. This edition does not fail to deliver, introducing Odoo 12 and the updated API, including coverage of the optimized batch create method, the new super-admin mechanisms, the enhanced debug menu, and much more. The book also includes a wealth of pro tips, acquired through years of experience, that should make a seasoned Odoo developer out of you in no time, without the extra gray hair! Daniel's natural talent will make you enjoy the Odoo Development Essentials journey! Olivier Dony R&D Engineer, Odoo Belgium
Contributors About the author Daniel Reis has had a long career in the IT industry, mostly as a consultant implementing business applications in variety of sectors, and today works for Securitas, a multinational security services provider. He has been working with Odoo since 2010, is an active contributor to Odoo Community Association projects, is currently a member of the board of the Odoo Community Association, and collaborates with ThinkOpen Solutions, a leading Portuguese Odoo integrator. I would like to thank my wife, Maria, for all her patience and support. My thanks also to Olivier Dony for agreeing to be part of this project and for all the valuable feedback given.
About the reviewer Parth Gajjar has a degree in computer engineering. He loves programming and designing complex applications in Odoo. He has more than 6 years of experience with Odoo. In 2012, he joined the Indian branch of Odoo, S.A. He has expertise in both the Python and the JavaScript framework of Odoo. At Odoo, he started working in the offshore department and then moved to R&D department. At Odoo, he has worked on features such as marketing automation, surveys, website forums, Odoo Mobile App, QWeb Report Engine, CSS Editor, and Domain Selector. Currently, he is active as a code reviewer at Odoo and helps developers with architectural decisions. He often gives technical training to Odoo partners and prospects. He also assists the recruitment department with technical interviews. Packt is searching for authors like you If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents Preface Chapter 1: Quick Start Using the Developer Mode Technical requirements Introducing the to-do list project Basic concepts The Odoo architecture Odoo community versus Odoo enterprise Odoo version policy Preparing a basic work environment Using an Odoo SaaS trial database Installing Odoo on Windows Installing Odoo using Docker containers Other installation options Creating a work database Enabling the developer mode Modifying an existing model to add a field Adding a field to a Model Adding a field to a form view Creating a new Model Configuring access control security Security groups Security access control lists Security record rules The superuser account Creating menu items Creating views List views Form views Search views Summary Questions Chapter 2: Preparing the Development Environment Technical requirements Setting up a host for the Odoo server Installing the Windows Subsystem for Linux Installing a Linux server Installing Odoo from source Installing the PostgreSQL database 1 8 9 9 11 12 13 14 15 15 16 16 18 18 20 22 23 25 31 34 35 36 38 40 40 44 44 46 47 49 49 50 50 51 51 52 53 54
分享到:
收藏