diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-12-27 13:37:37 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-12-27 13:37:37 +0700 |
| commit | 5eabba4b2a8a3e1ec233f60c6aa7a0fa7414fd51 (patch) | |
| tree | d968166a0564703f9ed7fdeec2a57240db6722a2 /indoteknik_custom/models/automatic_purchase.py | |
| parent | 624e4077925cf1517097da015076dd4385cf286c (diff) | |
alert if so have matches po
Diffstat (limited to 'indoteknik_custom/models/automatic_purchase.py')
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 29 |
1 files changed, 13 insertions, 16 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') |
