Skip to content

Commit 79c35c7

Browse files
committed
💣 Added child_tree and onload func in js
Signed-off-by: Vildan Safin <safin@it-projects.info>
1 parent 81e4d1e commit 79c35c7

File tree

8 files changed

+197
-158
lines changed

8 files changed

+197
-158
lines changed

saas_apps/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# "price": 9.00,
1818
# "currency": "EUR",
1919

20-
"depends": ['website'],
20+
"depends": ['website', 'saas'],
2121
"external_dependencies": {"python": [], "bin": []},
2222
"data": [
2323
'security/ir.model.access.csv',

saas_apps/controllers/main.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ def catch_app_click(self, **kw):
2222

2323
@http.route(['/what_dependencies'], type='json', auth='public', website=True)
2424
def what_dependencies(self, **kw):
25-
app_name, which_price = kw['args']
26-
app = http.request.env['saas.line'].search([('name', '=', app_name)])
27-
month = False
28-
if which_price == 'month':
29-
month = True
25+
app_name = kw['args'][0]
26+
app = http.request.env['saas.line'].search([('module_name', '=', app_name)])
3027
return {
31-
'dependencies': app.dependencies_info(month, 0)
28+
'dependencies': app.dependencies_info('root')
3229
}

saas_apps/doc/index.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ Configuration
1717

1818
* `Log in as SUPERUSER <https://odoo-development.readthedocs.io/en/latest/odoo/usage/login-as-superuser.html>`__
1919
* `Activate Developer Mode <https://odoo-development.readthedocs.io/en/latest/odoo/usage/debug-mode.html>`__
20-
* Open menu ``[[ {Menu} ]] >> {Submenu} >> {Subsubmenu}``
21-
* Click ``[{Button Name}]``
20+
* Open menu ``[[ Website ]] >> Configuration >> Manage Apps``
21+
* Click ``[ Refresh ]``
22+
* Choose modules that you want to make saleable by clicking to ``[ Saleable ]``
2223

2324
Usage
2425
=====
2526

2627
{Instruction for daily usage. It should describe how to check that module works. What shall user do and what would user get.}
2728

28-
* Open menu ``[[ {Menu} ]]>> {Submenu} >> {Subsubmenu}``
29-
* Click ``[{Button Name}]``
30-
* RESULT: {what user gets, how the modules changes default behaviour}
29+
* Open ``[http://odoo-saas.sh/]``
30+
* Click ``[{Make new Odoo instance}]``
31+
* Choose modules that you want to buy by on them
32+
* Choose the using period year/month
33+
* Click ``[Buy now]``
34+
* RESULT: you will be redirected and logged in to the created build with choosen modules
3135

3236
Uninstallation
3337
==============

saas_apps/models/saas_apps.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
# Copyright 2020 Vildan Safin <https://github.com/Enigma228322>
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33

4-
from odoo import api, fields, models
4+
from odoo import api, fields, models, modules
55
import logging
66

77
_logger = logging.getLogger(__name__)
88

99

1010
class SAASModule(models.Model):
11-
_name = 'saas.module'
12-
_description = 'Model line'
11+
_inherit = 'saas.module'
1312

14-
name = fields.Char(default="default", string="Module Name")
1513
month_price = fields.Float(default=0.0, string="Month price")
1614
year_price = fields.Float(default=0.0, string="Year price")
17-
icon_path = fields.Char(compute='_compute_path', string="icon path")
15+
icon_path = fields.Char(string="Icon path")
1816
saas_modules = fields.Many2one('saas.line', string="Module dependencies")
1917

20-
def _compute_path(self):
21-
self.icon_path = "/saas_apps/static/src/img/%s.png" % self.name
22-
2318
@api.model
2419
def create(self, vals):
2520
rec = super(SAASModule, self).create(vals)
@@ -40,38 +35,44 @@ def add_new_module(self, name):
4035

4136
def refresh(self):
4237
irmodules = self.env["ir.module.module"].search([])
38+
ir_module_obj = self.env["ir.module.module"]
4339
if len(irmodules) > len(self.search([])):
4440
for irmodule in irmodules:
4541
if len(self.search([('name', '=', irmodule.name)])) == 0:
4642
self.create({'name': irmodule.name})
47-
48-
def cost(self, month):
49-
if month:
50-
return self.month_price
51-
else:
52-
return self.year_price
5343

5444

5545
class SAASDependence(models.Model):
5646
_name = 'saas.line'
5747
_description = 'Module dependencies'
5848

5949
# First dependence is root module
60-
name = fields.Char(default="default", string="Module Name")
50+
name = fields.Char(default="default", string="Module technical name")
51+
module_name = fields.Char(default="default", string="Module name")
6152
allow_to_sell = fields.Boolean(string="Sellable")
6253
dependencies = fields.One2many('saas.module', 'saas_modules', ondelete='cascade', delegate=True)
6354
year_price = fields.Float(default=0.0, compute='_compute_year_price', string="Price per year")
6455
month_price = fields.Float(default=0.0, compute='_compute_month_price', string="Price per month")
6556

6657
def refresh(self):
6758
apps = self.env["saas.module"]
59+
apps.search([]).unlink()
60+
self.search([]).unlink()
6861
apps.refresh()
69-
apps = apps.search([])
70-
if len(apps) > len(self.search([])):
71-
for app in apps:
62+
for app in apps.search([]):
63+
try:
7264
if len(self.search([('name', '=', app.name)])) == 0:
73-
new = self.create({'name': app.name})
74-
new.dependencies += app
65+
new = self.create({
66+
'name': app.name,
67+
'module_name': app.module_name
68+
})
69+
if len(ir_module_obj.get_module_info(app.name)):
70+
for dep_name in ir_module_obj.get_module_info(app.name)['depends']:
71+
new.dependencies += app.search([('name', '=', dep_name)])
72+
except:
73+
# import wdb
74+
# wdb.set_trace()
75+
_logger.error("Fuck!")
7576

7677
def _compute_year_price(self):
7778
for module in self.dependencies:
@@ -81,29 +82,26 @@ def _compute_month_price(self):
8182
for module in self.dependencies:
8283
self.month_price += module.month_price
8384

84-
def dependencies_info(self, for_month, deep):
85+
def dependencies_info(self, root):
8586
apps = []
86-
# Root module
87-
if not deep:
88-
apps.append({
89-
'parent': 'root',
90-
'name': self.name,
91-
'price': self.dependencies[0].cost(for_month)
92-
})
87+
childs = []
88+
for child in self.dependencies - self.dependencies[0]:
89+
childs.append(child.module_name)
90+
apps.append({
91+
'parent': root,
92+
'name': self.module_name,
93+
'year_price': self.dependencies[0].year_price,
94+
'month_price': self.dependencies[0].month_price,
95+
'childs': childs,
96+
'icon_path': self.dependencies[0].icon_path
97+
})
9398
# Looking to the period
9499
for app in self.dependencies - self.dependencies[0]:
95100
set = self.search([('name', '=', app.name)])
96-
leafs = set.dependencies_info(for_month, deep + 1)
101+
leafs = set.dependencies_info(self.name)
97102
for leaf in leafs:
98103
if not(leaf in apps):
99104
apps.append(leaf)
100-
item = {
101-
'parent': self.name,
102-
'name': app.name,
103-
'price': app.cost(for_month)
104-
}
105-
if not(item in apps):
106-
apps.append(item)
107105
return apps
108106

109107
@api.multi

saas_apps/static/src/css/calculator.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
position: fixed;
2727
right: 15%;
2828
top: 20%;
29-
width: 25%;
29+
width: 20%;
3030
z-index: 1;
3131
}
3232
}
@@ -40,4 +40,11 @@
4040
width: 100%;
4141
z-index: 1;
4242
}
43+
.container{
44+
margin-left: auto !important;
45+
}
46+
}
47+
48+
.col-lg-9{
49+
padding-left: 0px;
4350
}

0 commit comments

Comments
 (0)