diff --git a/saas_apps/controllers/main.py b/saas_apps/controllers/main.py index 39b2870b4..f6467ce33 100644 --- a/saas_apps/controllers/main.py +++ b/saas_apps/controllers/main.py @@ -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 + } diff --git a/saas_apps/models/saas_apps.py b/saas_apps/models/saas_apps.py index 1530d9071..f239f12af 100644 --- a/saas_apps/models/saas_apps.py +++ b/saas_apps/models/saas_apps.py @@ -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): @@ -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): @@ -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 }) @@ -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() diff --git a/saas_apps/static/src/js/apps.js b/saas_apps/static/src/js/apps.js index b0eb5b06f..c50f6591d 100644 --- a/saas_apps/static/src/js/apps.js +++ b/saas_apps/static/src/js/apps.js @@ -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); }); } }); diff --git a/saas_apps/views/calculator.xml b/saas_apps/views/calculator.xml index 5eb50c245..53d85c5eb 100644 --- a/saas_apps/views/calculator.xml +++ b/saas_apps/views/calculator.xml @@ -35,7 +35,7 @@
-

+

diff --git a/saas_apps/views/manage.xml b/saas_apps/views/manage.xml index ee591749a..3ea090da7 100644 --- a/saas_apps/views/manage.xml +++ b/saas_apps/views/manage.xml @@ -39,7 +39,7 @@ saas.lines.list saas.lines - + diff --git a/saas_apps/views/refresh.xml b/saas_apps/views/refresh.xml index 37cd124df..9e216b2f8 100644 --- a/saas_apps/views/refresh.xml +++ b/saas_apps/views/refresh.xml @@ -3,7 +3,7 @@