diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-09-26 14:17:54 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-09-26 14:17:54 +0700 |
| commit | 300b62f3ca9898d31254c53dda267a6cc8feaaef (patch) | |
| tree | 9d0c4a56e24722f16034fd0c2cf83405881aaeaf | |
| parent | 18a08e93126100d572a56e4deced21434082bd72 (diff) | |
Update sale_order.py - add approval process for sales order TODO change approval to Sales Manager
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 84 |
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): |
