summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-01-13 15:34:13 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-01-13 15:34:13 +0700
commit41da8b32edee0dc394bb69ac179833388e977053 (patch)
tree6693223ca8a2ae23a4b492ef05256e9e2d10a21a
parent88a54aebe579809dcaf8d8fd9640d5c4db83f2d6 (diff)
<iman> if unlock PO harus approv finance & if not FAT cannot edit jurnal entris
-rw-r--r--indoteknik_custom/models/account_move.py5
-rwxr-xr-xindoteknik_custom/models/purchase_order.py74
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv1
-rwxr-xr-xindoteknik_custom/views/purchase_order.xml33
4 files changed, 109 insertions, 4 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index 725b3c2d..022a7f5f 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -318,6 +318,11 @@ class AccountMove(models.Model):
if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm':
raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock')
+ def write(self, vals):
+ if not self.env.user.is_accounting:
+ raise UserError("Hanya IT FAT yang bisa ubah data")
+ return super(AccountMove, self).write(vals)
+
# def write(self, vals):
# res = super(AccountMove, self).write(vals)
# for rec in self.line_ids:
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 799c4db0..f497dc9b 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -30,6 +30,11 @@ class PurchaseOrder(models.Model):
('pengajuan2', 'Approval Pimpinan'), #akbar - 7 temporary not used
('approved', 'Approved'),
], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
+ approval_status_unlock = fields.Selection([
+ ('pengajuanFinance', 'Pengajuan Finance'),
+ ('approvedFinance', 'Approved Finance'),
+ ('approved', 'Approved'),
+ ], string='Approval Status Unlock', readonly=True, copy=False, index=True, tracking=3)
delivery_amount = fields.Float('Delivery Amount', compute='compute_delivery_amount')
delivery_amt = fields.Float('Delivery Amt')
total_margin = fields.Float(
@@ -75,6 +80,7 @@ class PurchaseOrder(models.Model):
exclude_incoming = fields.Boolean(string='Exclude Incoming', default=False,
help='Centang jika tidak mau masuk perhitungan Incoming Qty')
not_update_purchasepricelist = fields.Boolean(string='Not Update Purchase Pricelist?')
+ reason_unlock = fields.Char(string='Alasan unlock', tracking=3)
# total_cost_service = fields.Float(string='Total Cost Service')
# total_delivery_amt = fields.Float(string='Total Delivery Amt')
@@ -779,8 +785,12 @@ class PurchaseOrder(models.Model):
def po_approve(self):
greater_than_plafon, message = self._get_msg_plafon_qty()
different_vendor_message = self.check_different_vendor_so() # Panggil fungsi check_different_vendor_so
-
- if self.env.user.is_leader or self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
+ if self.approval_status_unlock == 'pengajuanFinance':
+ if self.env.user.is_accounting:
+ self.approval_status_unlock = 'approvedFinance'
+ else:
+ raise UserError("Bisa langsung Confirm, menunggu persetujuan Finance jika ingin unlock PO")
+ elif self.env.user.is_leader or self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
raise UserError("Bisa langsung Confirm")
elif self.total_percent_margin == self.total_so_percent_margin and self.matches_so and not greater_than_plafon and not different_vendor_message:
raise UserError("Bisa langsung Confirm")
@@ -809,7 +819,17 @@ class PurchaseOrder(models.Model):
subtype_id=self.env.ref("mail.mt_note").id
)
-
+ def po_approve_unlock(self):
+ if self.approval_status_unlock == 'pengajuanFinance':
+ if self.env.user.is_accounting:
+ self.approval_status_unlock = 'approvedFinance'
+ else:
+ raise UserError("Menunggu persetujuan Finance jika ingin unlock PO")
+ elif self.approval_status_unlock == 'approvedFinance':
+ raise UserError("PO bisa langsung di unlock")
+ else:
+ raise UserError("Menunggu persetujuan Finance jika ingin unlock PO")
+
def check_different_vendor_so(self):
vendor_po = self.partner_id.id
message = ''
@@ -953,3 +973,51 @@ class PurchaseOrder(models.Model):
if line.product_id.type == 'product':
sum_price_total += line.price_total
order.amount_total_without_service = sum_price_total
+
+ def button_unlock(self):
+ for order in self:
+ # Check if any order line has received_qty not equal to 0
+ if self.env.user.is_accounting:
+ order.state = 'purchase'
+ order.approval_status_unlock = 'approved'
+ break
+ for line in order.order_line:
+ if line.qty_received > 0:
+ if order.approval_status_unlock == 'approvedFinance':
+ order.approval_status_unlock = 'approved'
+ order.state = 'purchase'
+ break
+ if order.approval_status_unlock == 'pengajuanFinance':
+ raise UserError(_(
+ "Menunggu Approve Dari Finance."
+ ))
+ else:
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': _('Untuk mengubah PO butuh approve dari Finance. Berikan alasan anda unlock PO!'),
+ 'res_model': 'purchase.order.unlock.wizard',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': {
+ 'default_purchase_order_id': order.id
+ }
+ }
+
+ return super(PurchaseOrder, self).button_unlock()
+
+
+class PurchaseOrderUnlockWizard(models.TransientModel):
+ _name = 'purchase.order.unlock.wizard'
+ _description = 'Wizard untuk memberikan alasan unlock PO'
+
+ purchase_order_id = fields.Many2one('purchase.order', string='Purchase Order', required=True)
+ alasan = fields.Text(string='Alasan', required=True)
+
+ def confirm_reject(self):
+ order = self.purchase_order_id
+ if order:
+ order.write({'reason_unlock': self.alasan})
+ order.approval_status_unlock = 'pengajuanFinance'
+ return {'type': 'ir.actions.act_window_close'}
+
+
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 6093636c..2b6d4420 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -150,3 +150,4 @@ access_va_multi_approve,access.va.multi.approve,model_va_multi_approve,,1,1,1,1
access_va_multi_reject,access.va.multi.reject,model_va_multi_reject,,1,1,1,1
access_stock_immediate_transfer,access.stock.immediate.transfer,model_stock_immediate_transfer,,1,1,1,1
access_coretax_faktur,access.coretax.faktur,model_coretax_faktur,,1,1,1,1
+access_purchase_order_unlock_wizard,access.purchase.order.unlock.wizard,model_purchase_order_unlock_wizard,,1,1,1,1
diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml
index d22c3b5c..fa11c373 100755
--- a/indoteknik_custom/views/purchase_order.xml
+++ b/indoteknik_custom/views/purchase_order.xml
@@ -20,6 +20,11 @@
type="object"
attrs="{'invisible': [('approval_status', '=', 'approved')]}"
/>
+ <button name="po_approve_unlock"
+ string="Ask Approval Unlock PO"
+ type="object"
+ attrs="{'invisible': [('approval_status_unlock', '=', 'approved')]}"
+ />
<button name="indoteknik_custom.action_view_uangmuka_pembelian" string="UangMuka"
type="action" attrs="{'invisible': [('approval_status', '!=', 'approved')]}"/>
</button>
@@ -43,6 +48,9 @@
<field name="revisi_po"/>
<field name="not_update_purchasepricelist"/>
</field>
+ <field name="approval_status" position="after">
+ <field name="approval_status_unlock" invisible="True"/>
+ </field>
<field name="incoterm_id" position="after">
<field name="amount_total_without_service"/>
<field name="delivery_amt"/>
@@ -137,7 +145,30 @@
</field>
</record>
</data>
-
+ <data>
+ <record id="view_purchase_order_unlock_wizard_form" model="ir.ui.view">
+ <field name="name">purchase.order.unlock.wizard.form</field>
+ <field name="model">purchase.order.unlock.wizard</field>
+ <field name="arch" type="xml">
+ <form string="Reject Reason">
+ <group>
+ <field name="alasan" widget="text"/>
+ </group>
+ <footer>
+ <button string="Confirm" type="object" name="confirm_reject" class="btn-primary"/>
+ <button string="Cancel" class="btn-secondary" special="cancel"/>
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record id="action_purchase_order_unlock_wizard" model="ir.actions.act_window">
+ <field name="name">Reject Reason</field>
+ <field name="res_model">purchase.order.unlock.wizard</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+ </data>
<data>
<record id="rfq_order_tree_view_inherit" model="ir.ui.view">