summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-04-15 08:56:53 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-04-15 08:56:53 +0700
commit39f9f7626e601719a9dcd4e5b3143f0fce928224 (patch)
treeb6e293b9bdd352e2afc678959626a93ea6da49b5
parentbb00e1a54298bab88856e291ca8190f1823b1fcc (diff)
trying to fix bug automatic purchase
-rw-r--r--indoteknik_custom/models/automatic_purchase.py47
1 files changed, 23 insertions, 24 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index 8a44b747..9d61e5f3 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -152,33 +152,32 @@ class AutomaticPurchase(models.Model):
self.is_po = True
def check_qty_po(self):
- if self.apo_type == 'regular':
- 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')
+ 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', 'in', [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()
+ if self.apo_type == 'regular':
+ self.check_qty_po()
PRODUCT_PER_PO = 20