summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xindoteknik_custom/models/sale_order.py84
1 files changed, 39 insertions, 45 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 4d1550aa..c643aa6d 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -13,8 +13,8 @@ class SaleOrder(models.Model):
'Total Percent Margin', compute='compute_total_margin',
help="Total % Margin in Sales Order Header")
approval_status = fields.Selection([
- ('pengajuan1', 'Approval Adela'),
- ('pengajuan2', 'Approval Tyas'),
+ ('pengajuan1', 'Approval Manager'),
+ ('pengajuan2', 'Approval Pimpinan'),
('approved', 'Approved'),
], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method')
@@ -33,55 +33,49 @@ class SaleOrder(models.Model):
self.have_visit_service = True
def sale_order_approve(self):
- raise UserError("Bisa langsung Confirm")
- # for order in self:
- # if order.state == 'cancel' or order.state == 'done' or order.state == 'sale':
- # raise UserError("Status harus draft atau sent")
- # approval1 = approval2 = 0
- # for line in order.order_line:
- # if not line.product_id:
- # continue
- # if (line.item_percent_margin <= 15 or line.item_percent_margin == 100) and (
- # self.env.user.id != 6 and self.env.user.id != 7):
- # approval2 += 1
- # # order.approval_status = "pengajuan2"
- # # break
- # elif line.item_percent_margin <= 40 and (self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7):
- # approval1 += 1
- # # order.approval_status = 'pengajuan1'
- # # break
- # if approval2 > 0:
- # order.approval_status = 'pengajuan2'
- # elif approval1 > 0:
- # order.approval_status = 'pengajuan1'
- # else:
- # raise UserError("Bisa langsung Confirm")
+ # raise UserError("Bisa langsung Confirm")
+ for order in self:
+ if order.state == 'cancel' or order.state == 'done' or order.state == 'sale':
+ raise UserError("Status harus draft atau sent")
+ approval1 = approval2 = 0
+ for line in order.order_line:
+ if not line.product_id or line.product_id.type == 'service':
+ continue
+ if (line.item_percent_margin <= 15) and (self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas
+ approval2 += 1
+ elif line.item_percent_margin <= 25 and (self.env.user.id != 19 and self.env.user.id != 6 and self.env.user.id != 7):
+ approval1 += 1
+ if approval2 > 0:
+ order.approval_status = 'pengajuan2'
+ elif approval1 > 0:
+ order.approval_status = 'pengajuan1'
+ else:
+ raise UserError("Bisa langsung Confirm")
def action_cancel(self):
- # self.approval_status = False
+ self.approval_status = False
return super(SaleOrder, self).action_cancel()
def action_confirm(self):
res = super(SaleOrder, self).action_confirm()
- # for line in self.order_line:
- # if line.product_id.id == 232383:
- # raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara'))
- # for order in self:
- # approval1 = approval2 = 0
- # for line in order.order_line:
- # if not line.product_id:
- # continue
- # if (line.item_percent_margin <= 15 or line.item_percent_margin == 100) and (
- # self.env.user.id != 6 and self.env.user.id != 7):
- # approval2 += 1
- # elif line.item_percent_margin <= 40 and (
- # self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7):
- # approval1 += 1
- # if approval2 > 0:
- # raise UserError("Need Tyas / Akbar Approval, atau Approval manual dan lampirkan di Log Internal")
- # elif approval1 > 0:
- # raise UserError("Need Adela Approval")
- # order.approval_status = 'approved'
+ for line in self.order_line:
+ if line.product_id.id == 232383:
+ raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara'))
+
+ for order in self:
+ approval1 = approval2 = 0
+ for line in order.order_line:
+ if not line.product_id or line.product_id.type == 'service':
+ continue
+ if (line.item_percent_margin <= 15) and (self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas will approve
+ approval2 += 1
+ elif line.item_percent_margin <= 25 and (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 19): # darren?
+ approval1 += 1
+ if approval2 > 0:
+ raise UserError("Harus diapprove oleh Pimpinan (Akbar / Tyas)")
+ elif approval1 > 0:
+ raise UserError("Harus diapprove oleh Manager (?)")
+ order.approval_status = 'approved'
return res
def compute_total_margin(self):