diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-02-06 11:22:06 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-02-06 11:22:06 +0700 |
| commit | f78fcf1c60160540221e240338acc54dfc9beb74 (patch) | |
| tree | 6d52a44ed54f847e422da5c2b3794e70cf83c3af | |
| parent | e990d1d8af808fe2cc5f7218df12849f9ee370a9 (diff) | |
add po count on po and add validation duplicate contact
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 13 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 3 |
3 files changed, 17 insertions, 0 deletions
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 @@ <field name="approval_status" position="after"> <field name="approval_status_unlock" invisible="True"/> </field> + <field name="partner_id" position="after"> + <field name="purchase_order_count"/> + </field> <field name="incoterm_id" position="after"> <field name="amount_total_without_service"/> <field name="delivery_amt"/> |
