summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-06-05 11:03:10 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-06-05 11:03:10 +0700
commit8d87673201e7339cb946c36e8f91579e135d5c5b (patch)
treecf17537384f05b26632b47e217f4c5536f5edc60
parent9306992db370c793e8cab494038b0de5b61b600f (diff)
api promotion program line get program line by promotion_type
-rw-r--r--indoteknik_api/controllers/api_v1/promotion.py44
-rwxr-xr-xindoteknik_custom/models/product_template.py4
2 files changed, 46 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/api_v1/promotion.py b/indoteknik_api/controllers/api_v1/promotion.py
index 221f6e10..aca092af 100644
--- a/indoteknik_api/controllers/api_v1/promotion.py
+++ b/indoteknik_api/controllers/api_v1/promotion.py
@@ -28,7 +28,51 @@ class Promotion(controller.Controller):
'remaining_qty': remaining_qty,
'used_percentage': percent_remaining,
})
+
+ @http.route(prefix + 'program-line', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def get_promotion_type(self, **kw):
+ type = kw.get('type')
+ program_line = request.env['promotion.program.line'].search([
+ ("promotion_type", "=", type),
+ ("active", "=", True)
+ ])
+
+ if not type:
+ program_line = request.env['promotion.program.line'].search([("active", "=", True)])
+
+ data = []
+ for line in program_line:
+ product_list = []
+ for product in line.product_ids:
+ product_list.append({
+ 'id': product.product_id.id,
+ 'name': product.product_id.name,
+ 'qty': product.qty
+ })
+ free_product_list = []
+ for free_product in line.product_ids:
+ free_product_list.append({
+ 'id': free_product.product_id.id,
+ 'name': free_product.product_id.name,
+ 'qty': product.qty
+ })
+
+ data.append({
+ 'id': line.id,
+ 'name': line.name,
+ 'program': line.program_id.name,
+ 'promotion_type': line.promotion_type,
+ 'active': line.active,
+ 'description': line.description,
+ 'package_limit': line.package_limit,
+ 'package_limit_user': line.package_limit_user,
+ 'package_limit_trx': line.package_limit_trx,
+ 'price': line.price,
+ 'products': product_list
+ })
+ return self.response(data)
@http.route(prefix + 'promotion/<id>', auth='public', methods=['GET'])
@controller.Controller.must_authorized()
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 6086a2ca..d490eb05 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -403,7 +403,7 @@ class ProductProduct(models.Model):
for product in self:
qty_incoming = self.env['stock.move'].search([
('product_id', '=', product.id),
- ('location_dest_id', '=', 57),
+ ('location_dest_id', 'in', [57, 83]),
('state', 'not in', ['done', 'cancel'])
])
qty = sum(qty_incoming.mapped('product_uom_qty'))
@@ -414,7 +414,7 @@ class ProductProduct(models.Model):
qty_incoming = self.env['stock.move'].search([
('product_id', '=', product.id),
('location_dest_id', '=', 5),
- ('location_id', '=', 57),
+ ('location_id', 'in', [57, 83]),
('state', 'not in', ['done', 'cancel'])
])
qty = sum(qty_incoming.mapped('product_uom_qty'))