Skip to content

Commit

Permalink
⬇️1️⃣2️⃣
Browse files Browse the repository at this point in the history
Signed-off-by: Vildan Safin <[email protected]>
  • Loading branch information
Enigma228322 committed May 9, 2020
1 parent c571c0c commit e0b6343
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
8 changes: 5 additions & 3 deletions saas_apps/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def catch_app_click(self, **kw):

@route(['/what_dependencies'], type='json', auth='public')
def search_incoming_app_dependencies(self, **kw):
app_tech_name = kw.get('root')[0]
app_tech_name = kw.get('root')
app = request.env['saas.line'].sudo().search([('name', '=', app_tech_name)])
return {
'dependencies': app.dependencies_info('root')
Expand Down Expand Up @@ -94,8 +94,10 @@ def take_product_ids(self, **kw):
apps_product_ids = []
apps = modules.search([('name', 'in', module_names), ('application', '=', True)])
templates = request.env['saas.template'].sudo().search([('name', 'in', module_names)])
for app in apps.product_id + templates.product_id:
apps_product_ids.append(app.id)
for app in apps:
apps_product_ids.append(app.product_id.id)
for package in templates:
apps_product_ids.append(package.product_id.id)

return {
'ids': apps_product_ids
Expand Down
2 changes: 1 addition & 1 deletion saas_apps/data/saas_apps_product_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<record id="product_user" model="product.product">
<field name="name">User</field>
<field name="price">10</field>
<field file="saas_apps/static/src/img/user.png" name="image_1920" type="base64" />
<field file="saas_apps/static/src/img/user.png" name="image" type="base64" />
</record>
</odoo>
5 changes: 2 additions & 3 deletions saas_apps/data/saas_base_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
</record>

<record id="saas_apps_base_image" model="ir.attachment">
<field name="public" eval="True" />
<field name="name">Application base icon</field>
<field name="store_fname">base.png</field>
<field name="type">binary</field>
<field name="datas_fname">base.png</field>
<field name="use_as_background">True</field>
<field
name="datas"
type="base64"
Expand Down
36 changes: 18 additions & 18 deletions saas_apps/models/saas_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ class SAASDependence(models.Model):
def _compute_currency_id(self):
self.currency_id = self.company_id.currency_id

def _compute_default_image(self):
return self.env.ref("saas_apps.saas_apps_base_image").datas
# def _compute_default_image(self):
# return self.env.ref("saas_apps.saas_apps_base_image").datas

app_image = fields.Image(
string='App image',
default=_compute_default_image
app_image = fields.Binary(
string='App image'
)

def refresh_lines(self):
Expand All @@ -85,17 +84,16 @@ def refresh_lines(self):
apps.refresh_modules()
base_icon = self.env["ir.module.module"].search([('name', '=', 'base')]).icon_image
for app in apps.search([]):
self.delete_shit(app.name)
if self.search_count([('name', '=', app.name)]) == 0:
ir_module_obj = self.env["ir.module.module"].get_module_info(app.name)
if len(ir_module_obj):
new = self.create({
'name': app.name,
'module_name': ir_module_obj['name'],
'app_image': self.env["ir.module.module"].search([('name', '=', app.name)]).icon_image,
'application': ir_module_obj['application'],
'dependencies': app + apps.search([('name', 'in', ir_module_obj['depends'])])
'application': ir_module_obj['application']
})
new.dependencies = app + apps.search([('name', 'in', ir_module_obj['depends'])])
else:
new = self.create({
'name': app.name,
Expand All @@ -116,11 +114,12 @@ def make_product(self, app):
app.product_id += prod_templ.create({
'name': app.module_name,
'price': app.year_price,
'image_1920': app.app_image
'image': app.app_image
})

def change_product_price(self, app, price):
app.product_id.price = price
if len(app) == 1:
app.product_id.price = price

def compute_price(self):
sum = 0
Expand Down Expand Up @@ -203,12 +202,11 @@ class SAASAppsTemplate(models.Model):
year_price = fields.Float()
product_id = fields.Many2many('product.product', ondelete='cascade')

def _compute_default_image(self):
return self.env.ref("saas_apps.saas_apps_base_image").datas
# def _compute_default_image(self):
# return self.env.ref("saas_apps.saas_apps_base_image").datas

package_image = fields.Image(
string='Package image',
default=_compute_default_image
package_image = fields.Binary(
string='Package image'
)

@api.onchange('set_as_base')
Expand All @@ -229,13 +227,15 @@ def compute_price(self):
self.month_price = sum

def change_product_price(self, package, price):
package.product_id.price = price
if len(package) == 1:
package.product_id.price = price

@api.model
def create(self, vals):
res = super(SAASAppsTemplate, self).create(vals)
if res.set_as_package:
res.compute_price()
if not (res.year_price + res.month_price):
res.compute_price()
prod = self.env['product.product']
ready_product = prod.search([('name', '=', res.name)])
if ready_product:
Expand All @@ -245,7 +245,7 @@ def create(self, vals):
res.product_id += prod.create({
'name': res.name,
'price': res.year_price,
'image_1920': res.package_image
'image': res.package_image
})
return res

Expand Down
2 changes: 1 addition & 1 deletion saas_apps/static/src/js/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ odoo.define('saas_apps.model', function (require){
$.each($('.app_tech_name'), function(key, app){
++requests_stack;
session.rpc('/what_dependencies', {
root: [app.innerText]
root: app.innerText
}).then(function (result) {
--requests_stack;
if(requests_stack < 5){
Expand Down

0 comments on commit e0b6343

Please sign in to comment.