summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/stock_picking.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/stock_picking.py')
-rw-r--r--indoteknik_custom/models/stock_picking.py100
1 files changed, 96 insertions, 4 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 6f038386..2a73d631 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -3,7 +3,7 @@ from odoo.exceptions import AccessError, UserError, ValidationError
from odoo.tools.float_utils import float_is_zero
from datetime import datetime
from itertools import groupby
-import pytz, datetime
+import pytz, datetime, requests, json
class StockPicking(models.Model):
@@ -73,10 +73,8 @@ class StockPicking(models.Model):
('hold', 'Hold by Sales'),
('not_paid', 'Customer belum bayar'),
('partial', 'Kirim Parsial'),
- ('not_complete', 'Belum Lengkap'),
('indent', 'Indent'),
('self_pickup', 'Barang belum di pickup Customer'),
- ('delivery_route', 'Belum masuk rute pengiriman'),
('expedition_closed', 'Eskpedisi belum buka')
], string='Note Logistic', help='jika field ini diisi maka tidak akan dihitung ke lead time')
waybill_id = fields.One2many(comodel_name='airway.bill', inverse_name='do_id', string='Airway Bill')
@@ -94,6 +92,8 @@ class StockPicking(models.Model):
date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True)
sale_order = fields.Char(string='Matches SO', copy=False)
printed_sj = fields.Boolean('Printed Surat Jalan', help='flag which is internal use or not')
+ printed_sj_retur = fields.Boolean('Printed Surat Jalan Retur', help='flag which is internal use or not')
+ date_printed_sj_retur = fields.Datetime(string='Status Printed Surat Jalan Retur', copy=False, tracking=True)
invoice_status = fields.Selection([
('upselling', 'Upselling Opportunity'),
('invoiced', 'Fully Invoiced'),
@@ -101,6 +101,58 @@ class StockPicking(models.Model):
('no', 'Nothing to Invoice')
], string='Invoice Status', related="sale_id.invoice_status")
+ state_reserve = fields.Selection([
+ ('waiting', 'Waiting For Fullfilment'),
+ ('ready', 'Ready to Ship'),
+ ('done', 'Done'),
+ ('cancel', 'Cancelled'),
+ ], string='Status Reserve', readonly=True, tracking=True, help="The current state of the stock picking.")
+
+ def action_send_to_biteship(self):
+ url = "https://api.biteship.com/v1/orders"
+
+ api_key = "biteship_test.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSW5kb3Rla25payIsInVzZXJJZCI6IjY3MTViYTJkYzVkMjdkMDAxMjRjODk2MiIsImlhdCI6MTcyOTQ5ODAwMX0.L6C73couP4-cgVEfhKI2g7eMCMo3YOFSRZhS-KSuHNA"
+
+ items_data = []
+ for item in self.items:
+ items_data.append({
+ "name": item.name,
+ "description": item.description,
+ "category": item.category,
+ "value": item.value,
+ "quantity": item.quantity,
+ "weight": item.weight
+ })
+
+ payload = {
+ "shipper_contact_name": self.carrier_id.pic_name or '',
+ "shipper_contact_phone": self.carrier_id.pic_phone or '',
+ # "shipper_contact_email": "sales@indoteknik.co.id",
+ "shipper_organization": self.carrier_id.name,
+ "origin_contact_name": "PT. Indoteknik Dotcom Gemilang",
+ "origin_contact_phone": "081717181922",
+ "origin_address": "Jl. Bandengan Utara Komp A & BRT. Penjaringan, Kec. Penjaringan, Jakarta (BELAKANG INDOMARET) KOTA JAKARTA UTARA PENJARINGAN",
+ "origin_postal_code": "14440",
+ "destination_contact_name": self.real_shipping_id.name,
+ "destination_contact_phone": self.real_shipping_id.phone or self.real_shipping_id.mobile,
+ "destination_contact_email": self.real_shipping_id.email or '',
+ "destination_address": self.real_shipping_id.street,
+ "destination_postal_code": self.real_shipping_id.zip,
+ "items": items_data
+ }
+
+ headers = {
+ "Authorization": f"Bearer {api_key}",
+ "Content-Type": "application/json"
+ }
+
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
+
+ if response.status_code == 201:
+ return response.json()
+ else:
+ raise UserError(f"Error saat mengirim ke Biteship: {response.content}")
+
@api.constrains('driver_departure_date')
def constrains_driver_departure_date(self):
self.date_doc_kirim = self.driver_departure_date
@@ -125,16 +177,54 @@ class StockPicking(models.Model):
raise UserError('Hanya Logistic yang bisa mengubah shipping method')
def do_unreserve(self):
- if not self._context.get('darimana') == 'sale.order':
+ group_id = self.env.ref('indoteknik_custom.group_role_it').id
+ users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])])
+ if not self._context.get('darimana') == 'sale.order' and self.env.user.id not in users_in_group.mapped('id'):
self.sale_id.unreserve_id = self.id
return self._create_approval_notification('Logistic')
res = super(StockPicking, self).do_unreserve()
current_time = datetime.datetime.utcnow()
self.date_unreserve = current_time
+ # self.check_state_reserve()
return res
+ # def check_state_reserve(self):
+ # do = self.search([
+ # ('state', 'not in', ['cancel', 'draft', 'done']),
+ # ('picking_type_code', '=', 'outgoing')
+ # ])
+
+ # for rec in do:
+ # rec.state_reserve = 'ready'
+ # rec.date_reserved = datetime.datetime.utcnow()
+
+ # for line in rec.move_ids_without_package:
+ # if line.product_uom_qty > line.reserved_availability:
+ # rec.state_reserve = 'waiting'
+ # rec.date_reserved = ''
+ # break
+
+ def check_state_reserve(self):
+ picking = self.search([
+ ('state', 'not in', ['cancel', 'draft', 'done']),
+ ('picking_type_code', '=', 'outgoing')
+ ])
+
+ for data in picking:
+ fullfilment = self.env['sales.order.fullfillment'].search([
+ ('sales_order_id', '=', data.sale_id.id)
+ ])
+
+ data.state_reserve = 'ready'
+ data.date_reserved = datetime.datetime.utcnow()
+ for rec in fullfilment:
+ if rec.reserved_from not in ['Inventory On Hand', 'Reserved from stock', 'Free Stock']:
+ data.state_reserve = 'waiting'
+ data.date_reserved = ''
+ break
+
def _create_approval_notification(self, approval_role):
title = 'Warning'
message = f'Butuh approval sales untuk unreserved'
@@ -273,6 +363,7 @@ class StockPicking(models.Model):
current_time = datetime.datetime.utcnow()
self.real_shipping_id = self.sale_id.real_shipping_id
self.date_availability = current_time
+ # self.check_state_reserve()
return res
def ask_approval(self):
@@ -419,6 +510,7 @@ class StockPicking(models.Model):
res = super(StockPicking, self).button_validate()
self.calculate_line_no()
self.date_done = datetime.datetime.utcnow()
+ self.state_reserve = 'done'
return res
@api.model