summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-09-22 17:20:57 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-09-22 17:20:57 +0700
commit54ce5a6396f5d5365d8afba0823167dfb5561cc5 (patch)
treeeda08c9a17c2600a643ea6bf5fd01ddba44075cf
parent60fffef5ee0c91ba58a056823fc2feff6241a303 (diff)
add approval validation in po confirmation
-rwxr-xr-xindoteknik_custom/models/purchase_order.py51
-rwxr-xr-xindoteknik_custom/views/purchase_order.xml6
2 files changed, 54 insertions, 3 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index fd02cd2b..b53f973f 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -1,4 +1,5 @@
-from odoo import fields, models, api
+from odoo import fields, models, api, _
+from odoo.exceptions import AccessError, UserError, ValidationError
class PurchaseOrder(models.Model):
@@ -13,8 +14,8 @@ class PurchaseOrder(models.Model):
'Total Percent Margin', compute='compute_total_margin',
help="Total % Margin in Sales Order Header")
approval_status = fields.Selection([
- ('pengajuan1', 'Approval Manager'), #siapa?
- ('pengajuan2', 'Approval Pimpinan'), #akbar
+ ('pengajuan1', 'Approval Manager'), #siapa? darren - 11
+ ('pengajuan2', 'Approval Pimpinan'), #akbar - 7
('approved', 'Approved'),
], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
count_line_product = fields.Float('Count Line Product', compute='compute_count_line_product')
@@ -92,3 +93,47 @@ class PurchaseOrder(models.Model):
if po.amount_untaxed > 0:
total_percent_margin = round((total_margin / po.amount_untaxed), 2) * 100
po.total_percent_margin = total_percent_margin
+
+ def button_confirm(self):
+ res = super(PurchaseOrder, self).button_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): # tyas or akbar
+ approval2 += 1
+ elif (line.item_percent_margin >= 15 and line.item_percent_margin < 25) and \
+ (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11):
+ approval1 += 1
+ if approval2 > 0:
+ raise UserError("Need Tyas / Akbar Approval")
+ elif approval1 > 0:
+ raise UserError("Need Adela Approval")
+ order.approval_status = 'approved'
+ return res
+
+ def po_approve(self):
+ 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
+ elif (line.item_percent_margin >= 15 and line.item_percent_margin < 25) and \
+ (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11):
+ approval1 += 1
+ if approval2 > 0:
+ order.approval_status = 'pengajuan2'
+ elif approval1 > 0:
+ order.approval_status = 'pengajuan1'
+ else:
+ raise UserError("Bisa langsung Confirm")
diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml
index 7df2ca9f..21ce3c58 100755
--- a/indoteknik_custom/views/purchase_order.xml
+++ b/indoteknik_custom/views/purchase_order.xml
@@ -14,6 +14,12 @@
attrs="{'invisible': ['|', ('sale_order_id', '=', False), ('state', 'not in', ['draft'])]}"
/>
</div>
+ <button id="draft_confirm" position="after">
+ <button name="po_approve"
+ string="Ask Approval"
+ type="object"
+ />
+ </button>
<field name="date_order" position="before">
<field name="sale_order_id" attrs="{'readonly': [('state', 'not in', ['draft'])]}"/>
</field>