summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_api/controllers')
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index 88a72755..6c878197 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -335,28 +335,36 @@ class SaleOrder(controller.Controller):
'product_uom_qty': item['quantity'],
})
- cart_ids = [x['cart_id'] for x in products]
- user_cart.browse(cart_ids).unlink()
request.env['sale.order.line'].create(parameters)
- amount_untaxed = sale_order.amount_untaxed
- voucher = request.env['voucher'].search([
- ('code', '=', params['value']['voucher'])
- ])
+ voucher_code = params['value']['voucher']
+ voucher = request.env['voucher'].search([('code', '=', voucher_code)])
if voucher:
+ amount_untaxed = 0
+ manufacture_ids = [x.id for x in voucher.manufacture_ids]
+ for line in sale_order.order_line:
+ manufacture_id = line.product_id.x_manufacture.id or False
+ if len(manufacture_ids) == 0 or manufacture_id in manufacture_ids:
+ amount_untaxed += line.price_subtotal
+
voucher_discount = voucher.calculate_discount(amount_untaxed)
sale_order.voucher_id = voucher.id
sale_order.amount_voucher_disc = voucher_discount
- total_qty = sum(line.product_uom_qty for line in sale_order.order_line)
- voucher_discount_item = voucher_discount / total_qty
for line in sale_order.order_line:
+ manufacture_id = line.product_id.x_manufacture.id or False
+ if len(manufacture_ids) > 0 and manufacture_id not in manufacture_ids:
+ continue
+ voucher_discount_line = line.price_subtotal / amount_untaxed * voucher_discount
+ line.amount_voucher_disc = voucher_discount_line
+
discount_decimal = line.discount / 100
- voucher_discount_line = voucher_discount_item / (1 - discount_decimal)
- price = line.price_unit - voucher_discount_line
- line.price_unit = price
- line.amount_voucher_disc = voucher_discount_item * line.product_uom_qty
+ voucher_discount_item = voucher_discount_line / line.product_uom_qty
+ voucher_disc_before_line_disc = voucher_discount_item / (1 - discount_decimal)
+ line.price_unit -= voucher_disc_before_line_disc
+ cart_ids = [x['cart_id'] for x in products]
+ user_cart.browse(cart_ids).unlink()
return self.response({
'id': sale_order.id,
'name': sale_order.name