summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-12-27 10:13:47 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-12-27 10:13:47 +0700
commit624e4077925cf1517097da015076dd4385cf286c (patch)
treee6e677101b2d7e154fdeaa9e1e43621e3013775a
parent8a10587c8582ed68944634928c9a7c34d3321dbe (diff)
validate if product have po
-rw-r--r--indoteknik_custom/models/automatic_purchase.py21
-rw-r--r--indoteknik_custom/models/purchasing_job.py1
-rw-r--r--indoteknik_custom/models/sales_order_purchase_match.py4
-rw-r--r--indoteknik_custom/views/purchasing_job.xml1
4 files changed, 25 insertions, 2 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)],
diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py
index 43da2458..09c202d9 100644
--- a/indoteknik_custom/models/purchasing_job.py
+++ b/indoteknik_custom/models/purchasing_job.py
@@ -18,6 +18,7 @@ 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)
diff --git a/indoteknik_custom/models/sales_order_purchase_match.py b/indoteknik_custom/models/sales_order_purchase_match.py
index f5436335..042d5855 100644
--- a/indoteknik_custom/models/sales_order_purchase_match.py
+++ b/indoteknik_custom/models/sales_order_purchase_match.py
@@ -10,8 +10,8 @@ class SalesOrderPurchaseMatch(models.Model):
_name = 'sales.order.purchase.match'
sales_order_id = fields.Many2one('sale.order', string='Sale Order', index=True, required=True, ondelete='cascade')
- purchase_order_id = fields.Many2one('purchase.order', string='SO')
- purchase_line_id = fields.Many2one('purchase.order.line', string='SO Line')
+ purchase_order_id = fields.Many2one('purchase.order', string='PO')
+ purchase_line_id = fields.Many2one('purchase.order.line', string='PO Line')
product_id = fields.Many2one('product.product', string='Product')
qty_so = fields.Float(string='Qty SO')
qty_po = fields.Float(string='Qty PO')
diff --git a/indoteknik_custom/views/purchasing_job.xml b/indoteknik_custom/views/purchasing_job.xml
index 42dfd359..e9d83ba5 100644
--- a/indoteknik_custom/views/purchasing_job.xml
+++ b/indoteknik_custom/views/purchasing_job.xml
@@ -13,6 +13,7 @@
<field name="incoming"/>
<field name="outgoing"/>
<field name="action"/>
+ <field name="is_po"/>
</tree>
</field>
</record>