Skip to content

Commit

Permalink
💣 Added binary icons and corrected saas_apps form view
Browse files Browse the repository at this point in the history
Signed-off-by: Vildan Safin <[email protected]>
  • Loading branch information
Enigma228322 committed May 8, 2020
1 parent 0a8c338 commit 1a757b0
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 18 deletions.
2 changes: 1 addition & 1 deletion saas_apps/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SaaSAppsController(Controller):
def user_page(self, **kw):
apps = request.env['saas.line'].sudo()
packages = request.env['saas.template'].sudo()
# apps.delete_app_duplicates()
apps.delete_app_duplicates()
if not apps.search_count([]):
apps.refresh_lines()
return request.render('saas_apps.index', {
Expand Down
1 change: 1 addition & 0 deletions saas_apps/data/saas_apps_product_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +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" />
</record>
</odoo>
12 changes: 12 additions & 0 deletions saas_apps/data/saas_base_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@
<field name="template_id" eval="ref('base_template')"/>
<field name="operator_id" ref="saas.local_operator"/>
</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"
type="base64"
file="saas_apps/static/src/img/base.png"
/>
</record>
</odoo>
46 changes: 35 additions & 11 deletions saas_apps/models/saas_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from odoo import api, fields, models
import logging
from slugify import slugify
import base64

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -64,33 +65,42 @@ class SAASDependence(models.Model):
default=lambda s: s.env.user.company_id,
)
currency_id = fields.Many2one("res.currency", compute="_compute_currency_id")
product_id = fields.Many2many('product.product', ondelete='cascade')
product_id = fields.Many2many('product.product')

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

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

def refresh_lines(self):
apps = self.env["saas.module"]
for line in map(self.browse, self._search([])):
line.unlink()
apps.refresh_modules()
base_icon_path = '/base/static/description/icon.png'
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'],
'icon_path': ir_module_obj['icon'],
'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'])])
})
else:
new = self.create({
'name': app.name,
'module_name': app.name,
'icon_path': base_icon_path
'app_image': base_icon
})

@api.multi
Expand All @@ -105,7 +115,8 @@ def make_product(self, app):
else:
app.product_id += prod_templ.create({
'name': app.module_name,
'price': app.year_price
'price': app.year_price,
'image_1920': app.app_image
})

def delete_app_duplicates(self):
Expand Down Expand Up @@ -201,9 +212,16 @@ class SAASAppsTemplate(models.Model):
set_as_package = fields.Boolean("Package")
month_price = fields.Float()
year_price = fields.Float()
icon_path = fields.Char(string="Icon path")
product_id = fields.Many2many('product.product', ondelete='cascade')

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
)

@api.onchange('set_as_base')
def change_base_template(self):
old_base_template = self.search([('set_as_base', '=', True)])
Expand All @@ -229,11 +247,17 @@ def create(self, vals):
res = super(SAASAppsTemplate, self).create(vals)
if res.set_as_package:
res.compute_price()
res.icon_path = 'saas_apps/static/src/img/idea.png'
res.product_id += self.env['product.product'].create({
'name': res.name,
'price': res.year_price
})
prod = self.env['product.product']
ready_product = prod.search([('name', '=', res.name)])
if ready_product:
if not len(res.product_id):
res.product_id += ready_product
else:
res.product_id += prod.create({
'name': res.name,
'price': res.year_price,
'image_1920': res.package_image
})
return res


Expand Down
File renamed without changes
Binary file added saas_apps/static/src/img/user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 4 additions & 6 deletions saas_apps/views/calculator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
<t t-if="app.application">
<div class="col-12 col-sm-6 col-lg-4 shadow p-3 bg-white rounded price-window text-truncate transition app">
<div class="app-icon">
<img t-if="app.icon_path"
t-att-src="to_text(app.icon_path)"
style="max-width: 40px;max-height: 40px;"/>
<img t-att-src="'data:image/png;base64,%s' % to_text(app.app_image)"
style="max-width: 40px;max-height: 40px;"/>
</div>
<div class="app-data">
<div><t t-esc="app.module_name"/></div>
Expand Down Expand Up @@ -65,9 +64,8 @@
<t t-foreach="packages" t-as="package">
<div class="col-12 col-sm-6 col-lg-4 shadow p-3 bg-white rounded price-window text-truncate transition app package">
<div class="app-icon">
<img t-if="package.icon_path"
t-att-src="to_text(package.icon_path)"
style="max-width: 40px;max-height: 40px;"/>
<img t-att-src="'data:image/png;base64,%s' % to_text(package.package_image)"
style="max-width: 40px;max-height: 40px;"/>
</div>
<div class="app-data">
<div><t t-esc="package.name"/></div>
Expand Down
24 changes: 24 additions & 0 deletions saas_apps/views/manage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,33 @@
<xpath expr="//form/sheet/group" position="inside">
<field name="set_as_base"/>
<field name="set_as_package"/>
<field attrs="{'invisible':[('set_as_package','=',False)]}" name="package_image" widget="image" class="oe_left oe_avatar"/>
<field attrs="{'invisible':[('set_as_package','=',False)]}" name="month_price"/>
<field attrs="{'invisible':[('set_as_package','=',False)]}" name="year_price"/>
</xpath>
</field>
</record>

<record id="saas_line_form_view" model="ir.ui.view">
<field name="name">saas.line.form.view</field>
<field name="model">saas.line</field>
<field name="arch" type="xml">
<form>
<sheet>
<field name="app_image" widget="image" class="oe_avatar o_field_image"/>
<group>
<field name="module_name"/>
<field name="allow_to_sell"/>
<field name="month_price" class="oe_inline"
widget='monetary'/>
<field name="year_price" class="oe_inline"
widget='monetary'/>
<field name="currency_id" invisible="1"/>
<field name="dependencies"/>
<field name="product_id"/>
</group>
</sheet>
</form>
</field>
</record>
</odoo>

0 comments on commit 1a757b0

Please sign in to comment.