Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ssi_product_website] 14.0.1.0.0 #8

Merged
merged 26 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f790a59
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 7, 2023
45e05e8
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 17, 2023
f5827db
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 17, 2023
161410e
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 17, 2023
2571784
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 17, 2023
2db53b5
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
9a14748
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
493b857
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
ad24355
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
fe4ba51
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
5ba2945
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
70861f1
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
111ac4b
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
1c96b84
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
f90a811
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
a98f22d
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
7fb7a25
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 22, 2023
649a6c9
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 28, 2023
2ff258e
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 28, 2023
d81d941
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 28, 2023
f7aca30
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 28, 2023
cc9c0d5
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 28, 2023
80dd17f
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 28, 2023
39eb416
[ssi_product_website] 14.0.1.0.0
Miftahussalam Aug 28, 2023
542ce94
[ssi_product_website] 14.0.1.0.0
Miftahussalam Sep 15, 2023
6c37ce4
[UPD] ssi_product_website
Miftahussalam Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions ssi_product_website/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3

=================================
Product App - website Integration
=================================


Installation
============

To install this module, you need to:

1. Clone the branch 14.0 of the repository https://github.com/open-synergy/ssi-product-attribute
2. Add the path to this repository in your configuration (addons-path)
3. Update the module list
4. Go to menu *Apps -> Apps -> Main Apps*
5. Search For *Product App - website Integration*
6. Install the module

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/open-synergy/ssi-product-attribute/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed
and welcomed feedback.


Credits
=======

Contributors
------------

* Miftahussalam <[email protected]>

Maintainer
----------

.. image:: https://simetri-sinergi.id/logo.png
:alt: PT. Simetri Sinergi Indonesia
:target: https://simetri-sinergi.id.com

This module is maintained by the PT. Simetri Sinergi Indonesia.
8 changes: 8 additions & 0 deletions ssi_product_website/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import (
controllers,
models,
)
24 changes: 24 additions & 0 deletions ssi_product_website/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "Product App - website Integration",
"version": "14.0.1.0.0",
"website": "https://simetri-sinergi.id",
"author": "PT. Simetri Sinergi Indonesia, OpenSynergy Indonesia",
"license": "LGPL-3",
"installable": True,
"application": False,
"auto_install": True,
"depends": [
"ssi_product",
"website",
],
"data": [
"security/ir.model.access.csv",
"data/data.xml",
"views/templates.xml",
"views/product_template_views.xml",
],
"demo": [],
}
7 changes: 7 additions & 0 deletions ssi_product_website/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import (
main,
)
211 changes: 211 additions & 0 deletions ssi_product_website/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import json
import logging
from datetime import datetime
from werkzeug.exceptions import Forbidden, NotFound

from odoo import fields, http, SUPERUSER_ID, tools, _
from odoo.http import request
from odoo.addons.base.models.ir_qweb_fields import nl2br
from odoo.addons.http_routing.models.ir_http import slug
from odoo.addons.payment.controllers.portal import PaymentProcessing
from odoo.addons.website.controllers.main import QueryURL
from odoo.addons.website.models.ir_http import sitemap_qs2dom
from odoo.exceptions import ValidationError
from odoo.addons.portal.controllers.portal import _build_url_w_params
from odoo.addons.website.controllers.main import Website
from odoo.addons.website_form.controllers.main import WebsiteForm
from odoo.osv import expression
_logger = logging.getLogger(__name__)


class TableCompute(object):

def __init__(self):
self.table = {}

def _check_place(self, posx, posy, sizex, sizey, ppr):
res = True
for y in range(sizey):
for x in range(sizex):
if posx + x >= ppr:
res = False
break
row = self.table.setdefault(posy + y, {})
if row.setdefault(posx + x) is not None:
res = False
break
for x in range(ppr):
self.table[posy + y].setdefault(x, None)
return res

def process(self, products, ppg=20, ppr=4):
# Compute products positions on the grid
minpos = 0
index = 0
maxy = 0
x = 0
for p in products:
x = min(1, ppr)
y = min(1, ppr)
if index >= ppg:
x = y = 1

