summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-02-27 09:14:34 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-02-27 09:14:34 +0700
commitac4f111ba1605fe3891582b7fc396e740130791d (patch)
treed204380870d16a3e523df07b8ba0f907c0184904
parent391fe72c5d9d92d49a09fc971a6c86a39a6e22d1 (diff)
parentdb98ba79a92ca11df958cce513bc320110764434 (diff)
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
-rw-r--r--indoteknik_api/controllers/api_v1/cart.py4
-rw-r--r--indoteknik_custom/models/promotion/promotion_monitoring.py30
-rw-r--r--indoteknik_custom/models/promotion/promotion_program_line.py3
-rw-r--r--indoteknik_custom/models/solr/promotion_program_line.py12
-rw-r--r--indoteknik_custom/views/apache_solr_queue.xml7
-rw-r--r--indoteknik_custom/views/promotion/promotion_monitoring.xml26
-rw-r--r--indoteknik_custom/views/promotion/promotion_program_line.xml18
7 files changed, 83 insertions, 17 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py
index 5948a277..f472a9b0 100644
--- a/indoteknik_api/controllers/api_v1/cart.py
+++ b/indoteknik_api/controllers/api_v1/cart.py
@@ -44,6 +44,7 @@ class Cart(controller.Controller):
qty = int(kw.get('qty', 0))
source = kw.get('source')
+ qty_append = kw.get('qty_append', False)
is_selected = kw.get('selected', False)
is_selected = is_selected in ('true', True)
@@ -78,6 +79,9 @@ class Cart(controller.Controller):
'product_id': product_id,
'source': source or False
}
+
+ if isinstance(qty_append, str) and qty_append.lower() == "true" and cart:
+ data_to_update['qty'] += cart.qty
if cart:
cart.write(data_to_update)
diff --git a/indoteknik_custom/models/promotion/promotion_monitoring.py b/indoteknik_custom/models/promotion/promotion_monitoring.py
index e5598e40..9df0825d 100644
--- a/indoteknik_custom/models/promotion/promotion_monitoring.py
+++ b/indoteknik_custom/models/promotion/promotion_monitoring.py
@@ -7,23 +7,39 @@ class PromotionMonitoring(models.Model):
_rec_name = "product_id"
product_id = fields.Many2one(comodel_name="product.product", string="Product")
+ manufacture_id = fields.Many2one(comodel_name="x_manufactures", string="Manufacture", related="product_id.x_manufacture")
+ price = fields.Float(string="Price", help="Computed Price di Product Pricelist (Tier 1 New)")
has_promo = fields.Boolean(string="Has Promo")
- count_promo = fields.Integer(string="Count Promo")
+ count_active = fields.Integer(string="Count Active")
+ count_inactive = fields.Integer(string="Count Inactive")
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
+ sql = {
+ 'count_active': "COUNT(CASE WHEN ppl.active = True THEN ppl.id ELSE NULL END)",
+ 'count_inactive': "COUNT(CASE WHEN ppl.active = False THEN ppl.id ELSE NULL END)"
+ }
self.env.cr.execute("""
- CREATE OR REPLACE VIEW %s AS (
+ CREATE OR REPLACE VIEW {table} AS (
SELECT
p.id as id,
p.id as product_id,
- (COUNT(pp.id) > 0) as has_promo,
- COUNT(pp.id) as count_promo
+ ppi.computed_price as price,
+ ({count_active} > 0) as has_promo,
+ {count_active} as count_active,
+ {count_inactive} as count_inactive
FROM product_product p
LEFT JOIN product_template pt ON pt.id = p.product_tmpl_id
- LEFT JOIN promotion_product pp ON p.id = pp.product_id
+ LEFT JOIN promotion_product pp ON pp.product_id = p.id
+ LEFT JOIN promotion_program_line ppl ON ppl.id = pp.program_line_id
+ LEFT JOIN product_pricelist_item ppi ON ppi.product_id = p.id
WHERE p.active = True
AND pt.sale_ok = True
- GROUP BY p.id
+ AND ppi.pricelist_id = 17023
+ GROUP BY p.id, ppi.id
)
- """ % self._table) \ No newline at end of file
+ """.format(
+ table=self._table,
+ count_active=sql['count_active'],
+ count_inactive=sql['count_inactive']
+ )) \ No newline at end of file
diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py
index ce46d2e7..cb231889 100644
--- a/indoteknik_custom/models/promotion/promotion_program_line.py
+++ b/indoteknik_custom/models/promotion/promotion_program_line.py
@@ -30,7 +30,8 @@ class PromotionProgramLine(models.Model):
discount_amount = fields.Float('Discount Amount')
order_promotion_ids = fields.One2many('sale.order.promotion', 'program_line_id', 'Promotions')
- active = fields.Boolean(default=True)
+ active = fields.Boolean(string="Active", default=True)
+ solr_flag = fields.Integer(string="Solr Flag", default=1)
def get_active_promotions(self, product_id):
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py
index 30ce16c9..b241b248 100644
--- a/indoteknik_custom/models/solr/promotion_program_line.py
+++ b/indoteknik_custom/models/solr/promotion_program_line.py
@@ -54,9 +54,7 @@ class PromotionProgramLine(models.Model):
'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]),
'active': rec.active
})
-
self.solr().add([document])
-
self.solr().commit()
@api.model
@@ -67,3 +65,13 @@ class PromotionProgramLine(models.Model):
def write(self, vals):
self._create_solr_queue('_sync_to_solr')
return super(PromotionProgramLine, self).write(vals)
+
+ def solr_flag_to_queue(self, limit=500):
+ domain = [
+ ('solr_flag', '=', 2),
+ ('active', 'in', [True, False])
+ ]
+ records = self.search(domain, limit=limit)
+ for record in records:
+ record._create_solr_queue('_sync_to_solr')
+ record.solr_flag = 1
diff --git a/indoteknik_custom/views/apache_solr_queue.xml b/indoteknik_custom/views/apache_solr_queue.xml
index 7577e569..4c145b9f 100644
--- a/indoteknik_custom/views/apache_solr_queue.xml
+++ b/indoteknik_custom/views/apache_solr_queue.xml
@@ -4,13 +4,16 @@
<field name="model">apache.solr.queue</field>
<field name="arch" type="xml">
<tree editable="top" default_order="create_date desc">
- <button type="object" name="open_target_record" class="fa fa-external-link" />
+ <button type="object" name="open_target_record" string="" icon="fa-external-link" />
<field name="id" readonly="1" />
<field name="display_name" readonly="1" />
<field name="res_model" readonly="1" />
<field name="res_id" readonly="1" />
<field name="function_name" readonly="1" />
- <field name="execute_status" widget="badge" readonly="1"
+ <field
+ name="execute_status"
+ widget="badge"
+ readonly="1"
decoration-danger="execute_status == 'failed'"
decoration-success="execute_status == 'success'"
decoration-primary="execute_status == 'not_found'"
diff --git a/indoteknik_custom/views/promotion/promotion_monitoring.xml b/indoteknik_custom/views/promotion/promotion_monitoring.xml
index b1f80276..88325c52 100644
--- a/indoteknik_custom/views/promotion/promotion_monitoring.xml
+++ b/indoteknik_custom/views/promotion/promotion_monitoring.xml
@@ -3,10 +3,13 @@
<field name="name">Promotion Monitoring Tree</field>
<field name="model">promotion.monitoring</field>
<field name="arch" type="xml">
- <tree>
+ <tree create="0">
<field name="product_id" />
+ <field name="manufacture_id" />
+ <field name="price" />
<field name="has_promo" />
- <field name="count_promo" />
+ <field name="count_active" />
+ <field name="count_inactive" />
</tree>
</field>
</record>
@@ -15,13 +18,16 @@
<field name="name">Promotion Monitoring Form</field>
<field name="model">promotion.monitoring</field>
<field name="arch" type="xml">
- <form>
+ <form create="0" edit="0">
<sheet>
<group>
<group>
<field name="product_id" />
+ <field name="manufacture_id" />
+ <field name="price" />
<field name="has_promo" />
- <field name="count_promo" />
+ <field name="count_active" />
+ <field name="count_inactive" />
</group>
</group>
</sheet>
@@ -29,6 +35,18 @@
</field>
</record>
+ <record id="promotion_monitoring_view_search" model="ir.ui.view">
+ <field name="name">promotion.monitoring.search</field>
+ <field name="model">promotion.monitoring</field>
+ <field name="mode">primary</field>
+ <field name="arch" type="xml">
+ <search string="Search">
+ <field name="product_id" />
+ <field name="manufacture_id" />
+ </search>
+ </field>
+ </record>
+
<record id="promotion_monitoring_action" model="ir.actions.act_window">
<field name="name">Promotion Monitoring</field>
<field name="type">ir.actions.act_window</field>
diff --git a/indoteknik_custom/views/promotion/promotion_program_line.xml b/indoteknik_custom/views/promotion/promotion_program_line.xml
index 280bdfba..025ea35a 100644
--- a/indoteknik_custom/views/promotion/promotion_program_line.xml
+++ b/indoteknik_custom/views/promotion/promotion_program_line.xml
@@ -21,9 +21,10 @@
<sheet>
<group>
<group>
- <field name="program_id" />
<field name="name" />
+ <field name="program_id" />
<field name="promotion_type" />
+ <field name="active" readonly="1" />
</group>
<group>
<field name="package_limit" />
@@ -71,4 +72,19 @@
sequence="2"
action="promotion_program_line_action"
/>
+
+ <data noupdate="1">
+ <record id="cron_program_line_solr_flag_solr" model="ir.cron">
+ <field name="name">Program Line: Solr Flag to Queue</field>
+ <field name="interval_number">1</field>
+ <field name="interval_type">hours</field>
+ <field name="numbercall">-1</field>
+ <field name="doall" eval="False"/>
+ <field name="model_id" ref="model_promotion_program_line"/>
+ <field name="code">model.solr_flag_to_queue()</field>
+ <field name="state">code</field>
+ <field name="priority">55</field>
+ <field name="active">True</field>
+ </record>
+ </data>
</odoo> \ No newline at end of file