From f78fcf1c60160540221e240338acc54dfc9beb74 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 6 Feb 2025 11:22:06 +0700 Subject: add po count on po and add validation duplicate contact --- indoteknik_custom/models/purchase_order.py | 1 + indoteknik_custom/models/res_partner.py | 13 +++++++++++++ indoteknik_custom/views/purchase_order.xml | 3 +++ 3 files changed, 17 insertions(+) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 12a94730..54d771ba 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -86,6 +86,7 @@ class PurchaseOrder(models.Model): total_cost_service = fields.Float(string='Total Cost Service') total_delivery_amt = fields.Float(string='Total Delivery Amt') store_name = fields.Char(string='Nama Toko') + purchase_order_count = fields.Integer('Purchase Order Count', related='partner_id.purchase_order_count') @api.onchange('total_cost_service') def _onchange_total_cost_service(self): diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index 5322515a..3c5e0e05 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -183,6 +183,19 @@ class ResPartner(models.Model): # # raise UserError('You name it') # return res + + @api.constrains('name') + def _check_duplicate_name(self): + for record in self: + if record.name: + # Mencari partner lain yang memiliki nama sama (case-insensitive) + existing_partner = self.env['res.partner'].search([ + ('id', '!=', record.id), # Hindari mencocokkan diri sendiri + ('name', 'ilike', record.name) # Case-insensitive search + ], limit=1) + + if existing_partner: + raise ValidationError(f"Nama '{record.name}' sudah digunakan oleh partner lain!") def write(self, vals): # Fungsi rekursif untuk meng-update semua child, termasuk child dari child diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 022937f4..f7f38686 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -51,6 +51,9 @@ + + + -- cgit v1.2.3