开发¶
如果你正在阅读这段文字,那么你很可能对如何为Odoo代码库做出贡献感兴趣。无论你是有意来到这里还是偶然到达,我们都会为你提供帮助!
当你准备就绪时,前往 环境设置 章节,开始你对 Odoo 开发的贡献之旅。
环境设置¶
以下说明将帮助您准备环境,以便对代码库进行本地修改,然后将其推送到 GitHub。如果您已经完成此步骤,请跳过本节,直接前往 开始你的首次贡献。
首先,您需要 创建一个 GitHub 账户。Odoo 使用 GitHub 来管理其产品的源代码,这也是您将进行更改并提交审核的地方。
Generate a new SSH key and register it on your GitHub account.
前往 github.com/odoo/odoo,并在右上角点击 分叉 按钮,以在您的账户中创建该仓库的分叉 (您自己的副本)。如果您有权限访问 github.com/odoo/enterprise,请对它执行相同操作。这将创建一个代码库的副本,您可以对其进行修改而不会影响主代码库。如果您在 Odoo 工作,请跳过此步骤。
Install Git. It is a command-line (a text interface) tool that allows tracking the history of changes made to a file and, more importantly, working on different versions of that file simultaneously. It means you do not need to worry about overwriting someone else’s pending work when making changes.
Verify that the installation directory of Git is included in your system’s
PATH
variable.Follow the guide to update the PATH variable on Linux and macOS with the installation path of Git (by default
/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"
从源代码安装 Odoo。确保通过 Git 使用 SSH 获取源代码。
将 Git 配置为将更改推送到你的分支,而不是主代码库。如果你在 Odoo 工作,请将 Git 配置为将更改推送到账户 odoo-dev 上创建的共享分支。
在下面的命令中,将
<your_github_account>
替换为您创建分支(fork)的 GitHub 账户名称。$ cd /CommunityPath $ git remote add dev git@github.com:<your_github_account>/odoo.git
如果你可以访问
odoo/enterprise
,请也配置相关的远程仓库。$ 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
就是这样!您已准备好进行您的首次贡献:提交您的第一个贡献。
开始你的首次贡献¶
重要
既然你的环境已经配置完成,你就可以开始为代码库做贡献了。在终端中,导航到你从源代码安装 Odoo 的目录,并按照下面的指南操作。
选择您希望进行更改的 Odoo 版本。请注意,针对 不支持的 Odoo 版本 的贡献是不被接受的。本指南假设更改的目标是 Odoo 18,对应分支
18.0
。从分支 18.0 创建一个新分支,将分支名称以基础分支为前缀:
18.0-...
。如果您在 Odoo 工作,请在分支名称后加上您的 Odoo 用户名:18.0-...-xyz
。Example
$ git switch -c 18.0-fix-invoices
$ git switch -c 18.0-fix-invoices-xyz
Sign the Odoo CLA if not already done. Skip this step if you work at Odoo.
对代码库进行所需的更改。在处理代码库时,请遵循以下规则:
提交您的更改。按照 Git 指南 中的说明编写清晰的提交信息。
$ git add . $ git commit
将你的更改推送到你自己的分支,我们已为该分支添加了远程别名
dev
。Example
$ git push -u dev 18.0-fix-invoices-xyz
在 GitHub 上打开一个 PR 以提交您的更改进行审核。
根据您的更改所针对的代码库,前往 Odoo/Odoo 代码库的比较页面,或 Odoo/Enterprise 代码库的比较页面。
选择 18.0 作为基础版本。
点击 跨分叉比较。
选择 <your_github_account>/odoo 或 <your_github_account>/enterprise 作为主仓库。将
<your_github_account>
替换为你在 GitHub 上创建分支的账户名称,或在你于 Odoo 工作时使用 odoo-dev。查看您的更改,然后点击 创建拉取请求 按钮。
勾选 允许维护者进行编辑 复选框。如果您在 Odoo 工作,请跳过此步骤。
请完成描述,然后再次点击 创建拉取请求 按钮。
页面底部,检查可合并状态并解决任何问题。
一旦您的 PR 准备好可以合并,Odoo 团队的一名成员将被自动分配进行审查。如果审查人员有疑问或意见,他们将以评论的形式提出,您将通过电子邮件收到通知。这些评论必须得到解决,贡献才能继续推进。
一旦您的更改获得批准,审查人员将合并这些更改,并在下一次代码更新后对所有 Odoo 用户可用!