summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-09-04 17:12:38 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-09-04 17:12:38 +0700
commit1bb074bb8f63072fb990c57c18986c50981f1402 (patch)
tree5b466fca04cc421fae058c743db94af25e479d7b
parent0222d907c08ef27dd8d3b303b55d70542cbeb788 (diff)
fix voucher shipping
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py4
-rwxr-xr-xindoteknik_custom/models/sale_order.py54
-rw-r--r--indoteknik_custom/models/website_user_cart.py3
-rwxr-xr-xindoteknik_custom/views/sale_order.xml16
4 files changed, 72 insertions, 5 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index c871b69e..e8d18366 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -407,7 +407,7 @@ class SaleOrder(controller.Controller):
'real_invoice_id': params['value']['partner_invoice_id'],
'partner_purchase_order_name': params['value']['po_number'],
'partner_purchase_order_file': params['value']['po_file'],
- 'delivery_amt': params['value']['delivery_amount'],
+ 'delivery_amt': params['value']['delivery_amount'] * 1.10,
'estimated_arrival_days': params['value']['estimated_arrival_days'],
'shipping_cost_covered': 'customer',
'shipping_paid_by': 'customer',
@@ -468,7 +468,7 @@ class SaleOrder(controller.Controller):
if voucher_shipping and len(promotions) == 0:
sale_order.voucher_shipping_id = voucher_shipping.id
- sale_order.apply_voucher()
+ sale_order.apply_voucher_shipping()
cart_ids = [x['cart_id'] for x in carts]
if sale_order._requires_approval_margin_leader(): #jika ada error tambahkan kondisi if params['value']['type'] == 'sale_order':
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 348ea4d3..0268f27b 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -88,6 +88,8 @@ class SaleOrder(models.Model):
voucher_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False)
applied_voucher_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False)
amount_voucher_disc = fields.Float(string='Voucher Discount')
+ applied_voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False)
+ amount_voucher_shipping_disc = fields.Float(string='Voucher Discount')
source_id = fields.Many2one('utm.source', 'Source', domain="[('id', 'in', [32, 59, 60, 61])]", required=True)
estimated_arrival_days = fields.Integer('Estimated Arrival Days', default=0)
email = fields.Char(string='Email')
@@ -109,7 +111,7 @@ class SaleOrder(models.Model):
date_driver_departure = fields.Datetime(string='Departure Date', compute='_compute_date_kirim', copy=False)
note_website = fields.Char(string="Note Website")
use_button = fields.Boolean(string='Using Calculate Selling Price', copy=False)
- voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False)
+ voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher Shipping', copy=False)
def _compute_date_kirim(self):
for rec in self:
@@ -781,6 +783,28 @@ class SaleOrder(models.Model):
self.apply_voucher()
+ def action_apply_voucher_shipping(self):
+ for line in self.order_line:
+ if line.order_promotion_id:
+ raise UserError('Voucher tidak dapat digabung dengan promotion program')
+
+ voucher = self.voucher_shipping_id
+ if voucher.limit > 0 and voucher.count_order >= voucher.limit:
+ raise UserError('Voucher tidak dapat digunakan karena sudah habis digunakan')
+
+ partner_voucher_orders = []
+ for order in voucher.order_ids:
+ if order.partner_id.id == self.partner_id.id:
+ partner_voucher_orders.append(order)
+
+ if voucher.limit_user > 0 and len(partner_voucher_orders) >= voucher.limit_user:
+ raise UserError('Voucher tidak dapat digunakan karena Customer ini sudah menghabiskan kuota voucher')
+
+ if self.pricelist_id.id in [x.id for x in voucher.excl_pricelist_ids]:
+ raise UserError('Voucher tidak dapat digunakan karena pricelist ini tidak berlaku pada voucher')
+
+ self.apply_voucher_shipping()
+
def apply_voucher(self):
order_line = []
for line in self.order_line:
@@ -822,6 +846,29 @@ class SaleOrder(models.Model):
self.amount_voucher_disc = voucher['discount']['all']
self.applied_voucher_id = self.voucher_id
+ def apply_voucher_shipping(self):
+ for order in self:
+ delivery_amt = order.delivery_amt
+ voucher = order.voucher_shipping_id
+
+ if voucher:
+ max_discount_amount = voucher.discount_amount
+ voucher_type = voucher.discount_type
+
+ if voucher_type == 'fixed_price':
+ discount = max_discount_amount
+ elif voucher_type == 'percentage':
+ discount = delivery_amt * (max_discount_amount / 100)
+
+ delivery_amt -= discount
+
+ delivery_amt = max(delivery_amt, 0)
+
+ order.delivery_amt = delivery_amt
+
+ order.amount_voucher_shipping_disc = discount
+ order.applied_voucher_shipping_id = order.voucher_id.id
+
def cancel_voucher(self):
self.applied_voucher_id = False
self.amount_voucher_disc = 0
@@ -830,6 +877,11 @@ class SaleOrder(models.Model):
line.discount = line.initial_discount
line.initial_discount = False
+ def cancel_voucher_shipping(self):
+ self.delivery_amt + self.amount_voucher_shipping_disc
+ self.applied_voucher_shipping_id = False
+ self.amount_voucher_shipping_disc = 0
+
def action_web_approve(self):
if self.env.uid != self.partner_id.user_id.id:
raise UserError('You are not authorized to approve this order. Only %s can approve this order.' % self.partner_id.user_id.name)
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index 0af22d47..b0cf47f7 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -130,8 +130,7 @@ class WebsiteUserCart(models.Model):
if voucher_shipping:
voucher_shipping_info = voucher_shipping.apply(order_line)
- discount_voucher_shipping = voucher_shipping_info['discount']['all']
- subtotal -= discount_voucher_shipping
+ discount_voucher_shipping = voucher_shipping_info['discount']['all']
tax = round(subtotal * 0.11)
grand_total = subtotal + tax
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 1257ff85..44070f35 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -43,6 +43,17 @@
attrs="{'invisible': ['|', ('applied_voucher_id', '=', False), ('state', 'not in', ['draft','sent'])]}"
/>
</div>
+ <label for="voucher_shipping_id"/>
+ <div class="o_row">
+ <field name="voucher_shipping_id" id="voucher_shipping_id" attrs="{'readonly': ['|', ('state', 'not in', ['draft', 'sent']), ('applied_voucher_shipping_id', '!=', False)]}"/>
+ <field name="applied_voucher_shipping_id" invisible="1" />
+ <button name="action_apply_voucher_shipping" type="object" string="Apply" confirm="Anda yakin untuk menggunakan voucher?" help="Apply the selected voucher" class="btn-link mb-1 px-0" icon="fa-plus"
+ attrs="{'invisible': ['|', '|', ('voucher_id', '=', False), ('state', 'not in', ['draft', 'sent']), ('applied_voucher_shipping_id', '!=', False)]}"
+ />
+ <button name="cancel_voucher_shipping" type="object" string="Cancel" confirm="Anda yakin untuk membatalkan penggunaan voucher?" help="Cancel applied voucher" class="btn-link mb-1 px-0" icon="fa-times"
+ attrs="{'invisible': ['|', ('applied_voucher_shipping_id', '=', False), ('state', 'not in', ['draft','sent'])]}"
+ />
+ </div>
<button name="calculate_selling_price"
string="Calculate Selling Price"
type="object"
@@ -138,6 +149,11 @@
<field class="mb-0" name="amount_voucher_disc" string="Voucher" readonly="1"/>
<div class="text-right mb-2"><small>*Hanya informasi</small></div>
</div>
+ <label for="amount_voucher_shipping_disc" string="Voucher Shipping" />
+ <div>
+ <field class="mb-0" name="amount_voucher_shipping_disc" string="Voucher Shipping" readonly="1"/>
+ <div class="text-right mb-2"><small>*Hanya informasi</small></div>
+ </div>
<field name="total_margin"/>
<field name="total_percent_margin"/>
</field>