diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-05-23 14:20:57 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-05-23 14:20:57 +0700 |
| commit | ca3455a3054e2953fb8b274ba5a4e65abcf3d257 (patch) | |
| tree | c3dca3015cfbb4efaf4de4e2463db8fe8bd12d6e /fixco_custom/models/detail_order.py | |
| parent | e38dcc63819f47ce32d52494a6b7277441c6c66a (diff) | |
Note Development
Diffstat (limited to 'fixco_custom/models/detail_order.py')
| -rw-r--r-- | fixco_custom/models/detail_order.py | 183 |
1 files changed, 97 insertions, 86 deletions
diff --git a/fixco_custom/models/detail_order.py b/fixco_custom/models/detail_order.py index 7bb3aec..466544f 100644 --- a/fixco_custom/models/detail_order.py +++ b/fixco_custom/models/detail_order.py @@ -23,6 +23,7 @@ class DetailOrder(models.Model): ('so_confirm', 'SO Confirm'), ('done', 'Done'), ('failed', 'Failed'), + ('already_so', 'SO Already Created'), ], 'Execute Status') sale_id = fields.Many2one('sale.order', 'Sale Order') picking_id = fields.Many2one('stock.picking', 'Picking') @@ -83,8 +84,7 @@ class DetailOrder(models.Model): self.execute_status = 'detail_order' else: self.write({ - 'execute_status': 'failed', - 'json_ginee': json.dumps({ + 'message_error': json.dumps({ 'error': f"Request failed with status code {response.status_code}", 'response': response.text }) @@ -92,8 +92,7 @@ class DetailOrder(models.Model): except Exception as e: self.write({ - 'execute_status': 'failed', - 'json_ginee': json.dumps({ + 'message_error': json.dumps({ 'error': str(e) }) }) @@ -143,7 +142,11 @@ class DetailOrder(models.Model): limit=1 ) if not product: - raise UserError(_("Product not found for SKU: %s") % item.get('sku')) + product = self.env['product.product'].search( + [('default_code', '=', 'PL-LN0760')], + limit=1 + ) + # raise UserError(_("Product not found for SKU: %s") % item.get('sku')) line_data = { 'product_id': product.id, @@ -161,35 +164,43 @@ class DetailOrder(models.Model): order_lines = self.prepare_data_so_line(json_data) order_id, order_status, print_info = self.get_order_id_detail() - if order_status == 'READY_TO_SHIP' and print_info == 'NOT_PRINTED': - # if order_status == 'SHIPPING' and print_info == 'PRINTED': - data['order_line'] = order_lines - - sale_order = self.env['sale.order'].create(data) - - self.sale_id = sale_order.id - sale_order.action_confirm() + if order_status != 'PENDING_PAYMENT': + if order_status == 'PARTIALLY_PAID' or order_status == 'PAID': + data['order_line'] = order_lines + + sale_order = self.env['sale.order'].create(data) + + self.sale_id = sale_order.id + sale_order.order_reference = order_id + sale_order.action_confirm() + - self.picking_id = sale_order.picking_ids[0].id + self.picking_id = sale_order.picking_ids[0].id - self.execute_status = 'so_confirm' - elif order_status == 'READY_TO_SHIP' and print_info == 'PRINTED': - data['order_line'] = order_lines - - sale_order = self.env['sale.order'].create(data) - - self.sale_id = sale_order.id - sale_order.action_confirm() + self.picking_id.order_reference = order_id - self.picking_id = sale_order.picking_ids[0].id - self.picking_id.sync_qty_reserved_qty_done() + self.execute_status = 'so_confirm' + else: + sale_orders = self.env['sale.order'].search([('order_reference', '=', order_id)]) + if not sale_orders: + data['order_line'] = order_lines + + sale_order = self.env['sale.order'].create(data) + + self.sale_id = sale_order.id + sale_order.order_reference = order_id + sale_order.action_confirm() - self.execute_status = 'so_confirm' - + self.picking_id = sale_order.picking_ids[0].id + self.picking_id.order_reference = order_id + + self.execute_status = 'so_confirm' + else: + self.sale_id = sale_orders.id + self.execute_status = 'already_so' except Exception as e: self.write({ - 'execute_status': 'failed', 'message_error': json.dumps({ 'error': str(e) }) @@ -206,72 +217,72 @@ class DetailOrder(models.Model): # check print do section - def get_order_id_check_print(self): - try: - if self.detail_order: - json_data = json.loads(self.detail_order) - order_id = json_data.get('data', {})[0].get('orderId') - if not order_id: - raise UserError(_("Order ID not found in JSON data")) - return order_id - raise UserError(_("No JSON data available")) - except json.JSONDecodeError: - raise UserError(_("Invalid JSON format in check_print field")) - except Exception as e: - raise UserError(_("Error extracting order ID: %s") % str(e)) + # def get_order_id_check_print(self): + # try: + # if self.detail_order: + # json_data = json.loads(self.detail_order) + # order_id = json_data.get('data', {})[0].get('orderId') + # if not order_id: + # raise UserError(_("Order ID not found in JSON data")) + # return order_id + # raise UserError(_("No JSON data available")) + # except json.JSONDecodeError: + # raise UserError(_("Invalid JSON format in check_print field")) + # except Exception as e: + # raise UserError(_("Error extracting order ID: %s") % str(e)) - def process_queue_item_check_print(self, limit=100): - domain = [('picking_id.state', 'not in', ['done', 'cancel'])] - records = self.search(domain, order='create_date asc', limit=limit) - for rec in records: - rec.execute_queue_check_print() + # def process_queue_item_check_print(self, limit=100): + # domain = [('picking_id.state', 'not in', ['done', 'cancel'])] + # records = self.search(domain, order='create_date asc', limit=limit) + # for rec in records: + # rec.execute_queue_check_print() - def execute_queue_check_print(self): - try: - order_id = self.get_order_id_check_print() + # def execute_queue_check_print(self): + # try: + # order_id = self.get_order_id_check_print() - authorization = self.sign_request() - headers = { - 'Content-Type': 'application/json', - 'X-Advai-Country': 'ID', - 'Authorization': authorization - } + # authorization = self.sign_request() + # headers = { + # 'Content-Type': 'application/json', + # 'X-Advai-Country': 'ID', + # 'Authorization': authorization + # } - payload = { - "orderIds": [order_id] - } + # payload = { + # "orderIds": [order_id] + # } - url = "https://api.ginee.com/openapi/order/v1/batch-get" + # url = "https://api.ginee.com/openapi/order/v1/batch-get" - response = requests.post( - url, - headers=headers, - data=json.dumps(payload) - ) + # response = requests.post( + # url, + # headers=headers, + # data=json.dumps(payload) + # ) - if response.status_code == 200: - data = response.json() - self.detail_order = json.dumps(data) - detail_order = json.loads(self.detail_order) - if detail_order['data'][0]['printInfo']['labelPrintStatus'] == 'PRINTED': #ubah ke printed lagi nanti - self.picking_id.sync_qty_reserved_qty_done() - # self.sale_id.api_create_invoices(self.sale_id.id) - self.execute_status = 'done' - else: - self.write({ - 'execute_status': 'failed', - 'json_ginee': json.dumps({ - 'error': f"Request failed with status code {response.status_code}", - 'response': response.text - }) - }) + # if response.status_code == 200: + # data = response.json() + # self.detail_order = json.dumps(data) + # detail_order = json.loads(self.detail_order) + # if detail_order['data'][0]['printInfo']['labelPrintStatus'] == 'PRINTED': #ubah ke printed lagi nanti + # self.picking_id.sync_qty_reserved_qty_done() + # # self.sale_id.api_create_invoices(self.sale_id.id) + # self.execute_status = 'done' + # else: + # self.write({ + # 'execute_status': 'failed', + # 'json_ginee': json.dumps({ + # 'error': f"Request failed with status code {response.status_code}", + # 'response': response.text + # }) + # }) - except Exception as e: - self.write({ - 'execute_status': 'failed', - 'json_ginee': json.dumps({ - 'error': str(e) - }) - }) + # except Exception as e: + # self.write({ + # 'execute_status': 'failed', + # 'json_ginee': json.dumps({ + # 'error': str(e) + # }) + # })
\ No newline at end of file |
