summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-02-22 14:49:25 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-02-22 14:49:25 +0700
commitda0a75bc6b7166e297bcaf175c15089e95dbbf2e (patch)
tree156cfb319848cd2b2964f83b3cb185e8f920f7b2 /indoteknik_custom/models
parent6850fd6f86a0fbba3156e59f9ac5836052f019ce (diff)
parent0face879a802bf1a15d1065d59db64f723b4e8d3 (diff)
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/account_move.py2
-rw-r--r--indoteknik_custom/models/promotion/promotion_free_product.py4
-rw-r--r--indoteknik_custom/models/promotion/promotion_product.py4
-rw-r--r--indoteknik_custom/models/promotion/promotion_program_line.py8
-rw-r--r--indoteknik_custom/models/solr/apache_solr_queue.py14
-rw-r--r--indoteknik_custom/models/solr/product_product.py2
-rw-r--r--indoteknik_custom/models/solr/promotion_program_line.py4
7 files changed, 30 insertions, 8 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index a9db212f..7eb65e9f 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -122,7 +122,7 @@ class AccountMove(models.Model):
sum_qty_invoice = sum_qty_order = 0
for line in purchase_order.order_line:
sum_qty_invoice += line.qty_invoiced
- sum_qty_order += line.product_uom_qty
+ sum_qty_order += line.product_qty
if sum_qty_invoice > sum_qty_order:
raise UserError('Error Qty Invoice akan lebih besar dari Qty Order jika lanjut Posting')
diff --git a/indoteknik_custom/models/promotion/promotion_free_product.py b/indoteknik_custom/models/promotion/promotion_free_product.py
index c5055562..e91d5137 100644
--- a/indoteknik_custom/models/promotion/promotion_free_product.py
+++ b/indoteknik_custom/models/promotion/promotion_free_product.py
@@ -17,6 +17,10 @@ class PromotionFreeProduct(models.Model):
weight = rec.product_id.weight or 0
result.append({
'id': rec.product_id.id,
+ 'parent': {
+ 'id': rec.product_id.product_tmpl_id.id,
+ 'name': rec.product_id.product_tmpl_id.name,
+ },
'image': ir_attachment.api_image('product.template', 'image_256', rec.product_id.product_tmpl_id.id),
'display_name': rec.product_id.display_name,
'name': rec.product_id.name,
diff --git a/indoteknik_custom/models/promotion/promotion_product.py b/indoteknik_custom/models/promotion/promotion_product.py
index 2fad0f0d..ae26e888 100644
--- a/indoteknik_custom/models/promotion/promotion_product.py
+++ b/indoteknik_custom/models/promotion/promotion_product.py
@@ -17,6 +17,10 @@ class PromotionProduct(models.Model):
weight = rec.product_id.weight or 0
result.append({
'id': rec.product_id.id,
+ 'parent': {
+ 'id': rec.product_id.product_tmpl_id.id,
+ 'name': rec.product_id.product_tmpl_id.name,
+ },
'image': ir_attachment.api_image('product.template', 'image_256', rec.product_id.product_tmpl_id.id),
'display_name': rec.product_id.display_name,
'name': rec.product_id.name,
diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py
index 18a7e184..ce46d2e7 100644
--- a/indoteknik_custom/models/promotion/promotion_program_line.py
+++ b/indoteknik_custom/models/promotion/promotion_program_line.py
@@ -30,6 +30,7 @@ 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)
def get_active_promotions(self, product_id):
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@@ -74,6 +75,9 @@ class PromotionProgramLine(models.Model):
}
def _get_remaining_time(self):
+ if not self.program_id.end_time:
+ return 0
+
calculate_time = self.program_id.end_time - datetime.now()
return round(calculate_time.total_seconds())
@@ -93,9 +97,7 @@ class PromotionProgramLine(models.Model):
free_products = self.free_product_ids.formats(purchase_qty=qty)
merged_products = products + free_products
- weight = 0
- if not any(x['package_weight'] == 0 for x in merged_products):
- weight = sum(x['package_weight'] for x in merged_products)
+ weight = sum(x['package_weight'] for x in merged_products)
# Sum of products and free products in 1 package quantity
products_total = sum(x['price']['price_discount'] * x['qty'] / qty for x in products)
diff --git a/indoteknik_custom/models/solr/apache_solr_queue.py b/indoteknik_custom/models/solr/apache_solr_queue.py
index 07274295..02ad5bb8 100644
--- a/indoteknik_custom/models/solr/apache_solr_queue.py
+++ b/indoteknik_custom/models/solr/apache_solr_queue.py
@@ -18,6 +18,7 @@ class ApacheSolrQueue(models.Model):
('not_found', 'Record not found')
], 'Execute Status')
execute_date = fields.Datetime('Execute Date')
+ description = fields.Text('Description')
def _compute_display_name(self):
for rec in self:
@@ -38,6 +39,16 @@ class ApacheSolrQueue(models.Model):
if elapsed_time > max_exec_time:
break
rec.execute_queue()
+
+ def open_target_record(self):
+ return {
+ 'name': '',
+ 'view_mode': 'form',
+ 'res_model': self.res_model,
+ 'target': 'current',
+ 'type': 'ir.actions.act_window',
+ 'res_id': self.res_id
+ }
def execute_queue(self):
for rec in self:
@@ -57,7 +68,8 @@ class ApacheSolrQueue(models.Model):
rec.execute_status = 'success'
else:
rec.execute_status = 'not_found'
- except:
+ except Exception as e:
+ rec.description = e
rec.execute_status = 'failed'
rec.execute_date = datetime.utcnow()
self.env.cr.commit()
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py
index 5a74df8c..c14f6b98 100644
--- a/indoteknik_custom/models/solr/product_product.py
+++ b/indoteknik_custom/models/solr/product_product.py
@@ -59,7 +59,7 @@ class ProductProduct(models.Model):
'template_id_i': variant.product_tmpl_id.id,
'image_s': ir_attachment.api_image('product.template', 'image_256', variant.product_tmpl_id.id),
'stock_total_f': variant.qty_stock_vendor,
- 'weight_f': variant.product_tmpl_id.weight,
+ 'weight_f': variant.weight,
'manufacture_id_i': variant.product_tmpl_id.x_manufacture.id or 0,
'manufacture_name_s': variant.product_tmpl_id.x_manufacture.x_name or '',
'manufacture_name': variant.product_tmpl_id.x_manufacture.x_name or '',
diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py
index 6e182324..30ce16c9 100644
--- a/indoteknik_custom/models/solr/promotion_program_line.py
+++ b/indoteknik_custom/models/solr/promotion_program_line.py
@@ -39,9 +39,8 @@ class PromotionProgramLine(models.Model):
document.update({
'id': rec.id,
- 'program_id_i': rec.program_id.id,
+ 'program_id_i': rec.program_id.id or 0,
'name_s': rec.name,
- 'image_s': self.env['ir.attachment'].api_image(self._name, 'image', rec.id) if rec.image else '',
'type_value_s': promotion_type['value'],
'type_label_s': promotion_type['label'],
'package_limit_i': rec.package_limit,
@@ -53,6 +52,7 @@ class PromotionProgramLine(models.Model):
'free_product_ids': [x.product_id.id for x in rec.free_product_ids],
'free_products_s': json.dumps(free_products),
'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])