summaryrefslogtreecommitdiff
path: root/indoteknik_custom
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-08-24 11:28:05 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-08-24 11:28:05 +0700
commitc420bd4e418b2f646e1b3116bdb31e4ff07bf448 (patch)
treed004c85cec5800c218fc1b39de3f6e2d842c63bb /indoteknik_custom
parent9e4511c8d27665a53d296ee648150121a7f6cf84 (diff)
Add estimated arrival days field and estimated time arrival API response
Diffstat (limited to 'indoteknik_custom')
-rwxr-xr-xindoteknik_custom/models/sale_order.py1
-rw-r--r--indoteknik_custom/models/stock_picking.py29
-rwxr-xr-xindoteknik_custom/views/sale_order.xml1
3 files changed, 30 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index ca98cde4..d0817ad5 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -76,6 +76,7 @@ class SaleOrder(models.Model):
voucher_id = fields.Many2one(comodel_name='voucher', string='Voucher')
amount_voucher_disc = fields.Float(string='Voucher Discount')
source_id = fields.Many2one('utm.source', 'Source', domain="[('id', 'in', [32, 59, 60, 61])]")
+ estimated_arrival_days = fields.Integer('Estimated Arrival Days', default=0)
def _compute_purchase_total(self):
for order in self:
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 8d1a85ea..c094b74d 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -396,7 +396,8 @@ class StockPicking(models.Model):
},
'delivered': False,
'waybill_number': self.delivery_tracking_no or '',
- 'delivery_status': None
+ 'delivery_status': None,
+ 'eta': self.generate_eta_delivery()
}
if not self.waybill_id or len(self.waybill_id.manifest_ids) == 0:
@@ -411,3 +412,29 @@ class StockPicking(models.Model):
response['manifests'] = [self.create_manifest_data(x.description, x.datetime) for x in self.waybill_id.manifest_ids]
return response
+
+ def generate_eta_delivery(self):
+ current_date = datetime.datetime.now()
+ prepare_days = 3
+ start_date = self.driver_departure_date or self.create_date
+
+ ead = self.sale_id.estimated_arrival_days or 0
+ if not self.driver_departure_date:
+ ead += prepare_days
+
+ ead_datetime = datetime.timedelta(days=ead)
+ fastest_eta = start_date + ead_datetime
+ if not self.driver_departure_date and fastest_eta < current_date:
+ fastest_eta = current_date + ead_datetime
+
+ longest_days = 3
+ longest_eta = fastest_eta + datetime.timedelta(days=longest_days)
+
+ if fastest_eta.year == longest_eta.year:
+ formatted_fastest_eta = fastest_eta.strftime('%d %b')
+ formatted_longest_eta = longest_eta.strftime('%d %b %Y')
+ else:
+ formatted_fastest_eta = fastest_eta.strftime('%d %b %Y')
+ formatted_longest_eta = longest_eta.strftime('%d %b %Y')
+
+ return f'{formatted_fastest_eta} - {formatted_longest_eta}'
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index d2a59621..032156cf 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -93,6 +93,7 @@
</field>
<field name="effective_date" position="after">
<field name="carrier_id"/>
+ <field name="estimated_arrival_days"/>
</field>
<page name="customer_signature" position="after">