summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-06-19 17:08:47 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-06-19 17:08:47 +0700
commite595c9ce8de2eb8c778b998cef58b2d85c29a6a7 (patch)
tree799c57e3e759ad4fe28b188bfbe58870f5159b64 /indoteknik_custom/models
parente59d33ea416afbe5d2e531f524be37c1eeef6015 (diff)
parent7ad6f514da84253dfed42efc18c3c9343d7cc052 (diff)
Merge branch 'nathan-dev' of bitbucket.org:altafixco/indoteknik-addons into nathan-dev
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/product_template.py21
-rwxr-xr-xindoteknik_custom/models/purchase_order.py27
-rwxr-xr-xindoteknik_custom/models/sale_monitoring.py15
-rwxr-xr-xindoteknik_custom/models/sale_monitoring_detail.py18
-rwxr-xr-xindoteknik_custom/models/sale_order.py4
-rw-r--r--indoteknik_custom/models/users.py4
6 files changed, 48 insertions, 41 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 9c480f4c..a4f8f031 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -211,7 +211,28 @@ class ProductProduct(models.Model):
usage = fields.Char(string='Usage')
specification = fields.Char(string='Specification')
material = fields.Char(string='Material')
+ qty_onhand_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_onhand_bandengan')
+ qty_incoming_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_incoming_bandengan')
+ def _get_qty_incoming_bandengan(self):
+ for product in self:
+ qty_incoming = self.env['stock.move'].search([
+ ('product_id', '=', product.id),
+ ('location_dest_id', '=', 57),
+ ('state', 'not in', ['done', 'cancel'])
+ ])
+ qty = sum(qty_incoming.mapped('product_uom_qty'))
+ product.qty_incoming_bandengan = qty
+
+ def _get_qty_onhand_bandengan(self):
+ for product in self:
+ qty_onhand = self.env['stock.quant'].search([
+ ('product_id', '=', product.id),
+ ('location_id', '=', 57)
+ ])
+ qty = sum(qty_onhand.mapped('quantity'))
+ product.qty_onhand_bandengan = qty
+
# def write(self, vals):
# if 'solr_flag' not in vals:
# for variant in self:
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 3b94e816..5aedb07b 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -151,38 +151,19 @@ class PurchaseOrder(models.Model):
self.order_line.unlink()
for order_line in self.sale_order_id.order_line:
if order_line.product_id.id and order_line.product_id.id not in products_exception:
- for order_line in self.sale_order_id.order_line:
-
- qty_onhand = self.env['stock.quant'].search([
- ('product_id', '=', order_line.product_id.id),
- ('location_id', '=', 57)
- ])
+ for order_line in self.sale_order_id.order_line:
- qty_incoming = self.env['stock.move'].search([
- ('product_id', '=', order_line.product_id.id),
- ('location_dest_id', '=', 57),
- ('state', 'not in', ['done', 'cancel'])
- ])
-
- qty_outgoing = self.env['stock.move'].search([
- ('product_id', '=', order_line.product_id.id),
- ('location_id', '=', 57),
- ('state', 'not in', ['done', 'cancel'])
- ])
-
- qty_total = sum(qty_onhand.mapped('quantity')) + sum(qty_incoming.mapped('product_uom_qty'))
-
- qty = qty_total - sum(qty_outgoing.mapped('product_uom_qty'))
+ qty_available = order_line.product_id.qty_onhand_bandengan + order_line.product_id.qty_incoming_bandengan - order_line.product_id.outgoing_qty
suggest = 'harus beli'
- if order_line.product_id.virtual_available > order_line.product_qty:
+ if qty_available > order_line.product_qty:
suggest = 'masih cukup'
values = {
'order_id': self.id,
'product_id': order_line.product_id.id,
'name': order_line.product_id.display_name,
'product_qty': order_line.product_qty,
- 'qty_available_store': qty,
+ 'qty_available_store': qty_available,
'suggest': suggest,
}
self.order_line.create(values)
diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py
index a3265a8b..e79ff9ab 100755
--- a/indoteknik_custom/models/sale_monitoring.py
+++ b/indoteknik_custom/models/sale_monitoring.py
@@ -20,6 +20,7 @@ class SaleMonitoring(models.Model):
date_order = fields.Datetime(string="Date Order")
status = fields.Char(string="Status")
po_number = fields.Char(string="PO Number")
+ qty_reserved = fields.Integer(string="Qty Reserved")
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
@@ -36,14 +37,14 @@ class SaleMonitoring(models.Model):
SUM(smd.qty_po_received) AS qty_po_received,
SUM(smd.qty_so_delivered) AS qty_so_delivered,
SUM(smd.qty_so_invoiced) AS qty_so_invoiced,
+ sum(smd.qty_reserved) as qty_reserved,
CASE
- WHEN SUM(qty_po) < SUM(qty_so) AND SUM(qty_po) <= 0 THEN 'Belum PO sama sekali'
- WHEN SUM(qty_po) < SUM(qty_so) THEN 'Belum PO full'
- WHEN SUM(qty_po_received) < SUM(qty_so) AND SUM(qty_po_received) <= 0 THEN 'Belum Received sama sekali'
- WHEN SUM(qty_po_received) < SUM(qty_so) THEN 'Belum Received full'
- WHEN SUM(qty_to_delivered) = SUM(qty_so) THEN 'SIAP KIRIM'
- WHEN SUM(qty_to_delivered) < SUM(qty_so) and SUM(qty_to_delivered) > 0 THEN 'KIRIM SISANYA'
- ELSE 'Belum Invoiced'
+ when sum(qty_so_invoiced) = sum(qty_so) then 'Invoiced'
+ when sum(qty_so_delivered) = sum(qty_so) then 'Delivered'
+ when sum(qty_reserved) >= sum(qty_so) then 'Siap kirim'
+ when sum(qty_po) + sum(qty_reserved) - sum(qty_po_received) < sum(qty_so) then 'Belum/Kurang PO'
+ when sum(qty_po_received) = 0 then 'Belum terima'
+ when sum(qty_po_received) < sum(qty_po) then 'Terima sebagian'
END AS status,
get_po_number(smd.sale_order_id) as po_number
FROM sale_monitoring_detail smd
diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py
index a578f67b..2bcda50c 100755
--- a/indoteknik_custom/models/sale_monitoring_detail.py
+++ b/indoteknik_custom/models/sale_monitoring_detail.py
@@ -21,6 +21,7 @@ class SaleMonitoringDetail(models.Model):
qty_so_invoiced = fields.Integer(string="Qty SO Invoiced")
date_order = fields.Datetime(string="Date Order")
status = fields.Char(string="Status")
+ qty_reserved = fields.Integer(string="Qty Reserved")
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
@@ -29,14 +30,12 @@ class SaleMonitoringDetail(models.Model):
SELECT
*,
CASE
- WHEN qty_so = qty_so_invoiced then 'Done'
- WHEN qty_po < qty_so AND qty_po <= 0 THEN 'Belum PO sama sekali'
- WHEN qty_po < qty_so THEN 'Belum PO full'
- WHEN qty_po_received < qty_so and qty_po_received <= 0 THEN 'Belum Received sama sekali'
- WHEN qty_po_received < qty_so THEN 'Belum Received full'
- WHEN qty_to_delivered = qty_so THEN 'SIAP KIRIM'
- WHEN qty_to_delivered < qty_so and qty_to_delivered > 0 THEN 'KIRIM SISANYA'
- ELSE 'Belum Invoiced'
+ when qty_so_invoiced = qty_so then 'Invoiced'
+ when qty_so_delivered = qty_so then 'Delivered'
+ when qty_reserved >= qty_so then 'Siap kirim'
+ when qty_po + qty_reserved - qty_po_received < qty_so then 'Belum/Kurang PO'
+ when qty_po_received = 0 then 'Belum terima'
+ when qty_po_received < qty_po then 'Terima sebagian'
END AS status
FROM
(
@@ -52,7 +51,8 @@ class SaleMonitoringDetail(models.Model):
sol.qty_invoiced AS qty_so_invoiced,
so.date_order AS date_order,
get_qty_po(so.id, sol.product_id) AS qty_po,
- get_qty_received(so.id, sol.product_id) AS qty_po_received
+ get_qty_received(so.id, sol.product_id) AS qty_po_received,
+ get_qty_reserved(so.id, sol.product_id) as qty_reserved
FROM sale_order so
JOIN sale_order_line sol ON sol.order_id = so.id
JOIN product_product p ON p.id = sol.product_id
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index e2693688..e99876c2 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -349,8 +349,8 @@ class SaleOrder(models.Model):
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_po:
+ # raise UserError("PO harus di Cancel dahulu")
self.approval_status = False
return super(SaleOrder, self).action_cancel()
diff --git a/indoteknik_custom/models/users.py b/indoteknik_custom/models/users.py
index 4904a33d..a2074c46 100644
--- a/indoteknik_custom/models/users.py
+++ b/indoteknik_custom/models/users.py
@@ -9,3 +9,7 @@ class Users(models.Model):
is_sales_manager = fields.Boolean(String='Sales Manager', help='Berhak melakukan Approval SO dengan margin 15-25')
is_leader = fields.Boolean(String='Leader', help='Berhak Approval SO Margin < 15 dan Approval PO')
is_accounting = fields.Boolean(String='Accounting', help='Berhak Approval Internal Use')
+
+ def notify_internal_users(self, message, title):
+ users = self.search([('share', '=', False)])
+ users.notify_info(message=message, title=title) \ No newline at end of file