开发¶
如果您正在阅读本文,那么您一定已经为Odoo的代码库做出不少贡献,或者十分有兴趣了解如何贡献Odoo。无论您出于何种目的,能偶然来到这里,我们都将为您提供所需的信息!
更多内容
当您准备好了,欢迎阅读 环境设置 部分,开始您的Odoo开发贡献之旅。
环境设置¶
以下说明将帮助您准备您的环境以进行对代码库的更改,并推送它们到GitHub。如果您已经完成此步骤,请跳转到 Make your first contribution 部分。
首先,你需要 创建一个GitHub账户 。Odoo使用GitHub来管理其产品的源代码,这是您将进行更改并提交给审核的场所。
转到 github.com/odoo/odoo 并在右上角点击 Fork 按钮以创建一个 fork (您自己的副本) 仓库。转到 github.com/odoo/enterprise 如果已经有访问权限。这会创建一个代码库的副本,您可以在此处进行更改,而不会影响主代码库。如果您是Odoo的worker,请跳过此步骤。
安装 Git 。它是一个命令行 (一个文本界面) 工具,允许跟踪对文件的更改并,更重要的,在文件之间进行不同版本的工作。这意味着您不需要担心覆盖其他用户的待处理工作,当进行更改时。
验证Git的安装目录是否包含在系统的`PATH`变量中。
在 Linux 和 macOS 上更新 PATH 变量。 <https://unix.stackexchange.com/a/26059>`_ (默认为路径为
/usr/bin/git)。Follow the guide to update the PATH variable on Windows with the installation path of Git (by default
C:\Program Files\Git).配置 Git 以识别你未来贡献的作者身份。输入你注册时用来在GitHub上的同一个邮箱地址。
$ git config --global user.name "Your Name" $ git config --global user.email "youremail@example.com"
Install Odoo from the sources. Make sure to fetch the sources through Git with SSH.
Configure Git to push changes to your fork(s) rather than to the main codebase. If you work at Odoo, configure Git to push changes to the shared forks created on the account odoo-dev.
In the command below, replace
<your_github_account>with the name of the GitHub account on which you created the fork(s).$ cd /CommunityPath $ git remote add dev git@github.com:<your_github_account>/odoo.git
If you have access to
odoo/enterprise, configure the related remote too.$ cd /EnterprisePath $ git remote add dev git@github.com:<your_github_account>/enterprise.git
$ cd /CommunityPath $ git remote add dev git@github.com:odoo-dev/odoo.git $ git remote set-url --push origin you_should_not_push_on_this_repository $ cd /EnterprisePath $ git remote add dev git@github.com:odoo-dev/enterprise.git $ git remote set-url --push origin you_should_not_push_on_this_repository
That’s it! You are ready to make your first contribution.
Make your first contribution¶
重要
Odoo development can be challenging for beginners. We recommend you to be knowledgeable enough to code a small module before contributing. If that is not the case, take some time to go through the developer tutorials to fill in the gaps.
Some steps of this guide require to be comfortable with Git. Here are some tutorials and an interactive training if you are stuck at some point.
Now that your environment is set up, you can start contributing to the codebase. In a terminal, navigate to the directory where you installed Odoo from sources and follow the guide below.
Choose the version of Odoo to which you want to make changes. Keep in mind that contributions targeting an unsupported version of Odoo are not accepted. This guide assumes that the changes target Odoo 19, which corresponds to branch
19.0.Create a new branch starting from branch 19.0. Prefix the branch name with the base branch:
19.0-.... If you work at Odoo, suffix the branch name with your Odoo handle:19.0-...-xyz.Example
$ git switch -c 19.0-fix-invoices
$ git switch -c 19.0-fix-invoices-xyz
Sign the Odoo CLA if not already done. Skip this step if you work at Odoo.
Make the desired changes to the codebase. When working on the codebase, follow these rules:
Keep your changes focused and specific. It is best to work on one particular feature or bug fix at a time rather than tackle multiple unrelated changes simultaneously.
Respect the stable policy when working in another branch than
master.Follow the coding guidelines.
Test your changes thoroughly and write tests to ensure that everything is working as expected and that there are no regressions or unintended consequences.
Commit your changes. Write a clear commit message as instructed in the Git guidelines.
$ git add . $ git commit
Push your change to your fork, for which we added the remote alias
dev.Example
$ git push -u dev 19.0-fix-invoices-xyz
Open a PR on GitHub to submit your changes for review.
Go to the compare page of the odoo/odoo codebase, or the compare page of the odoo/enterprise codebase, depending on which codebase your changes target.
Select 19.0 for the base.
Click on compare across forks.
Select <your_github_account>/odoo or <your_github_account>/enterprise for the head repository. Replace
<your_github_account>with the name of the GitHub account on which you created the fork or by odoo-dev if you work at Odoo.Review your changes and click on the Create pull request button.
Tick the Allow edits from maintainer checkbox. Skip this step if you work at Odoo.
Complete the description and click on the Create pull request button again.
页面底部,检查合并状态并解决任何问题。
As soon as your PR is ready for merging, a member of the Odoo team is automatically assigned for review. If the reviewer has questions or remarks, they will post them as comments and you will be notified by email. Those comments must be resolved for the contribution to go forward.
Once your changes are approved, the review merges them and they become available for all Odoo users after the next code update!