summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/automatic_purchase.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/automatic_purchase.py')
-rw-r--r--indoteknik_custom/models/automatic_purchase.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index 070db78f..5ab05aed 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -44,6 +44,25 @@ class AutomaticPurchase(models.Model):
vals['number'] = self.env['ir.sequence'].next_by_code('automatic.purchase') or '0'
result = super(AutomaticPurchase, self).create(vals)
return result
+
+ def validate_so_is_po(self):
+ #TODO user cant create po if in so exist matches po
+ for line in self.purchase_lines:
+ # Assuming that 'order_sales_match_line' is a field on the model 'sale.order'
+ sale_id = self.env['sale.order'].search([
+ ('id', '=', line.sale_id.id),
+ ('order_sales_match_line', '!=', False)
+ ])
+
+ # Check if there are multiple records
+ if len(sale_id) > 1:
+ raise UserError('Ada SO Yang sudah create PO, berikut SO nya: %s' % [sale.name for sale in sale_id])
+
+ # Check if there is exactly one record
+ if sale_id:
+ # Access the first record in the set
+ sale_id = sale_id[0]
+ raise UserError('Ada SO Yang sudah create PO, berikut SO nya: %s' % [sale.name for sale in sale_id])
def create_po_from_automatic_purchase(self):
if not self.purchase_lines:
@@ -51,6 +70,8 @@ class AutomaticPurchase(models.Model):
if self.is_po:
raise UserError('Sudah pernah di create PO')
+ self.validate_so_is_po()
+
current_time = datetime.now()
vendor_ids = self.env['automatic.purchase.line'].read_group(
[('automatic_purchase_id', '=', self.id), ('partner_id', '!=', False)],