diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-10-22 15:26:24 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-10-22 15:26:24 +0700 |
| commit | ecc3621e449af1393836cf67ca34d91ed32eea5c (patch) | |
| tree | ff9162dc5ef50e5e974159df804bd8f5e991656a | |
| parent | c99e4d67c037a781b79e0ed198899d5f5c4a153b (diff) | |
cr status reserve
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 82 |
1 files changed, 74 insertions, 8 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index a5482f9d..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): @@ -107,6 +107,51 @@ class StockPicking(models.Model): ('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): @@ -145,18 +190,39 @@ class StockPicking(models.Model): 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): - do = self.search([ + 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) + ]) - for rec in do: - rec.state_reserve = 'ready' - - for line in rec.move_ids_without_package: - if line.product_uom_qty > line.reserved_availability: - rec.state_reserve = 'waiting' + 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): |