pos = minpos
while not self._check_place(pos % ppr, pos // ppr, x, y, ppr):
pos += 1
# if 21st products (index 20) and the last line is full (ppr products in it), break
# (pos + 1.0) / ppr is the line where the product would be inserted
# maxy is the number of existing lines
# + 1.0 is because pos begins at 0, thus pos 20 is actually the 21st block
# and to force python to not round the division operation
if index >= ppg and ((pos + 1.0) // ppr) > maxy:
break

if x == 1 and y == 1: # simple heuristic for CPU optimization
minpos = pos // ppr

for y2 in range(y):
for x2 in range(x):
self.table[(pos // ppr) + y2][(pos % ppr) + x2] = False
self.table[pos // ppr][pos % ppr] = {
'product': p, 'x': x, 'y': y,
}
if index <= ppg:
maxy = max(maxy, y + (pos // ppr))
index += 1

# Format table according to HTML needs
rows = sorted(self.table.items())
rows = [r[1] for r in rows]
for col in range(len(rows)):
cols = sorted(rows[col].items())
x += len(cols)
rows[col] = [r[1] for r in cols if r[1]]

return rows


class ProductWebsite(http.Controller):

def _get_search_order(self, post):
# OrderBy will be parsed in orm and so no direct sql injection
# id is added to be sure that order is a unique sort key
order = post.get('order') or 'name ASC'
return order

def _get_search_domain(self, search, search_in_description=True):
domains = [[("product_catalog", "=", True)]]
if search:
for srch in search.split(" "):
subdomains = [
[('name', 'ilike', srch)],
[('product_variant_ids.default_code', 'ilike', srch)]
]
if search_in_description:
subdomains.append([('description', 'ilike', srch)])
domains.append(expression.OR(subdomains))

return expression.AND(domains)

def sitemap_product_catalog(env, rule, qs):
if not qs or qs.lower() in '/product_catalog':
yield {'loc': '/product_catalog'}

@http.route([
'''/product_catalog''',
'''/product_catalog/page/<int:page>''',
], type='http', auth="public", website=True, sitemap=sitemap_product_catalog)
def product_catalog(self, page=0, search='', ppg=False, **post):
add_qty = int(post.get('add_qty', 1))

if ppg:
try:
ppg = int(ppg)
post['ppg'] = ppg
except ValueError:
ppg = False
if not ppg:
ppg = 20

ppr = 4

attrib_list = request.httprequest.args.getlist('attrib')
attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v]
attributes_ids = {v[0] for v in attrib_values}

domain = self._get_search_domain(search)

keep = QueryURL('/product_catalog', search=search,
order=post.get('order'))

request.context = dict(request.context, partner=request.env.user.partner_id)

url = "/product_catalog"
if search:
post["search"] = search

Product = request.env['product.template'].with_context(bin_size=True)

search_product = Product.search(domain, order=self._get_search_order(post))

product_count = len(search_product)
pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post)
offset = pager['offset']
products = search_product[offset: offset + ppg]

ProductAttribute = request.env['product.attribute']
if products:
# get all products without limit
attributes = ProductAttribute.search([('product_tmpl_ids', 'in', search_product.ids)])
else:
attributes = ProductAttribute.browse(attributes_ids)

layout_mode = 'grid'

values = {
'search': search,
'order': post.get('order', ''),
'pager': pager,
'add_qty': add_qty,
'products': products,
'search_count': product_count, # common for all searchbox
'bins': TableCompute().process(products, ppg, ppr),
'ppg': ppg,
'ppr': ppr,
'attributes': attributes,
'keep': keep,
'layout_mode': layout_mode,
}
return request.render("ssi_product_website.products", values)

@http.route(['/product_catalog/<model("product.template"):product>'], type='http', auth="public", website=True, sitemap=True)
def product(self, product, search='', **kwargs):
if not product.product_catalog:
raise NotFound()

return request.render("ssi_product_website.product", self._prepare_product_values(product, search, **kwargs))

def _prepare_product_values(self, product, search, **kwargs):
add_qty = int(kwargs.get('add_qty', 1))

product_context = dict(request.env.context, quantity=add_qty,
active_id=product.id,
partner=request.env.user.partner_id)

keep = QueryURL('/product_catalog', search=search)

# Needed to trigger the recently viewed product rpc
view_track = request.website.viewref("ssi_product_website.product").track

return {
'search': search,
'keep': keep,
'main_object': product,
'product': product,
'add_qty': add_qty,
'view_track': view_track,
}
13 changes: 13 additions & 0 deletions ssi_product_website/data/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record id="menu_product_catalog" model="website.menu">
<field name="name">Product Catalog</field>
<field name="url">/product_catalog</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">25</field>
</record>

</data>
</odoo>
7 changes: 7 additions & 0 deletions ssi_product_website/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import (
product_template,
)
Loading
Loading