From 21f7c7a9b5ad175994b0824f82f9459feed3ca90 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 31 May 2023 14:09:59 +0700 Subject: add calculate all so status function --- indoteknik_custom/models/sale_order.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 85d7e595..d7b4331a 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -116,6 +116,33 @@ class SaleOrder(models.Model): sale.so_status = 'terproses' _logger.info('Calculate SO Status %s' % sale.id) + def _calculate_all_so_status(self, limit=500): + so_state = ['sale'] + sales = self.env['sale.order'].search([ + ('state', 'in', so_state), + # ('so_status', '!=', 'terproses'), + ], order='id desc', limit=limit) + for sale in sales: + sum_qty_ship = sum_qty_so = 0 + have_outstanding_pick = False + + for pick in sale.picking_ids: + if pick.state == 'draft' or pick.state == 'assigned' or pick.state == 'confirmed' or pick.state == 'waiting': + have_outstanding_pick = True + + for so_line in sale.order_line: + sum_qty_so += so_line.product_uom_qty + sum_qty_ship += so_line.qty_delivered + + if have_outstanding_pick: + if sum_qty_so > sum_qty_ship > 0: + sale.so_status = 'sebagian' + else: + sale.so_status = 'menunggu' + else: + sale.so_status = 'terproses' + _logger.info('Calculate All SO Status %s' % sale.id) + def calculate_so_status(self): so_state = ['sale'] sales = self.env['sale.order'].search([ -- cgit v1.2.3 From aff9fdd49543648bfed395fff0c86af5b0269686 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 2 Jun 2023 14:16:33 +0700 Subject: add feature generate payment link midtrans --- indoteknik_custom/models/sale_order.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d7b4331a..d021934f 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -5,6 +5,9 @@ import logging import warnings import random import string +import requests +import math +import json _logger = logging.getLogger(__name__) @@ -74,6 +77,36 @@ class SaleOrder(models.Model): notification = fields.Char(string='Notification', help='Dapat membantu error dari approval') delivery_service_type = fields.Char(string='Delivery Service Type', help='data dari rajaongkir') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') + payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') + + def generate_payment_link_midtrans_sales_order(self): + # midtrans_url = 'https://app.sandbox.midtrans.com/snap/v1/transactions' # dev - sandbox + # midtrans_auth = 'Basic U0ItTWlkLXNlcnZlci1uLVY3ZDJjMlpCMFNWRUQyOU95Q1dWWXA6' # dev - sandbox + midtrans_url = 'https://app.midtrans.com/snap/v1/transactions' # production + midtrans_auth = 'Basic TWlkLXNlcnZlci1SbGMxZ2gzWGpSVW5scl9JblZzTV9OTnU6' # production + so_number = self.name + so_number = so_number.replace('/', '-') + so_grandtotal = math.floor(self.grand_total) + headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': midtrans_auth, + } + + json_data = { + 'transaction_details': { + 'order_id': so_number, + 'gross_amount': so_grandtotal, + }, + 'credit_card': { + 'secure': True, + }, + } + + response = requests.post(midtrans_url, headers=headers, json=json_data).json() + lookup_json = json.dumps(response, indent=4, sort_keys=True) + redirect_url = json.loads(lookup_json)['redirect_url'] + self.payment_link_midtrans = str(redirect_url) @api.model def _generate_so_access_token(self, limit=50): -- cgit v1.2.3 From 7ffcb706cfbacdc7abf11c239073acadaae469a7 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 5 Jun 2023 09:43:28 +0700 Subject: fix compute grand total in sales order --- indoteknik_custom/models/sale_order.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d021934f..735a467c 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -425,7 +425,10 @@ class SaleOrder(models.Model): def _compute_grand_total(self): for order in self: - order.grand_total = order.delivery_amt + order.amount_total + if order.shipping_cost_covered == 'customer': + order.grand_total = order.delivery_amt + order.amount_total + else: + order.grand_total = order.amount_total class SaleOrderLine(models.Model): -- cgit v1.2.3 From 242bac3811359cdf80954fd3ef82a04a2537410b Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 7 Jun 2023 11:41:11 +0700 Subject: add validation can sell product in sale order --- indoteknik_custom/models/sale_order.py | 37 +++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 735a467c..1bdc7f7d 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -228,7 +228,7 @@ class SaleOrder(models.Model): order.have_outstanding_invoice = False def _have_outstanding_picking(self): - picking_state = ['done', 'confirmed', 'draft', 'cancel'] + picking_state = ['done', 'confirmed', 'draft'] for order in self: if not order.picking_ids: order.have_outstanding_picking = False @@ -309,6 +309,9 @@ class SaleOrder(models.Model): if not order.carrier_id: raise UserError("Shipping Method harus diisi") for line in order.order_line: + # must add product can sell validation + if not line.product_id.product_tmpl_id.sale_ok: + raise UserError('Product ini belum bisa dijual, harap hubungi finance') if not line.product_id or line.product_id.type == 'service': continue if line.product_id.id == 232383: @@ -326,12 +329,15 @@ class SaleOrder(models.Model): def action_cancel(self): # TODO stephan prevent cancel if have invoice, do, and po + if self._name != 'sale.order': + return super(SaleOrder, self).action_cancel() + if self.have_outstanding_invoice: raise UserError("Invoice harus di Cancel dahulu") - # elif self.have_outstanding_picking: - # raise UserError("DO harus di Cancel dahulu") - # elif self.have_outstanding_po: - # raise UserError("PO harus di Cancel dahulu") + elif self.have_outstanding_picking: + raise UserError("DO harus di Cancel dahulu") + elif self.have_outstanding_po: + raise UserError("PO harus di Cancel dahulu") self.approval_status = False return super(SaleOrder, self).action_cancel() @@ -347,6 +353,9 @@ class SaleOrder(models.Model): raise UserError("Shipping Method harus diisi") # approval1 = approval2 = 0 for line in order.order_line: + # must add product can sell validation + if not line.product_id.product_tmpl_id.sale_ok: + raise UserError('Product ini belum bisa dijual, harap hubungi finance') if not line.product_id or line.product_id.type == 'service': continue if line.product_id.id == 232383: @@ -485,15 +494,15 @@ class SaleOrderLine(models.Model): if not self.product_id or self.product_id.type == 'service': return elif self.product_id.categ_id.id == 34: # finish good / manufacturing only - print('a') - bom = self.env['mrp.bom'].search( - [('product_tmpl_id', '=', self.product_id.product_tmpl_id.id)] - , limit=1) - cost = 0 - for line in bom.bom_line_ids: - purchase_price = self.env['purchase.pricelist'].search( - [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', line.product_id.id)], limit=1) - cost += purchase_price.product_price + # bom = self.env['mrp.bom'].search( + # [('product_tmpl_id', '=', self.product_id.product_tmpl_id.id)] + # , limit=1) + # cost = 0 + # for line in bom.bom_line_ids: + # purchase_price = self.env['purchase.pricelist'].search( + # [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', line.product_id.id)], limit=1) + # cost += purchase_price.product_price + cost = self.product_id.standard_price self.purchase_price = cost else: purchase_price = self.env['purchase.pricelist'].search( -- cgit v1.2.3 From b0effc107cd0dcb1d9f5a458a00b2c1170edf1e8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 13 Jun 2023 13:38:21 +0700 Subject: Menambahkan detail validasi approve/confirm so jika barang tidak dijual --- indoteknik_custom/models/sale_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 1bdc7f7d..e592326d 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -311,7 +311,7 @@ class SaleOrder(models.Model): for line in order.order_line: # must add product can sell validation if not line.product_id.product_tmpl_id.sale_ok: - raise UserError('Product ini belum bisa dijual, harap hubungi finance') + raise UserError('Product %s belum bisa dijual, harap hubungi finance' % line.product_id.display_name) if not line.product_id or line.product_id.type == 'service': continue if line.product_id.id == 232383: @@ -355,7 +355,7 @@ class SaleOrder(models.Model): for line in order.order_line: # must add product can sell validation if not line.product_id.product_tmpl_id.sale_ok: - raise UserError('Product ini belum bisa dijual, harap hubungi finance') + raise UserError('Product %s belum bisa dijual, harap hubungi finance' % line.product_id.display_name) if not line.product_id or line.product_id.type == 'service': continue if line.product_id.id == 232383: -- cgit v1.2.3 From 1cca590f07fd84a33626e5fc965924c617d8e287 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 13 Jun 2023 13:46:23 +0700 Subject: Bug fix error input note on sale order line validation --- indoteknik_custom/models/sale_order.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e592326d..cefba3da 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -309,11 +309,11 @@ class SaleOrder(models.Model): if not order.carrier_id: raise UserError("Shipping Method harus diisi") for line in order.order_line: + if not line.product_id or line.product_id.type == 'service': + continue # must add product can sell validation if not line.product_id.product_tmpl_id.sale_ok: raise UserError('Product %s belum bisa dijual, harap hubungi finance' % line.product_id.display_name) - if not line.product_id or line.product_id.type == 'service': - continue if line.product_id.id == 232383: raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price: @@ -353,11 +353,11 @@ class SaleOrder(models.Model): raise UserError("Shipping Method harus diisi") # approval1 = approval2 = 0 for line in order.order_line: + if not line.product_id or line.product_id.type == 'service': + continue # must add product can sell validation if not line.product_id.product_tmpl_id.sale_ok: raise UserError('Product %s belum bisa dijual, harap hubungi finance' % line.product_id.display_name) - if not line.product_id or line.product_id.type == 'service': - continue if line.product_id.id == 232383: raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: -- cgit v1.2.3 From f6b57e41f73c0a64e64397223bbba17aa45de0f1 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 15 Jun 2023 08:53:42 +0700 Subject: make so_status didnt copy while duplicate sales order --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index cefba3da..cbc6a60a 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -53,7 +53,7 @@ class SaleOrder(models.Model): ('terproses', 'Terproses'), ('sebagian', 'Sebagian Diproses'), ('menunggu', 'Menunggu Diproses'), - ]) + ], copy=False) partner_purchase_order_name = fields.Char(string='Nama PO Customer', copy=False, help="Nama purchase order customer, diisi oleh customer melalui website.", tracking=3) partner_purchase_order_description = fields.Text(string='Keterangan PO Customer', copy=False, help="Keterangan purchase order customer, diisi oleh customer melalui website.", tracking=3) partner_purchase_order_file = fields.Binary(string='File PO Customer', copy=False, help="File purchase order customer, diisi oleh customer melalui website.") -- cgit v1.2.3