Skip to content

Commit

Permalink
💣 Added child_tree and onload func in js
Browse files Browse the repository at this point in the history
Signed-off-by: Vildan Safin <[email protected]>
  • Loading branch information
Enigma228322 committed Mar 16, 2020
1 parent 81e4d1e commit 79c35c7
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 158 deletions.
2 changes: 1 addition & 1 deletion saas_apps/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# "price": 9.00,
# "currency": "EUR",

"depends": ['website'],
"depends": ['website', 'saas'],
"external_dependencies": {"python": [], "bin": []},
"data": [
'security/ir.model.access.csv',
Expand Down
9 changes: 3 additions & 6 deletions saas_apps/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ def catch_app_click(self, **kw):

@http.route(['/what_dependencies'], type='json', auth='public', website=True)
def what_dependencies(self, **kw):
app_name, which_price = kw['args']
app = http.request.env['saas.line'].search([('name', '=', app_name)])
month = False
if which_price == 'month':
month = True
app_name = kw['args'][0]
app = http.request.env['saas.line'].search([('module_name', '=', app_name)])
return {
'dependencies': app.dependencies_info(month, 0)
'dependencies': app.dependencies_info('root')
}
14 changes: 9 additions & 5 deletions saas_apps/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ Configuration

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

Usage
=====

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

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

Uninstallation
==============
Expand Down
70 changes: 34 additions & 36 deletions saas_apps/models/saas_apps.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# Copyright 2020 Vildan Safin <https://github.com/Enigma228322>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo import api, fields, models, modules
import logging

_logger = logging.getLogger(__name__)


class SAASModule(models.Model):
_name = 'saas.module'
_description = 'Model line'
_inherit = 'saas.module'

name = fields.Char(default="default", string="Module Name")
month_price = fields.Float(default=0.0, string="Month price")
year_price = fields.Float(default=0.0, string="Year price")
icon_path = fields.Char(compute='_compute_path', string="icon path")
icon_path = fields.Char(string="Icon path")
saas_modules = fields.Many2one('saas.line', string="Module dependencies")

def _compute_path(self):
self.icon_path = "/saas_apps/static/src/img/%s.png" % self.name

@api.model
def create(self, vals):
rec = super(SAASModule, self).create(vals)
Expand All @@ -40,38 +35,44 @@ def add_new_module(self, name):

def refresh(self):
irmodules = self.env["ir.module.module"].search([])
ir_module_obj = self.env["ir.module.module"]
if len(irmodules) > len(self.search([])):
for irmodule in irmodules:
if len(self.search([('name', '=', irmodule.name)])) == 0:
self.create({'name': irmodule.name})

def cost(self, month):
if month:
return self.month_price
else:
return self.year_price


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

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

def refresh(self):
apps = self.env["saas.module"]
apps.search([]).unlink()
self.search([]).unlink()
apps.refresh()
apps = apps.search([])
if len(apps) > len(self.search([])):
for app in apps:
for app in apps.search([]):
try:
if len(self.search([('name', '=', app.name)])) == 0:
new = self.create({'name': app.name})
new.dependencies += app
new = self.create({
'name': app.name,
'module_name': app.module_name
})
if len(ir_module_obj.get_module_info(app.name)):
for dep_name in ir_module_obj.get_module_info(app.name)['depends']:
new.dependencies += app.search([('name', '=', dep_name)])
except:
# import wdb
# wdb.set_trace()
_logger.error("Fuck!")

def _compute_year_price(self):
for module in self.dependencies:
Expand All @@ -81,29 +82,26 @@ def _compute_month_price(self):
for module in self.dependencies:
self.month_price += module.month_price

def dependencies_info(self, for_month, deep):
def dependencies_info(self, root):
apps = []
# Root module
if not deep:
apps.append({
'parent': 'root',
'name': self.name,
'price': self.dependencies[0].cost(for_month)
})
childs = []
for child in self.dependencies - self.dependencies[0]:
childs.append(child.module_name)
apps.append({
'parent': root,
'name': self.module_name,
'year_price': self.dependencies[0].year_price,
'month_price': self.dependencies[0].month_price,
'childs': childs,
'icon_path': self.dependencies[0].icon_path
})
# Looking to the period
for app in self.dependencies - self.dependencies[0]:
set = self.search([('name', '=', app.name)])
leafs = set.dependencies_info(for_month, deep + 1)
leafs = set.dependencies_info(self.name)
for leaf in leafs:
if not(leaf in apps):
apps.append(leaf)
item = {
'parent': self.name,
'name': app.name,
'price': app.cost(for_month)
}
if not(item in apps):
apps.append(item)
return apps

@api.multi
Expand Down
9 changes: 8 additions & 1 deletion saas_apps/static/src/css/calculator.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
position: fixed;
right: 15%;
top: 20%;
width: 25%;
width: 20%;
z-index: 1;
}
}
Expand All @@ -40,4 +40,11 @@
width: 100%;
z-index: 1;
}
.container{
margin-left: auto !important;
}
}

.col-lg-9{
padding-left: 0px;
}
Loading

0 comments on commit 79c35c7

Please sign in to comment.