diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-09-29 17:59:26 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-09-29 17:59:26 +0700 |
| commit | 156507bd6de73802ae9ef32d344c59184e6f923a (patch) | |
| tree | 3e2947e087686267d68327bf5cab5a1d02c11c31 | |
| parent | 78811641ffa04c7930fe450f9222d21b5dfceb62 (diff) | |
Update sale_order.py
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 6e16c63e..5c868c67 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -49,7 +49,7 @@ class SaleOrder(models.Model): raise UserError("Tax di Header harus diisi") if not order.carrier_id: raise UserError("Shipping Method harus diisi") - approval1 = approval2 = 0 + # approval1 = approval2 = 0 for line in order.order_line: if not line.product_id or line.product_id.type == 'service': continue @@ -57,13 +57,19 @@ class SaleOrder(models.Model): raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) - if line.item_percent_margin <= 15 and not self.env.user.is_leader: # akbar or tyas - approval2 += 1 - elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: - approval1 += 1 - if approval2 > 0: + # if line.item_percent_margin <= 15 and not self.env.user.is_leader: # akbar or tyas + # approval2 += 1 + # elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: + # approval1 += 1 + # if approval2 > 0: + # order.approval_status = 'pengajuan2' + # elif approval1 > 0: + # order.approval_status = 'pengajuan1' + # else: + # raise UserError("Bisa langsung Confirm") + if order.total_percent_margin <= 15 and not self.env.user.is_leader: order.approval_status = 'pengajuan2' - elif approval1 > 0: + elif order.total_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: order.approval_status = 'pengajuan1' else: raise UserError("Bisa langsung Confirm") @@ -79,7 +85,7 @@ class SaleOrder(models.Model): raise UserError("Tax di Header harus diisi") if not order.carrier_id: raise UserError("Shipping Method harus diisi") - approval1 = approval2 = 0 + # approval1 = approval2 = 0 for line in order.order_line: if not line.product_id or line.product_id.type == 'service': continue @@ -87,15 +93,22 @@ class SaleOrder(models.Model): raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) - if line.item_percent_margin <= 15 and not self.env.user.is_leader: - approval2 += 1 - elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: - approval1 += 1 - if approval2 > 0: + # if line.item_percent_margin <= 15 and not self.env.user.is_leader: + # approval2 += 1 + # elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: + # approval1 += 1 + # if approval2 > 0: + # raise UserError("Harus diapprove oleh Pimpinan") + # elif approval1 > 0: + # raise UserError("Harus diapprove oleh Manager") + # order.approval_status = 'approved' + if order.total_percent_margin <= 15 and not self.env.user.is_leader: raise UserError("Harus diapprove oleh Pimpinan") - elif approval1 > 0: + elif order.total_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: raise UserError("Harus diapprove oleh Manager") - order.approval_status = 'approved' + else: + order.approval_status = 'approved' + return res def compute_total_margin(self): @@ -188,4 +201,7 @@ class SaleOrderLine(models.Model): super(SaleOrderLine, self).product_id_change() for line in self: if line.product_id and line.product_id.type == 'product': + purchase_price = self.env['purchase.pricelist'].search( + [('product_id', '=', self.product_id.id)], limit=1, order='product_price ASC') + line.vendor_id = purchase_price.vendor_id line.tax_id = line.order_id.sales_tax_id |
