summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-10-07 14:05:09 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-10-07 14:05:09 +0700
commit55a7bd6000c93b19f70489e5393102854cceaa4b (patch)
tree94c8357a12396338d743b2062bfe6b6282fed78d
parent6b6a7d9f271106325133f1ec84c66717d2eec711 (diff)
cr estimate shipping price envio
-rwxr-xr-xindoteknik_custom/models/sale_order.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 265ffb9e..2cef531e 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -140,14 +140,42 @@ class SaleOrder(models.Model):
def _compute_total_weight(self):
for order in self:
order.total_weight = sum(line.weight for line in order.order_line)
+
+ def action_indoteknik_estimate_shipping(self):
+ if not self.real_shipping_id.kota_id.is_jabodetabek:
+ raise UserError('Estimasi ongkir hanya bisa dilakukan di kota Jabodetabek')
+
+ total_weight = 0
+ missing_weight_products = []
+
+ for line in self.order_line:
+ if line.weight:
+ 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.")
+
+ if total_weight < 10:
+ total_weight = 10
+ self.delivery_amt = total_weight * 3000
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:
- total_weight += line.weight
+ total_weight += line.weight * line.product_uom_qty
line.product_id.weight = line.weight
else:
missing_weight_products.append(line.product_id.name)