summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-06-07 13:58:24 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-06-07 13:58:24 +0700
commitdb7481a490b87e3a1768112395bf096b93969562 (patch)
tree4b62a1028b3db4748245a91a033817302deb0dff
parent06a4478d69975b8a6eb3d228fa88708448b40a0e (diff)
Add promotion program keyword and api homepage promotion
-rw-r--r--indoteknik_api/controllers/api_v1/promotion.py66
-rwxr-xr-xindoteknik_custom/__manifest__.py1
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/promotion_program.py9
-rw-r--r--indoteknik_custom/models/promotion_program_keyword.py8
-rw-r--r--indoteknik_custom/models/promotion_program_line.py3
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv3
-rw-r--r--indoteknik_custom/views/promotion_program.xml10
-rw-r--r--indoteknik_custom/views/promotion_program_free_item.xml1
-rw-r--r--indoteknik_custom/views/promotion_program_keyword.xml44
-rw-r--r--indoteknik_custom/views/promotion_program_line.xml1
11 files changed, 136 insertions, 11 deletions
diff --git a/indoteknik_api/controllers/api_v1/promotion.py b/indoteknik_api/controllers/api_v1/promotion.py
index b137fe2e..5ee2acb1 100644
--- a/indoteknik_api/controllers/api_v1/promotion.py
+++ b/indoteknik_api/controllers/api_v1/promotion.py
@@ -1,7 +1,7 @@
from .. import controller
from odoo import http
from odoo.http import request
-import ast
+from datetime import datetime
class Promotion(controller.Controller):
@@ -26,4 +26,66 @@ class Promotion(controller.Controller):
}
return self.response(data)
- \ No newline at end of file
+
+ @http.route(prefix + 'promotion/home', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def v1_get_promotion_home(self):
+ current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+ programs = request.env['promotion.program'].search([
+ ('start_time', '<=', current_time),
+ ('end_time', '>=', current_time),
+ ])
+ if not programs:
+ return self.response(None)
+
+ data = []
+ for program in programs:
+ data_program = {
+ 'id': program.id,
+ 'name': program.name,
+ 'banner': request.env['ir.attachment'].api_image('promotion.program', 'banner', program.id),
+ 'icon': request.env['ir.attachment'].api_image('promotion.program', 'icon', program.id)
+ }
+ data.append(data_program)
+
+ return self.response(data)
+
+ @http.route(prefix + 'promotion/home/<id>', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def v1_get_promotion_home_detail(self, id):
+ program_lines = request.env['promotion.program.line'].search([
+ ('display_on_homepage', '=', True),
+ ('promotion_type', '=', 'specific_product'),
+ ('program_id', '=', int(id))
+ ])
+ pricelist = self.user_pricelist()
+ data = []
+ for line in program_lines:
+ product = request.env['product.product'].v2_api_single_response(line.product_id, pricelist=pricelist)
+ product_template = line.product_id.product_tmpl_id
+
+ product.update({
+ 'id': product['parent']['id'],
+ 'image': product['parent']['image'],
+ 'name': product['parent']['name'],
+ 'variant_total': len(product_template.product_variant_ids),
+ 'lowest_price': product['price'],
+ 'stock_total': product['stock'],
+ 'icon': {
+ 'top': request.env['ir.attachment'].api_image('promotion.program', 'icon_top', line.program_id.id),
+ 'bottom': request.env['ir.attachment'].api_image('promotion.program', 'icon_bottom', line.program_id.id)
+ }
+ })
+ price = product['lowest_price']['price']
+ if line.discount_type == 'percentage':
+ product['lowest_price']['discount_percentage'] = line.discount_amount
+ product['lowest_price']['price_discount'] = price - (price * line.discount_amount / 100)
+ if line.discount_type == 'fixed_price':
+ product['lowest_price']['price_discount'] = line.discount_amount
+ product['lowest_price']['discount_percentage'] = (price - line.discount_amount) / price * 100
+
+ product.pop('parent', None)
+ product.pop('price', None)
+ product.pop('stock', None)
+ data.append(product)
+ return self.response(data) \ No newline at end of file
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index 6386497b..c116ff0c 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -77,6 +77,7 @@
'views/promotion_program.xml',
'views/promotion_program_line.xml',
'views/promotion_program_free_item.xml',
+ 'views/promotion_program_keyword.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 42f011bf..3123d608 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -18,6 +18,7 @@ from . import product_template
from . import promotion_program
from . import promotion_program_line
from . import promotion_program_free_item
+from . import promotion_program_keyword
from . import purchase_order_line
from . import purchase_order
from . import purchase_outstanding
diff --git a/indoteknik_custom/models/promotion_program.py b/indoteknik_custom/models/promotion_program.py
index 7c264b65..bc7f2c49 100644
--- a/indoteknik_custom/models/promotion_program.py
+++ b/indoteknik_custom/models/promotion_program.py
@@ -6,6 +6,9 @@ class PromotionProgram(models.Model):
name = fields.Char(string="Name")
banner = fields.Binary(string="Banner")
+ icon = fields.Binary(string="Icon", help="Image 1:1 ratio")
+ icon_top = fields.Binary(string="Icon Top", help="Icon ini ditampilkan sebagai atribut pada atas gambar di product card pada website")
+ icon_bottom = fields.Binary(string="Icon Bottom", help="Icon ini ditampilkan sebagai atribut pada bawah gambar di product card pada website")
start_time = fields.Datetime(string="Start Time")
end_time = fields.Datetime(string="End Time")
applies_to = fields.Selection(selection=[
@@ -14,6 +17,6 @@ class PromotionProgram(models.Model):
])
program_line = fields.One2many(
comodel_name="promotion.program.line", inverse_name="program_id", string="Program Line")
-
- # TODO: Add search many2many tags input untuk ditampilkan ketika ada query search
- # TODO: Add ribbon atas, ribbon bawah, image 1:1 \ No newline at end of file
+ keywords = fields.One2many(
+ comodel_name="promotion.program.keyword", inverse_name="program_id", string="Keywords"
+ )
diff --git a/indoteknik_custom/models/promotion_program_keyword.py b/indoteknik_custom/models/promotion_program_keyword.py
new file mode 100644
index 00000000..79b938e2
--- /dev/null
+++ b/indoteknik_custom/models/promotion_program_keyword.py
@@ -0,0 +1,8 @@
+from odoo import fields, models
+
+
+class PromotionProgramKeyword(models.Model):
+ _name = "promotion.program.keyword"
+
+ name = fields.Char(string="Keyword")
+ program_id = fields.Many2one(comodel_name="promotion.program")
diff --git a/indoteknik_custom/models/promotion_program_line.py b/indoteknik_custom/models/promotion_program_line.py
index 3d314f76..a8ee2c43 100644
--- a/indoteknik_custom/models/promotion_program_line.py
+++ b/indoteknik_custom/models/promotion_program_line.py
@@ -68,6 +68,3 @@ class PromotionProgramLine(models.Model):
data = {'product_id': product.id,
'qty': 1, 'line_id': program_line.id}
line_free_item.create(data)
-
- # TODO: Add show on homepage boolean untuk priority specific product
- # TODO: Discount loading otomatis membuat line dengan product_id yang sama dengan parent
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 3b35615f..f782046d 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -51,4 +51,5 @@ access_rajaongkir_kurir,access.rajaongkir.kurir,model_rajaongkir_kurir,,1,1,1,1
access_brand_vendor,access.brand.vendor,model_brand_vendor,,1,1,1,1
access_promotion_program,access.promotion.program,model_promotion_program,,1,1,1,1
access_promotion_program_line,access.promotion.program.line,model_promotion_program_line,,1,1,1,1
-access_promotion_program_free_item,access.promotion.program.free_item,model_promotion_program_free_item,,1,1,1,1 \ No newline at end of file
+access_promotion_program_free_item,access.promotion.program.free_item,model_promotion_program_free_item,,1,1,1,1
+access_promotion_program_keyword,access.promotion.program.keyword,model_promotion_program_keyword,,1,1,1,1 \ No newline at end of file
diff --git a/indoteknik_custom/views/promotion_program.xml b/indoteknik_custom/views/promotion_program.xml
index e309cc29..5dff80e6 100644
--- a/indoteknik_custom/views/promotion_program.xml
+++ b/indoteknik_custom/views/promotion_program.xml
@@ -21,6 +21,7 @@
<group>
<group>
<field name="name" />
+ <field name="keywords" widget="many2many_tags" />
<field name="banner" widget="image" height="160" />
</group>
<group>
@@ -33,6 +34,15 @@
<page string="Program Lines" name="program_lines">
<field name="program_line" />
</page>
+ <page string="Image Properties" name="image_properties">
+ <group>
+ <group>
+ <field name="icon" widget="image" height="120" />
+ <field name="icon_top" widget="image" height="80" />
+ <field name="icon_bottom" widget="image" height="80" />
+ </group>
+ </group>
+ </page>
</notebook>
</sheet>
</form>
diff --git a/indoteknik_custom/views/promotion_program_free_item.xml b/indoteknik_custom/views/promotion_program_free_item.xml
index c17a752d..52d421fe 100644
--- a/indoteknik_custom/views/promotion_program_free_item.xml
+++ b/indoteknik_custom/views/promotion_program_free_item.xml
@@ -18,7 +18,6 @@
<sheet>
<group>
<group>
- <field name="line_id" invisible="1" />
<field name="product_id" />
<field name="qty" />
</group>
diff --git a/indoteknik_custom/views/promotion_program_keyword.xml b/indoteknik_custom/views/promotion_program_keyword.xml
new file mode 100644
index 00000000..fd279665
--- /dev/null
+++ b/indoteknik_custom/views/promotion_program_keyword.xml
@@ -0,0 +1,44 @@
+<odoo>
+ <record id="promotion_program_keyword_tree" model="ir.ui.view">
+ <field name="name">Promotion Program Keyword Tree</field>
+ <field name="model">promotion.program.keyword</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="name" />
+ <field name="program_id" />
+ </tree>
+ </field>
+ </record>
+
+ <record id="promotion_program_keyword_form" model="ir.ui.view">
+ <field name="name">Promotion Program Keyword Form</field>
+ <field name="model">promotion.program.keyword</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet>
+ <group>
+ <group>
+ <field name="name" />
+ <field name="program_id" />
+ </group>
+ </group>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="promotion_program_keyword_action" model="ir.actions.act_window">
+ <field name="name">Promotion Program Keyword</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">promotion.program.keyword</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem
+ id="menu_promotion_program_keyword"
+ name="Program Keyword"
+ parent="indoteknik_custom.menu_promotion_program_parent"
+ sequence="4"
+ action="promotion_program_keyword_action"
+ />
+</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/promotion_program_line.xml b/indoteknik_custom/views/promotion_program_line.xml
index 60334d6b..bb625a8f 100644
--- a/indoteknik_custom/views/promotion_program_line.xml
+++ b/indoteknik_custom/views/promotion_program_line.xml
@@ -23,7 +23,6 @@
<sheet>
<group>
<group>
- <field name="program_id" invisible="1" />
<field name="name" />
<field name="promotion_type"/>
<field name="product_id" />