Skip to content

Commit

Permalink
💣 started js low flexing
Browse files Browse the repository at this point in the history
Signed-off-by: Vildan Safin <[email protected]>
  • Loading branch information
Enigma228322 committed Mar 2, 2020
1 parent 29848c6 commit 235ebc2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 43 deletions.
9 changes: 9 additions & 0 deletions saas_apps/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ def catch_app_click(self, **kw):
apps.refresh()
# request.redirect('/manage/%s' % name)
return {}

@http.route(['/what_dependencies'], type='json', auth='public', website=True)
def put_in_basket(self, **kw):
app_name = kw['args'][0]
app = http.request.env['saas.lines'].search([('module_name', '=', app_name)])
return {
'dependencies': app.dependencies_info(),
'price': app.final_set_price
}
58 changes: 28 additions & 30 deletions saas_apps/models/saas_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

_logger = logging.getLogger(__name__)

class SAASBasket(models.Model):
_name = 'saas.basket'
_description = 'Module for selecting applications'
# class SAASBasket(models.Model):
# _name = 'saas.basket'
# _description = 'Module for selecting applications'

users = fields.Integer(default=0)
module_sets_in_basket = fields.One2many('saas.set', 'basket', ondelete="cascade", delegate=True)
final_basket_price = fields.Float(default=0.0, compute='_compute_price', string="Price of the set")
# users = fields.Integer(default=0)
# name = fields.Char(default="Basket", string="Basket Name")
# modules_in_basket = fields.One2many('saas.lines', 'basket', ondelete="cascade", delegate=True)
# final_basket_price = fields.Float(default=0.0, compute='_compute_price', string="Price of the set")

def _compute_price(self):
for module_set in self.module_set_in_basket:
self.final_basket_price = self.final_basket_price + module_set.price
# def _compute_price(self):
# if len(self.modules_in_basket) > 0:
# for module in self.modules_in_basket:
# self.final_basket_price += module.final_set_price


class SAASLine(models.Model):
Expand All @@ -27,10 +29,17 @@ class SAASLine(models.Model):
price = fields.Float(default=0.0, string="Price")
allow_to_sell = fields.Boolean(string="Sellable")
icon_path = fields.Char(compute='_compute_path', string="icon path")
dependencies = fields.Many2one('saas.set', string="Module dependences")
dependencies = fields.One2many('saas.set', 'saas_modules', ondelete='cascade', delegate=True)
final_set_price = fields.Float(default=0.0, compute='_compute_price', string="Price of the set")
# basket = fields.Many2one('saas.basket', string='Modules in basket')

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

def _compute_price(self):
self.final_set_price = self.price
for module in self.dependencies:
self.final_set_price += module.saas_modules.price

@api.constrains('price')
def _validate_price(self):
Expand All @@ -39,9 +48,6 @@ def _validate_price(self):
raise "Price can't be negative."

def add_new_module(self, name):
# for module in self:
# if(module.module_name == name)
# return False
self.create({
'module_name': name
})
Expand All @@ -53,25 +59,17 @@ def refresh(self):
for irmodule in irmodules:
if len(self.search([('module_name', '=', irmodule.name)])) == 0:
self.create({'module_name': irmodule.name})

def dependencies_info(self):
apps = []
for app in self.dependencies:
apps.append(app.saas_modules.module_name)
return apps


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

basket = fields.Many2one('saas.basket', string='Modules in basket')
modules = fields.One2many('saas.lines', 'dependencies', ondelete='cascade', delegate=True)
final_set_price = fields.Float(default=0.0, compute='_compute_price', string="Price of the set")

def add_dependence(self, new_module_name, new_module_price):
try:
self.modules.create({
'module_name': new_module_name,
'price': int(new_module_name_price)
})
except:
_logger.error("Can't add new item in dependencies of this module")

def _compute_price(self):
for module in self.modules:
self.final_set_price = self.final_set_price + module.price
saas_modules = fields.Many2one('saas.lines', string="Module dependencies")
# module = fields.One2many()
12 changes: 2 additions & 10 deletions saas_apps/static/src/js/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ odoo.define('saas_apps.model', function (require){

var session = require('web.session');


// function poopup_widjet(args){

// }

window.onclick=function(e){
console.log(e.target.innerText);

if(window.location.pathname === "/manage")
session.rpc('/test', {
if(window.location.pathname === "/price" && e.target.id == "application")
session.rpc('/what_dependencies', {
args: [e.target.innerText]
}).then(function (result) {
console.log(result);
// poopup_widjet(result);
});
}
});
2 changes: 1 addition & 1 deletion saas_apps/views/calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div class="openerp_enterprise_pricing_step_body mb24">
<div class="form-row">
<t t-foreach="apps" t-as="app">
<p class="col-12 col-sm-6 col-lg-4 shadow p-3 bg-white rounded price-window"><t t-esc="app.module_name"/></p>
<p id="application" class="col-12 col-sm-6 col-lg-4 shadow p-3 bg-white rounded price-window"><t t-esc="app.module_name"/></p>
</t>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion saas_apps/views/manage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<field name="name">saas.lines.list</field>
<field name="model">saas.lines</field>
<field name="arch" type="xml">
<tree string="Manage Apps" editable="bottom">
<tree string="Manage Apps">
<field name="module_name"/>
<field name="allow_to_sell"/>
</tree>
Expand Down
2 changes: 1 addition & 1 deletion saas_apps/views/refresh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<template xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after">
<button t-if="widget.modelName == 'saas.lines'" type="button" class="btn btn-primary btn-sm oe_filter_button" accesskey="f">
<button t-if="widget.modelName == 'saas.lines'" type="button" class="btn btn-primary oe_filter_button" accesskey="f">
Refresh
</button>
</t>
Expand Down

0 comments on commit 235ebc2

Please sign in to comment.