From 3ef9d136bd238464de7ff0a224b1a68a9b7bb1f3 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 9 Aug 2023 10:32:32 +0700 Subject: add new condition email po --- indoteknik_custom/models/purchase_order.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 38e617e7..d73f9037 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -187,13 +187,21 @@ class PurchaseOrder(models.Model): def button_confirm(self): res = super(PurchaseOrder, self).button_confirm() + if self.total_percent_margin < self.total_so_percent_margin and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: raise UserError("Beda Margin dengan Sales, harus approval Manager") if not self.sale_order_id and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: raise UserError("Tidak ada link dengan SO, harus approval Manager") + send_email = False for line in self.order_line: if not line.product_id.purchase_ok: - raise UserError("Terdapat barang yang tidak bisa di proses") + raise UserError("Terdapat barang yang tidak bisa diproses") + if line.price_vendor != 0 and line.price_unit != line.price_vendor: + send_email = True + break + + if send_email: + self._send_mail() self.approval_status = 'approved' self.po_status = 'menunggu' @@ -213,10 +221,6 @@ class PurchaseOrder(models.Model): template.send_mail(self.id, force_send=True) def po_approve(self): - for line in self.order_line: - if line.price_unit != line.price_vendor: - self._send_mail() - if self.env.user.is_leader or self.env.user.is_purchasing_manager: raise UserError("Bisa langsung Confirm") elif self.total_percent_margin == self.total_so_percent_margin and self.sale_order_id: -- cgit v1.2.3