summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriFP <andrifebriyadiputra@gmail.com>2025-04-15 16:47:04 +0700
committerAndriFP <andrifebriyadiputra@gmail.com>2025-04-15 16:47:04 +0700
commite9f38f540f92d6ef98b0153cbf17ce064932ad60 (patch)
treedf70ca5bb1b1ba5677197daa0bf62d1aaf0746d5
parentd04df4f0f78e34dbaf1ce7f8ea1102ac2bdf019c (diff)
fix: add minimun delivery_amt + alert
-rwxr-xr-xindoteknik_custom/models/sale_order.py80
1 files changed, 76 insertions, 4 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index c83ffd61..36feb70b 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -315,8 +315,12 @@ class SaleOrder(models.Model):
"sale_order_id": self.id,
})
self.shipping_option_id = shipping_option.id
-
+
def action_estimate_shipping(self):
+ # Pengecekan Minimum Delivery Amount
+ if self.delivery_amt < 5000:
+ raise UserError("Estimasi ongkos kirim belum mencapai jumlah minimum untuk pengiriman")
+
if self.carrier_id.id in [1, 151]:
self.action_indoteknik_estimate_shipping()
return
@@ -366,10 +370,65 @@ class SaleOrder(models.Model):
self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id
- self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}<br/>Detail Lain:<br/>{'<br/>'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}")
+ # Jika perlu, tambahkan log atau tindakan lebih lanjut setelah peringatan
else:
raise UserError("Gagal mendapatkan estimasi ongkir.")
+
+ # def action_estimate_shipping(self):
+ # if self.carrier_id.id in [1, 151]:
+ # self.action_indoteknik_estimate_shipping()
+ # return
+
+ # total_weight = 0
+ # missing_weight_products = []
+
+ # for line in self.order_line:
+ # if line.weight > 0:
+ # total_weight += line.weight * line.product_uom_qty
+ # line.product_id.weight = line.weight
+ # else:
+ # missing_weight_products.append(line.product_id.name)
+
+ # if missing_weight_products:
+ # product_names = '<br/>'.join(missing_weight_products)
+ # self.message_post(body=f"Produk berikut tidak memiliki berat:<br/>{product_names}")
+
+ # if total_weight == 0:
+ # raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.")
+
+ # destination_subsdistrict_id = self.real_shipping_id.kecamatan_id.rajaongkir_id
+ # if not destination_subsdistrict_id:
+ # raise UserError("Gagal mendapatkan ID kota tujuan.")
+
+ # result = self._call_rajaongkir_api(total_weight, destination_subsdistrict_id)
+ # if result:
+ # shipping_options = []
+ # for courier in result['rajaongkir']['results']:
+ # for cost_detail in courier['costs']:
+ # service = cost_detail['service']
+ # description = cost_detail['description']
+ # etd = cost_detail['cost'][0]['etd']
+ # value = cost_detail['cost'][0]['value']
+ # shipping_options.append((service, description, etd, value, courier['code']))
+
+ # self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink()
+
+ # for service, description, etd, value, provider in shipping_options:
+ # self.env["shipping.option"].create({
+ # "name": service,
+ # "price": value,
+ # "provider": provider,
+ # "etd": etd,
+ # "sale_order_id": self.id,
+ # })
+
+ # self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id
+
+ # self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}<br/>Detail Lain:<br/>{'<br/>'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}")
+ # else:
+ # raise UserError("Gagal mendapatkan estimasi ongkir.")
+
def _call_rajaongkir_api(self, total_weight, destination_subsdistrict_id):
url = 'https://pro.rajaongkir.com/api/cost'
headers = {
@@ -670,13 +729,26 @@ class SaleOrder(models.Model):
raise UserError('Email yang anda input kurang valid')
# @api.constrains('delivery_amt', 'carrier_id', 'shipping_cost_covered')
+
def _validate_delivery_amt(self):
+ if self.delivery_amt < 5000:
+ raise UserError("Estimasi Ongkos Kirim belum memenuhi jumlah minimum untuk pengiriman.")
+
if self.delivery_amt < 1:
- if(self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []):
- if(self.carrier_id.id == 1):
+ if (self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []):
+ if self.carrier_id.id == 1:
raise UserError('Untuk Kurir Indoteknik Delivery, Estimasi Ongkos Kirim Harus di isi')
else:
raise UserError('Untuk Shipping Covered Indoteknik, Estimasi Ongkos Kirim Harus di isi')
+
+
+ # def _validate_delivery_amt(self):
+ # if self.delivery_amt < 1:
+ # if(self.carrier_id.id == 1 or self.shipping_cost_covered == 'indoteknik') and not self.env.context.get('active_id', []):
+ # if(self.carrier_id.id == 1):
+ # raise UserError('Untuk Kurir Indoteknik Delivery, Estimasi Ongkos Kirim Harus di isi')
+ # else:
+ # raise UserError('Untuk Shipping Covered Indoteknik, Estimasi Ongkos Kirim Harus di isi')
def override_allow_create_invoice(self):
if not self.env.user.is_accounting: