summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-05-31 17:14:34 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-05-31 17:14:34 +0700
commit06a4478d69975b8a6eb3d228fa88708448b40a0e (patch)
treed1bb5115c61b973ad77ea0d975da29ce24c59bc0
parent6cb1fc1a1cd0c8091c32dfcd19ebc58793873d25 (diff)
Promotion program feature
-rwxr-xr-xindoteknik_custom/__manifest__.py3
-rwxr-xr-xindoteknik_custom/models/__init__.py3
-rw-r--r--indoteknik_custom/models/promotion_program.py19
-rw-r--r--indoteknik_custom/models/promotion_program_free_item.py12
-rw-r--r--indoteknik_custom/models/promotion_program_line.py73
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv5
-rw-r--r--indoteknik_custom/views/promotion_program.xml63
-rw-r--r--indoteknik_custom/views/promotion_program_free_item.xml45
-rw-r--r--indoteknik_custom/views/promotion_program_line.xml86
9 files changed, 308 insertions, 1 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index c52e27b7..6386497b 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -74,6 +74,9 @@
'views/procurement_monitoring_detail.xml',
'views/product_product.xml',
'views/brand_vendor.xml',
+ 'views/promotion_program.xml',
+ 'views/promotion_program_line.xml',
+ 'views/promotion_program_free_item.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 18f46d34..42f011bf 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -15,6 +15,9 @@ from . import product_pricelist
from . import product_public_category
from . import product_spec
from . import product_template
+from . import promotion_program
+from . import promotion_program_line
+from . import promotion_program_free_item
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
new file mode 100644
index 00000000..7c264b65
--- /dev/null
+++ b/indoteknik_custom/models/promotion_program.py
@@ -0,0 +1,19 @@
+from odoo import fields, models
+
+
+class PromotionProgram(models.Model):
+ _name = "promotion.program"
+
+ name = fields.Char(string="Name")
+ banner = fields.Binary(string="Banner")
+ start_time = fields.Datetime(string="Start Time")
+ end_time = fields.Datetime(string="End Time")
+ applies_to = fields.Selection(selection=[
+ ("all_user", "All User"),
+ ("login_user", "Login User")
+ ])
+ 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
diff --git a/indoteknik_custom/models/promotion_program_free_item.py b/indoteknik_custom/models/promotion_program_free_item.py
new file mode 100644
index 00000000..ddd97765
--- /dev/null
+++ b/indoteknik_custom/models/promotion_program_free_item.py
@@ -0,0 +1,12 @@
+from odoo import fields, models
+
+
+class PromotionProgramFreeItem(models.Model):
+ _name = "promotion.program.free_item"
+ _rec_name = "product_id"
+
+ product_id = fields.Many2one(
+ comodel_name="product.product", string="Product Variant")
+ qty = fields.Integer(string="Qty")
+ line_id = fields.Many2one(
+ comodel_name="promotion.program.line", string="Program Line")
diff --git a/indoteknik_custom/models/promotion_program_line.py b/indoteknik_custom/models/promotion_program_line.py
new file mode 100644
index 00000000..3d314f76
--- /dev/null
+++ b/indoteknik_custom/models/promotion_program_line.py
@@ -0,0 +1,73 @@
+from odoo import fields, models, api
+
+
+class PromotionProgramLine(models.Model):
+ _name = "promotion.program.line"
+
+ name = fields.Char(string="Name")
+ image = fields.Binary(string="Image")
+ product_id = fields.Many2one(
+ comodel_name="product.product", string="Product Variant")
+ program_id = fields.Many2one(
+ comodel_name="promotion.program", string="Program")
+ discount_type = fields.Selection(selection=[
+ ("percentage", "Percentage"),
+ ("fixed_price", "Fixed Price"),
+ ], string="Discount Type")
+ discount_amount = fields.Float(string="Discount Amount")
+ promotion_type = fields.Selection(selection=[
+ ("specific_product", "Specific Product"),
+ ("bundling", "Bundling"),
+ ("discount_loading", "Discount Loading"),
+ ("merchandise", "Merchandise")
+ ], string="Promotion Type")
+ minimum_purchase_qty = fields.Integer(
+ string="Minimum Purchase Qty", help="Minimum Qty to applied discount loading")
+ applies_multiply = fields.Boolean(
+ string="Applies Multiply", help="Is applies multiply")
+ limit_qty = fields.Integer(
+ string="Limit Qty", help="Limit Qty product in promotion")
+ limit_qty_user = fields.Integer(
+ string="Limit Qty / User", help="Limit Qty per User")
+ limit_qty_transaction = fields.Integer(
+ string="Limit Qty / Transaction", help="Limit Qty per Transaction")
+ line_free_item = fields.One2many(
+ comodel_name="promotion.program.free_item", inverse_name="line_id", string="Line Free Item")
+ display_on_homepage = fields.Boolean(string="Display on Homepage")
+
+ @api.onchange('product_id')
+ def _onchange_product_id(self):
+ if self.product_id and not self.name:
+ self.name = self.product_id.display_name
+ self._discount_loading_auto()
+
+ @api.onchange('promotion_type')
+ def onchange_promotion_type(self):
+ self._discount_loading_auto()
+
+ def _discount_loading_auto(self):
+ program_line = self
+ product = program_line.product_id
+ promotion_type = program_line.promotion_type
+
+ if promotion_type != 'discount_loading' or not product:
+ return
+
+ line = self.browse(self.ids)
+ line.product_id = self.product_id.id
+ line.promotion_type = self.promotion_type
+
+ product_added = False
+ line_free_item = program_line.line_free_item
+ for line in line_free_item:
+ if line.product_id.id == product.id:
+ product_added = True
+ continue
+ line.unlink()
+ if not product_added:
+ 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 39504393..3b35615f 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -48,4 +48,7 @@ access_apache_solr,access.apache.solr,model_apache_solr,,1,1,1,1
access_group_partner,access.group.partner,model_group_partner,,1,1,1,1
access_procurement_monitoring_detail,access.procurement.monitoring.detail,model_procurement_monitoring_detail,,1,1,1,1
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 \ No newline at end of file
+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
diff --git a/indoteknik_custom/views/promotion_program.xml b/indoteknik_custom/views/promotion_program.xml
new file mode 100644
index 00000000..e309cc29
--- /dev/null
+++ b/indoteknik_custom/views/promotion_program.xml
@@ -0,0 +1,63 @@
+<odoo>
+ <record id="promotion_program_tree" model="ir.ui.view">
+ <field name="name">Promotion Program Tree</field>
+ <field name="model">promotion.program</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="name" />
+ <field name="start_time" />
+ <field name="end_time" />
+ <field name="applies_to" />
+ </tree>
+ </field>
+ </record>
+
+ <record id="promotion_program_form" model="ir.ui.view">
+ <field name="name">Promotion Program Form</field>
+ <field name="model">promotion.program</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet>
+ <group>
+ <group>
+ <field name="name" />
+ <field name="banner" widget="image" height="160" />
+ </group>
+ <group>
+ <field name="start_time" />
+ <field name="end_time" />
+ <field name="applies_to" />
+ </group>
+ </group>
+ <notebook>
+ <page string="Program Lines" name="program_lines">
+ <field name="program_line" />
+ </page>
+ </notebook>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="promotion_program_action" model="ir.actions.act_window">
+ <field name="name">Promotion Program</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">promotion.program</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem
+ id="menu_promotion_program_parent"
+ name="Promotion Program"
+ parent="website.menu_website_configuration"
+ sequence="7"
+ />
+
+ <menuitem
+ id="menu_promotion_program"
+ name="Program"
+ parent="indoteknik_custom.menu_promotion_program_parent"
+ sequence="1"
+ action="promotion_program_action"
+ />
+</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/promotion_program_free_item.xml b/indoteknik_custom/views/promotion_program_free_item.xml
new file mode 100644
index 00000000..c17a752d
--- /dev/null
+++ b/indoteknik_custom/views/promotion_program_free_item.xml
@@ -0,0 +1,45 @@
+<odoo>
+ <record id="promotion_program_free_item_tree" model="ir.ui.view">
+ <field name="name">Promotion Program Free Item Tree</field>
+ <field name="model">promotion.program.free_item</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="product_id" />
+ <field name="qty" />
+ </tree>
+ </field>
+ </record>
+
+ <record id="promotion_program_free_item_form" model="ir.ui.view">
+ <field name="name">Promotion Program Free Item Form</field>
+ <field name="model">promotion.program.free_item</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet>
+ <group>
+ <group>
+ <field name="line_id" invisible="1" />
+ <field name="product_id" />
+ <field name="qty" />
+ </group>
+ </group>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="promotion_program_free_item_action" model="ir.actions.act_window">
+ <field name="name">Promotion Program Free Item</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">promotion.program.free_item</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem
+ id="menu_promotion_program_free_item"
+ name="Program Free Item"
+ parent="indoteknik_custom.menu_promotion_program_parent"
+ sequence="3"
+ action="promotion_program_free_item_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
new file mode 100644
index 00000000..60334d6b
--- /dev/null
+++ b/indoteknik_custom/views/promotion_program_line.xml
@@ -0,0 +1,86 @@
+<odoo>
+ <record id="promotion_program_line_tree" model="ir.ui.view">
+ <field name="name">Promotion Program Line Tree</field>
+ <field name="model">promotion.program.line</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="name" />
+ <field name="promotion_type" />
+ <field name="limit_qty" />
+ <field name="limit_qty_user" />
+ <field name="limit_qty_transaction" />
+ <field name="line_free_item" />
+ <field name="display_on_homepage" />
+ </tree>
+ </field>
+ </record>
+
+ <record id="promotion_program_line_form" model="ir.ui.view">
+ <field name="name">Promotion Program Line Form</field>
+ <field name="model">promotion.program.line</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet>
+ <group>
+ <group>
+ <field name="program_id" invisible="1" />
+ <field name="name" />
+ <field name="promotion_type"/>
+ <field name="product_id" />
+ <field name="image" widget="image" height="160" />
+ </group>
+ <group>
+ <field name="limit_qty" />
+ <field name="limit_qty_user" />
+ <field name="limit_qty_transaction" />
+ <field
+ name="discount_type"
+ attrs="{'invisible': [('promotion_type', '!=', 'specific_product')]}"
+ />
+ <field
+ name="discount_amount"
+ attrs="{'invisible': [('promotion_type', '!=', 'specific_product')]}"
+ />
+ <field
+ name="minimum_purchase_qty"
+ attrs="{'invisible': [('promotion_type', 'not in', ['discount_loading', 'bundling', 'merchandise'])]}"
+ />
+ <field
+ name="applies_multiply"
+ attrs="{'invisible': [('promotion_type', 'not in', ['discount_loading', 'bundling', 'merchandise'])]}"
+ />
+ <field
+ name="display_on_homepage"
+ attrs="{'invisible': [('promotion_type', '!=', 'specific_product')]}"
+ />
+ </group>
+ </group>
+ <notebook>
+ <page
+ string="Line Free Item"
+ name="line_free_items"
+ attrs="{'invisible': [('promotion_type', '=', 'specific_product')]}"
+ >
+ <field name="line_free_item" />
+ </page>
+ </notebook>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="promotion_program_line_action" model="ir.actions.act_window">
+ <field name="name">Promotion Program Line</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">promotion.program.line</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem
+ id="menu_promotion_program_line"
+ name="Program Line"
+ parent="indoteknik_custom.menu_promotion_program_parent"
+ sequence="2"
+ action="promotion_program_line_action"
+ />
+</odoo> \ No newline at end of file