Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][WIP] base_module_pip: install Odoo Pypi packaged modules from the webclient #135

Draft
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base_module_pip/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generated
2 changes: 2 additions & 0 deletions base_module_pip/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
19 changes: 19 additions & 0 deletions base_module_pip/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2021 Daniel Reis
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Pip Install Odoo Modules",
"version": "14.0.1.0.0",
"category": "Tools",
"author": "Daniel Reis, Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "https://github.com/OCA/server-backend",
"depends": ["base"],
"data": [
"security/ir.model.access.csv",
"wizards/base_module_pip_install_views.xml",
],
"installable": True,
"maintainers": ["dreispt"],
"development_status": "Beta",
}
1 change: 1 addition & 0 deletions base_module_pip/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base_module
26 changes: 26 additions & 0 deletions base_module_pip/models/base_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2021 Daniel Reis
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import subprocess
import sys

from odoo import api, models
from odoo.release import version_info


class BaseModule(models.Model):
_inherit = "ir.module.module"

def _get_pypi_package_name(self, module_name):
server_version = version_info[0]
return "odoo%d-addon-%s" % (server_version, module_name.replace("_", "-"))

@api.model
def action_pip_install(self, module_name):
pkg_name = self._get_pypi_package_name(module_name)
cmd = (sys.executable, "-m", "pip", "install", pkg_name)
res = subprocess.run(

Check warning on line 22 in base_module_pip/models/base_module.py

View check run for this annotation

Codecov / codecov/patch

base_module_pip/models/base_module.py#L20-L22

Added lines #L20 - L22 were not covered by tests
*cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True
)
# TODO: find a way for res to have line breaks?
return res

Check warning on line 26 in base_module_pip/models/base_module.py

View check run for this annotation

Codecov / codecov/patch

base_module_pip/models/base_module.py#L26

Added line #L26 was not covered by tests
1 change: 1 addition & 0 deletions base_module_pip/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
2 changes: 2 additions & 0 deletions base_module_pip/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_base_module_pip_install,access_base_module_pip_install,model_base_module_pip_install,base.group_system,1,1,1,1
1 change: 1 addition & 0 deletions base_module_pip/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_pip_install
12 changes: 12 additions & 0 deletions base_module_pip/tests/test_pip_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (C) 2021 Daniel Reis
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo.tests.common import TransactionCase


class TestPipInstall(TransactionCase):
def test_get_pypi_package_name(self):
module_name = "mis_builder"
pkg_name = self.env["ir.module.module"]._get_pypi_package_name(module_name)
self.assertEqual(pkg_name, "odoo14-addon-mis-builder")
1 change: 1 addition & 0 deletions base_module_pip/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base_module_pip_install
31 changes: 31 additions & 0 deletions base_module_pip/wizards/base_module_pip_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) 2021 Daniel Reis
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import fields, models


class BaseModulePipInstall(models.TransientModel):
_name = "base.module.pip.install"
_description = "Pip Install Module"

module_name = fields.Char()

def action_module_open(self):
return {

Check warning on line 15 in base_module_pip/wizards/base_module_pip_install.py

View check run for this annotation

Codecov / codecov/patch

base_module_pip/wizards/base_module_pip_install.py#L15

Added line #L15 was not covered by tests
"domain": [], # TODO: filter by module name
"name": "Modules",
"view_mode": "tree,form",
"res_model": "ir.module.module",
"view_id": False,
"type": "ir.actions.act_window",
}

def button_pip_install(self):
Module = self.env["ir.module.module"]
for wizard in self:
Module.action_pip_install(wizard.module_name)

Check warning on line 27 in base_module_pip/wizards/base_module_pip_install.py

View check run for this annotation

Codecov / codecov/patch

base_module_pip/wizards/base_module_pip_install.py#L25-L27

Added lines #L25 - L27 were not covered by tests
# TODO: present output on form (mayve use states on wizard form)
# TODO: update modules list
# TODO: also install module_name?
return self.action_module_open()

Check warning on line 31 in base_module_pip/wizards/base_module_pip_install.py

View check run for this annotation

Codecov / codecov/patch

base_module_pip/wizards/base_module_pip_install.py#L31

Added line #L31 was not covered by tests
46 changes: 46 additions & 0 deletions base_module_pip/wizards/base_module_pip_install_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_base_module_pip_install" model="ir.ui.view">
<field name="name">Pip Install Modules</field>
<field name="model">base.module.pip.install</field>
<field name="arch" type="xml">

<form>
<p>Type the modeule name to be installed.</p>
<p
>The module name will be converted into the Pypi expected package name,
and that package will be installed</p>
<separator string="Module to install" />
<field name="module_name" />
<footer>
<button
name="button_pip_install"
string="Install"
type="object"
class="btn-primary"
/>
<button string="Cancel" special="cancel" />
</footer>
</form>

</field>
</record>

<record id="action_view_base_module_pip_install" model="ir.actions.act_window">
<field name="name">Pip Install Module</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">base.module.pip.install</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

<menuitem
name="Pip Install Module"
action="action_view_base_module_pip_install"
id="menu_view_base_module_pip_install"
parent="base.menu_management"
sequence="60"
/>

</odoo>
1 change: 1 addition & 0 deletions setup/base_module_pip/odoo/addons/base_module_pip
6 changes: 6 additions & 0 deletions setup/base_module_pip/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading