summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/automatic_purchase.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-04-13 09:26:37 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-04-13 09:26:37 +0700
commit610b0dde2b83d539b153db5f71b68da441217eed (patch)
tree82ba9554aa2ff0c8002f08d34d5324d5bce92d95 /indoteknik_custom/models/automatic_purchase.py
parentef05fc18109974354f7a41b2c16381614fc4b1b6 (diff)
feedback sj
Diffstat (limited to 'indoteknik_custom/models/automatic_purchase.py')
-rw-r--r--indoteknik_custom/models/automatic_purchase.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index 3eba0d62..a8a67569 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -68,7 +68,6 @@ class AutomaticPurchase(models.Model):
if count > 0:
raise UserError('Ada sekitar %s SO Yang sudah create PO, berikut SO nya: %s' % (count, ', '.join(names)))
-
def create_po_from_automatic_purchase(self):
if not self.purchase_lines:
raise UserError('Tidak ada Lines, belum bisa create PO')
@@ -151,10 +150,35 @@ class AutomaticPurchase(models.Model):
self.notification = 'PO Created successfully'
self.is_po = True
-
+
+ def check_qty_po(self):
+ for lines in self.purchase_lines:
+ purchasing_job = self.env['v.purchasing.job'].search([
+ ('product_id', '=', lines.product_id.id)
+ ], limit=1)
+
+ po = self.env['purchase.order'].search([
+ ('product_id', '=', lines.product_id.id),
+ ('order_sales_match_line.sale_id', '=', lines.automatic_purchase_id.sales_match.sale_id),
+ ('state', 'not in', ['cancel']),
+ ('from_apo', '=', True)
+ ], limit=1)
+
+ if not purchasing_job:
+ raise UserError('Beberapa product sudah terbuat po dan sudah terconfirm')
+
+ for line in po.order_line:
+ qty_pj = po.product_qty + lines.qty_purchase
+ qty_outgoing_pj = po.qty_outgoing
+
+ if qty_pj > qty_outgoing_pj:
+ raise UserError('Qty yang anda beli lebih dari qty outgoing')
+
def create_po_by_vendor(self, vendor_id):
current_time = datetime.now()
+ self.check_qty_po()
+
PRODUCT_PER_PO = 20
auto_purchase_line = self.env['automatic.purchase.line']