summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/tukar_guling_po.py
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-08-06 08:49:56 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-08-06 08:49:56 +0700
commit9f9081714356e87500ab05bc5a294e9ca9e526fe (patch)
tree7ccec526e02e4fa78bddf88909cb3531e1b6c938 /indoteknik_custom/models/tukar_guling_po.py
parentd115f21b64e72af553d7c8965b9426b2802a0e3c (diff)
<miqdad> inv and bil return option
Diffstat (limited to 'indoteknik_custom/models/tukar_guling_po.py')
-rw-r--r--indoteknik_custom/models/tukar_guling_po.py65
1 files changed, 49 insertions, 16 deletions
diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py
index 467fff44..83aa49fe 100644
--- a/indoteknik_custom/models/tukar_guling_po.py
+++ b/indoteknik_custom/models/tukar_guling_po.py
@@ -54,6 +54,38 @@ class TukarGulingPO(models.Model):
('cancel', 'Cancel'),
], string='Status', default='draft', tracking=3)
+ val_bil_opt = fields.Selection([
+ ('tanpa_cancel', 'Tanpa Cancel Bill'),
+ ('cancel_bill', 'Cancel Bill'),
+ ], tracking=3, string='Bill Option')
+
+ is_has_bill = fields.Boolean('Has Bill?', compute='_compute_is_has_bill', readonly=True, default=False)
+
+ bill_id = fields.Many2one('account.move', string='Bill Ref', readonly=True)
+
+ @api.depends('origin')
+ def _compute_is_has_bill(self):
+ for rec in self:
+ bills = self.env['account.move'].search([
+ ('invoice_origin', 'ilike', rec.origin),
+ ('move_type', '=', 'in_invoice'), # hanya vendor bill
+ ('state', 'not in', ['draft', 'cancel'])
+ ])
+ if bills:
+ rec.is_has_bill = True
+ rec.bill_id = bills
+ else:
+ rec.is_has_bill = False
+
+ def set_opt(self):
+ if not self.val_bil_opt and self.is_has_bill == True:
+ raise UserError("Kalau sudah ada bill Return Bill Option harus diisi!")
+ for rec in self:
+ if rec.val_bil_opt == 'cancel_bill' and self.is_has_bill == True:
+ raise UserError("Tidak bisa mengubah Return karena sudah ada bill dan belum di cancel.")
+ elif rec.val_bil_opt == 'tanpa_cancel' and self.is_has_bill == True:
+ continue
+
@api.model
def create(self, vals):
# Generate sequence number
@@ -74,19 +106,18 @@ class TukarGulingPO(models.Model):
return res
- # @api.constrains('return_type', 'operations')
- # def _check_bill_on_revisi_po(self):
- # for record in self:
- # if record.return_type == 'revisi_po' and record.origin:
- # bills = self.env['account.move'].search([
- # ('invoice_origin', 'ilike', record.origin),
- # ('move_type', '=', 'in_invoice'), # hanya vendor bill
- # ('state', 'not in', ['draft', 'cancel'])
- # ])
- # if bills:
- # raise ValidationError(
- # _("Tidak bisa memilih Return Type 'Revisi PO' karena PO %s sudah dibuat vendor bill.") % record.origin
- # )
+ def _check_bill_on_revisi_po(self):
+ for record in self:
+ if record.return_type == 'revisi_po' and record.origin:
+ bills = self.env['account.move'].search([
+ ('invoice_origin', 'ilike', record.origin),
+ ('move_type', '=', 'in_invoice'), # hanya vendor bill
+ ('state', 'not in', ['draft', 'cancel'])
+ ])
+ # if bills:
+ # raise ValidationError(
+ # _("Tidak bisa memilih Return Type 'Revisi PO' karena PO %s sudah dibuat vendor bill. Harus Cancel Jika ingin melanjutkan") % record.origin
+ # )
@api.onchange('operations')
def _onchange_operations(self):
@@ -400,19 +431,21 @@ class TukarGulingPO(models.Model):
for rec in self:
if rec.state == 'approval_purchase':
if not rec.env.user.has_group('indoteknik_custom.group_role_sales'):
- raise UserError("Hanya Sales Manager yang boleh approve tahap ini.")
+ raise UserError("Hanya Sales yang boleh approve tahap ini.")
rec.state = 'approval_finance'
rec.date_purchase = now
elif rec.state == 'approval_finance':
if not rec.env.user.has_group('indoteknik_custom.group_role_fat'):
- raise UserError("Hanya Finance Manager yang boleh approve tahap ini.")
+ raise UserError("Hanya Finance yang boleh approve tahap ini.")
+ rec._check_bill_on_revisi_po()
+ rec.set_opt()
rec.state = 'approval_logistic'
rec.date_finance = now
elif rec.state == 'approval_logistic':
if not rec.env.user.has_group('indoteknik_custom.group_role_logistic'):
- raise UserError("Hanya Logistic Manager yang boleh approve tahap ini.")
+ raise UserError("Hanya Logistic yang boleh approve tahap ini.")
rec.state = 'approved'
rec._create_pickings()
rec.date_logistic = now