diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-10-25 09:03:36 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-10-25 09:03:36 +0700 |
| commit | af190fa1e5e9301d84307b39b1927f77d3f0ee21 (patch) | |
| tree | 3c070466253f4896d5a130fb45bf254d2952a146 | |
| parent | a7be93f4825967807f12e6bfbebcf090af8500fa (diff) | |
fix bug date reserved
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 73 | ||||
| -rw-r--r-- | indoteknik_custom/views/stock_picking.xml | 4 |
2 files changed, 59 insertions, 18 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 2a73d631..df72dadf 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -110,43 +110,78 @@ class StockPicking(models.Model): 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 - }) - + # 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 [{ + "name": line.product_id.name, + "description": line.name, + "value": line.price_unit, + "quantity": line.product_uom_qty, + "weight": line.weight + } for line in lines] + + # Items untuk pengiriman standard + items_data_standard = build_items_data(products) + + # Items untuk pengiriman instant, mengambil product_id dari move_line_ids_without_package + items_data_instant = [] + for move_line in self.move_line_ids_without_package: + # Mencari baris di sale.order.line berdasarkan product_id dari move_line + order_line = self.env['sale.order.line'].search([ + ('order_id', '=', self.sale_id.id), + ('product_id', '=', move_line.product_id.id) + ], limit=1) + + if order_line: + items_data_instant.append({ + "name": order_line.product_id.name, + "description": order_line.name, + "value": order_line.price_unit, + "quantity": move_line.qty_done, # Menggunakan qty_done dari move_line + "weight": order_line.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", + "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 + "courier_type": "reg", + "courier_company": self.carrier_id.name.lower(), + "delivery_type": "now", + "destination_postal_code": self.real_shipping_id.zip, + "items": items_data_standard } + # Cek jika pengiriman instant atau same_day + if "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 + }) + headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } - response = requests.post(url, headers=headers, data=json.dumps(payload)) + # Kirim request ke Biteship + response = requests.post(url, headers=headers, json=payload) if response.status_code == 201: return response.json() @@ -218,7 +253,9 @@ class StockPicking(models.Model): ]) data.state_reserve = 'ready' - data.date_reserved = datetime.datetime.utcnow() + if not data.date_reserved: + 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' diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index d713edbc..b5087e35 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -52,6 +52,10 @@ type="object" attrs="{'invisible': ['|', ('state', '!=', 'done'), ('name', 'ilike', 'out')]}" /> + <button name="action_send_to_biteship" + string="Biteship" + type="object" + /> </button> <field name="backorder_id" position="after"> <field name="summary_qty_detail"/> |
