summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-12-27 13:37:37 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-12-27 13:37:37 +0700
commit5eabba4b2a8a3e1ec233f60c6aa7a0fa7414fd51 (patch)
treed968166a0564703f9ed7fdeec2a57240db6722a2
parent624e4077925cf1517097da015076dd4385cf286c (diff)
alert if so have matches po
-rw-r--r--indoteknik_custom/models/automatic_purchase.py29
-rw-r--r--indoteknik_custom/models/purchasing_job.py3
-rw-r--r--indoteknik_custom/views/purchasing_job.xml1
3 files changed, 14 insertions, 19 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index 5ab05aed..ed35835e 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -46,24 +46,21 @@ class AutomaticPurchase(models.Model):
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)
- ])
+ # TODO user can't create po if in so exist matches po
+ sale_ids = self.env['automatic.purchase.sales.match'].search([
+ ('automatic_purchase_id', '=', self.id),
+ ])
- # 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])
+ names = []
+ for sale in sale_ids:
+ names.append(sale.sale_id.name)
+
+ count = len(sale_ids)
+ 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')
diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py
index 09c202d9..7ac678c4 100644
--- a/indoteknik_custom/models/purchasing_job.py
+++ b/indoteknik_custom/models/purchasing_job.py
@@ -18,13 +18,12 @@ class PurchasingJob(models.Model):
incoming = fields.Float(string="Incoming")
outgoing = fields.Float(string="Outgoing")
action = fields.Char(string="Status")
- is_po = fields.Boolean(string='Is PO')
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute("""
CREATE OR REPLACE VIEW %s AS (
- select product_id as id, product_id, brand, item_code, product, onhand, incoming, outgoing, action
+ select product_id as id, product_id, brand, item_code, product, onhand, incoming, outgoing, action
from v_procurement_monitoring_by_product
where action = 'kurang beli'
)
diff --git a/indoteknik_custom/views/purchasing_job.xml b/indoteknik_custom/views/purchasing_job.xml
index e9d83ba5..42dfd359 100644
--- a/indoteknik_custom/views/purchasing_job.xml
+++ b/indoteknik_custom/views/purchasing_job.xml
@@ -13,7 +13,6 @@
<field name="incoming"/>
<field name="outgoing"/>
<field name="action"/>
- <field name="is_po"/>
</tree>
</field>
</record>