diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-12-21 18:48:38 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-12-21 18:48:38 +0700 |
| commit | db2f280683b29ac5d32158f3fab0f3df671935e9 (patch) | |
| tree | 83624efbd3e7abc705c8d987994cf2c1b7612284 | |
| parent | a08dfcb0d1f99a99686a8fba948fae7d4eca374e (diff) | |
add website categories homepage module
| -rw-r--r-- | indoteknik_api/controllers/api_v1/category.py | 35 | ||||
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/website_categories_homepage.py | 14 | ||||
| -rwxr-xr-x | indoteknik_custom/models/x_manufactures.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 3 | ||||
| -rw-r--r-- | indoteknik_custom/views/website_categories_homepage.xml | 52 |
7 files changed, 105 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/api_v1/category.py b/indoteknik_api/controllers/api_v1/category.py index 88296d58..36e67e01 100644 --- a/indoteknik_api/controllers/api_v1/category.py +++ b/indoteknik_api/controllers/api_v1/category.py @@ -6,7 +6,40 @@ import ast class Category(controller.Controller): prefix = '/api/v1/' - + + @http.route(prefix + 'categories_homepage', auth='public', methods=['GET', 'OPTIONS']) + def get_categories_homepage(self, **kw): + if not self.authenticate(): + return self.response(code=401, description='Unauthorized') + base_url = request.env['ir.config_parameter'].get_param('web.base.url') + query = [('status', '=', 'tayang')] + categories = request.env['website.categories.homepage'].search(query, order='sequence') + data = [] + for category in categories: + query_product = [ + ('active', '=', True), + ('type', '=', 'product'), + ('product_rating', '>', 0), + ('public_categ_ids', 'child_of', [category.category_id.id]) + ] + products = request.env['product.template'].search(query_product, order='product_rating desc', limit=12) + # product_brands = [] + brands = request.env['x_manufactures'].search([ + ('product_tmpl_ids.public_categ_ids', 'child_of', [category.category_id.id]) + ], limit=8) + + data.append({ + 'id': category.id, + 'sequence': category.sequence, + 'category_id': category.category_id.id, + 'name': category.category_id.name, + 'image': base_url + 'api/image/website.categories.homepage/image/' + str(category.id) if category.image else '', + 'url': category.url, + 'brands': [y.x_name for y in brands], + 'products': [request.env['product.template'].api_single_response(x) for x in products] + }) + return self.response(data) + @http.route(prefix + 'category/page/<page>', auth='public', methods=['GET']) def get_category(self, **kw): if not self.authenticate(): diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 4c42bd31..633d407b 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -47,6 +47,7 @@ 'views/account_move.xml', 'views/dunning_run.xml', 'views/website_brand_homepage.xml', + 'views/website_categories_homepage.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 17ad7b8d..dc85ce96 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -34,3 +34,4 @@ from . import website_user_cart from . import website_user_wishlist from . import website_brand_homepage from . import mail_mail +from . import website_categories_homepage diff --git a/indoteknik_custom/models/website_categories_homepage.py b/indoteknik_custom/models/website_categories_homepage.py new file mode 100644 index 00000000..612dd8a0 --- /dev/null +++ b/indoteknik_custom/models/website_categories_homepage.py @@ -0,0 +1,14 @@ +from odoo import fields, models + + +class WebsiteCategoriesHomepage(models.Model): + _name = 'website.categories.homepage' + + category_id = fields.Many2one('product.public.category', string='Category', help='table ecommerce category') + image = fields.Binary(string='Image') + url = fields.Char(string='URL') + sequence = fields.Integer(string='Sequence') + status = fields.Selection([ + ('tayang', 'Tayang'), + ('tidak_tayang', 'Tidak Tayang') + ], string='Status') diff --git a/indoteknik_custom/models/x_manufactures.py b/indoteknik_custom/models/x_manufactures.py index dae37668..24b64c14 100755 --- a/indoteknik_custom/models/x_manufactures.py +++ b/indoteknik_custom/models/x_manufactures.py @@ -35,6 +35,7 @@ class XManufactures(models.Model): ('sparepart', 'Spare Part') ], string="Jenis Produk") x_short_desc = fields.Text(string="Short Description") + product_tmpl_ids = fields.One2many('product.template', 'x_manufacture', string='Product Templates') @api.onchange('x_name','image_promotion_1','image_promotion_2') def update_solr_flag(self): diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 50990e1f..295da4ee 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -16,4 +16,5 @@ access_dunning_run,access.dunning.run,model_dunning_run,,1,1,1,1 access_dunning_run_line,access.dunning.run.line,model_dunning_run_line,,1,1,1,1 access_website_user_cart,access.website.user.cart,model_website_user_cart,,1,1,1,1 access_website_user_wishlist,access.website.user.wishlist,model_website_user_wishlist,,1,1,1,1 -access_website_brand_homepage,access.website.brand.homepage,model_website_brand_homepage,,1,1,1,1
\ No newline at end of file +access_website_brand_homepage,access.website.brand.homepage,model_website_brand_homepage,,1,1,1,1 +access_website_categories_homepage,access.website.categories.homepage,model_website_categories_homepage,,1,1,1,1
\ No newline at end of file diff --git a/indoteknik_custom/views/website_categories_homepage.xml b/indoteknik_custom/views/website_categories_homepage.xml new file mode 100644 index 00000000..22424280 --- /dev/null +++ b/indoteknik_custom/views/website_categories_homepage.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <data> + <record id="website_categories_homepage_action" model="ir.actions.act_window"> + <field name="name">Website Categories Homepage</field> + <field name="res_model">website.categories.homepage</field> + <field name="view_mode">tree,form</field> + </record> + + <record id="website_categories_homepage_tree" model="ir.ui.view"> + <field name="name">Website Categories Homepage</field> + <field name="model">website.categories.homepage</field> + <field name="arch" type="xml"> + <tree> + <field name="id"/> + <field name="sequence"/> + <field name="category_id"/> + <field name="url"/> + <field name="status"/> + </tree> + </field> + </record> + + <record id="website_categories_homepage_form" model="ir.ui.view"> + <field name="name">Website Categories Homepage</field> + <field name="model">website.categories.homepage</field> + <field name="arch" type="xml"> + <form> + <sheet> + <group> + <group> + <field name="sequence"/> + <field name="category_id"/> + <field name="image"/> + <field name="url"/> + <field name="status"/> + </group> + </group> + </sheet> + </form> + </field> + </record> + + <menuitem + id="website_categories_homepage" + name="Website Categories Homepage" + parent="website_sale.menu_orders" + sequence="1" + action="website_categories_homepage_action" + /> + </data> +</odoo>
\ No newline at end of file |
