summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-06-15 15:47:05 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-06-15 15:47:05 +0700
commit55c67c71b04fce80c635b3a58d91c8bcb02e17c8 (patch)
treeed8833b969800e36b887b4134c14dab89d3b91c7 /indoteknik_custom/models/sale_order.py
parent1f2995a85428ac4335123bd33d48ae17d3c9f36f (diff)
parent24649f8e939484759ef34e5e68f251d951f63c02 (diff)
Merge commit '24649f8e939484759ef34e5e68f251d951f63c02'
Conflicts: indoteknik_custom/__manifest__.py indoteknik_custom/security/ir.model.access.csv
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
-rwxr-xr-xindoteknik_custom/models/sale_order.py104
1 files changed, 88 insertions, 16 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 85d7e595..cbc6a60a 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__)
@@ -50,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.")
@@ -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):
@@ -116,6 +149,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([
@@ -168,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
@@ -251,6 +311,9 @@ class SaleOrder(models.Model):
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 line.product_id.id == 232383:
raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara'))
if not line.vendor_id or not line.purchase_price:
@@ -266,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()
@@ -289,6 +355,9 @@ class SaleOrder(models.Model):
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 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:
@@ -365,7 +434,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):
@@ -422,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(