summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/stock_picking.py
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2025-02-13 11:20:11 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2025-02-13 11:20:11 +0700
commit6a1b03cbd12931784aee8226ed5f163dcae42081 (patch)
tree7a8c528d4dda29a7630d8603b2d87fadea4cb07a /indoteknik_custom/models/stock_picking.py
parentd539aedf0b1f7a6cfbd87b9d167833c6c9ea68ee (diff)
biteship
Diffstat (limited to 'indoteknik_custom/models/stock_picking.py')
-rw-r--r--indoteknik_custom/models/stock_picking.py46
1 files changed, 26 insertions, 20 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index f766dc3f..e7d9dbd5 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -170,18 +170,18 @@ class StockPicking(models.Model):
biteship_tracking_id = fields.Char(string="Biteship Trackcking ID")
biteship_waybill_id = fields.Char(string="Biteship Waybill ID")
estimated_ready_ship_date = fields.Datetime(string='ET Ready to Ship', copy=False, store=True, related='sale_id.estimated_ready_ship_date')
- countdown_hours = fields.Float(string='Countdown in Hours', compute='_compute_countdown_hours', store=True, default=False)
+ countdown_hours = fields.Float(string='Countdown in Hours', compute='_compute_countdown_ready_to_ship', store=True, default=False)
countdown_ready_to_ship = fields.Char(string='Countdown Ready to Ship', compute='_compute_countdown_ready_to_ship')
- @api.depends('estimated_ready_ship_date', 'state')
- def _compute_countdown_hours(self):
- for record in self:
- if record.state in ('cancel', 'done') or not record.estimated_ready_ship_date:
- # Gunakan nilai yang sangat besar sebagai placeholder
- record.countdown_hours = 999999
- else:
- delta = record.estimated_ready_ship_date - waktu.now()
- record.countdown_hours = delta.total_seconds() / 3600
+ # @api.depends('estimated_ready_ship_date', 'state')
+ # def _compute_countdown_hours(self):
+ # for record in self:
+ # if record.state in ('cancel', 'done') or not record.estimated_ready_ship_date:
+ # # Gunakan nilai yang sangat besar sebagai placeholder
+ # record.countdown_hours = 999999
+ # else:
+ # delta = record.estimated_ready_ship_date - waktu.now()
+ # record.countdown_hours = delta.total_seconds() / 3600
@api.depends('estimated_ready_ship_date', 'state')
def _compute_countdown_ready_to_ship(self):
@@ -194,6 +194,7 @@ class StockPicking(models.Model):
days = delta.days
hours, remainder = divmod(delta.seconds, 3600)
record.countdown_ready_to_ship = f"{days} days, {hours} hours"
+ record.countdown_hours = delta.total_seconds() / 3600
else:
record.countdown_ready_to_ship = False
@@ -351,7 +352,7 @@ class StockPicking(models.Model):
picking.tracking_by = self.env.user.id
ata_at_str = data.get("ata_at")
envio_ata = self._convert_to_datetime(data.get("ata_at"))
-
+
picking.driver_arrival_date = envio_ata
if data.get("status") != 'delivered':
picking.driver_arrival_date = False
@@ -367,7 +368,7 @@ class StockPicking(models.Model):
# Mencari data sale.order.line berdasarkan sale_id
products = self.env['sale.order.line'].search([('order_id', '=', self.sale_id.id)])
-
+
# Fungsi untuk membangun items_data dari order lines
def build_items_data(lines):
return [{
@@ -411,7 +412,8 @@ class StockPicking(models.Model):
"destination_contact_phone": self.real_shipping_id.phone or self.real_shipping_id.mobile,
"destination_address": self.real_shipping_id.street,
"destination_postal_code": self.real_shipping_id.zip,
- "courier_type": "reg",
+ "origin_note": "BELAKANG INDOMARET",
+ "courier_type": self.sale_id.delivery_service_type or "reg",
"courier_company": self.carrier_id.name.lower(),
"delivery_type": "now",
"destination_postal_code": self.real_shipping_id.zip,
@@ -421,11 +423,15 @@ class StockPicking(models.Model):
# Cek jika pengiriman instant atau same_day
if self.sale_id.delivery_service_type and ("instant" in self.sale_id.delivery_service_type or "same_day" in self.sale_id.delivery_service_type):
payload.update({
- "origin_note": "BELAKANG INDOMARET",
- "courier_company": self.carrier_id.name.lower(),
- "courier_type": self.sale_id.delivery_service_type,
- "delivery_type": "now",
- "items": items_data_instant # Gunakan items untuk instant
+ "origin_coordinate" :{
+ "latitude": -6.3031123,
+ "longitude" : 106.7794934999
+ },
+ "destination_coordinate" : {
+ "latitude": self.real_shipping_id.latitude,
+ "longitude": self.real_shipping_id.longtitude,
+ },
+ "items": items_data_instant
})
headers = {
@@ -440,8 +446,8 @@ class StockPicking(models.Model):
data = response.json()
self.biteship_id = data.get("id", "")
- self.biteship_tracking_id = data.get("tracking_id", "")
- self.biteship_waybill_id = data.get("waybill_id", "")
+ self.biteship_tracking_id = data.get("courier", {}).get("tracking_id", "")
+ self.biteship_waybill_id = data.get("courier", {}).get("waybill_id", "")
return data
else: