From 55a7bd6000c93b19f70489e5393102854cceaa4b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 7 Oct 2024 14:05:09 +0700 Subject: cr estimate shipping price envio --- indoteknik_custom/models/sale_order.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 = '
'.join(missing_weight_products) + self.message_post(body=f"Produk berikut tidak memiliki berat:
{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) -- cgit v1.2.3