summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/tukar_guling_po.py
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-08-06 13:52:21 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-08-06 13:52:21 +0700
commit7ebcf1675e55dae39f769466e5bf5ef064646f27 (patch)
treec7fccfb7e36678b9b5ee4145dee85b37dcbcd94d /indoteknik_custom/models/tukar_guling_po.py
parent09032d721277221730efa3db7a2d8353524d509c (diff)
parentab11c9455c6e125195ec5004adfd855058d46f5f (diff)
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into reminder-tempo-v2
Diffstat (limited to 'indoteknik_custom/models/tukar_guling_po.py')
-rw-r--r--indoteknik_custom/models/tukar_guling_po.py75
1 files changed, 54 insertions, 21 deletions
diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py
index 92d8c9a6..5d444472 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.Many2many('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):
@@ -281,7 +312,7 @@ class TukarGulingPO(models.Model):
def write(self, vals):
if self.operations.picking_type_id.id not in [75, 28]:
raise UserError("❌ Tidak bisa retur bukan BU/INPUT atau BU/PUT!")
- self._check_bill_on_revisi_po()
+ # self._check_bill_on_revisi_po()
tipe = vals.get('return_type', self.return_type)
if self.operations and self.operations.picking_type_id.id == 28 and tipe == 'tukar_guling':
@@ -349,7 +380,7 @@ class TukarGulingPO(models.Model):
def action_submit(self):
self.ensure_one()
- self._check_bill_on_revisi_po()
+ # self._check_bill_on_revisi_po()
self._validate_product_lines()
self._check_not_allow_tukar_guling_on_bu_input()
@@ -385,7 +416,7 @@ class TukarGulingPO(models.Model):
def action_approve(self):
self.ensure_one()
self._validate_product_lines()
- self._check_bill_on_revisi_po()
+ # self._check_bill_on_revisi_po()
self._check_not_allow_tukar_guling_on_bu_input()
if not self.operations:
@@ -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
@@ -427,7 +460,7 @@ class TukarGulingPO(models.Model):
('state', '=', 'done'),
('picking_type_id.id', '=', 76)
])
- if self.state == 'aproved' and prt:
+ if self.state == 'approved' and prt:
self.state = 'done'
# bu put rev po
elif self.operations.picking_type_id.id == 75 and self.return_type == 'revisi_po':
@@ -440,7 +473,7 @@ class TukarGulingPO(models.Model):
('state', '=', 'done'),
('picking_type_id.id', '=', 76)
])
- if self.state == 'aproved' and total_prt > 0 and prt == total_prt:
+ if self.state == 'approved' and total_prt > 0 and prt == total_prt:
self.state = 'done'
# bu put tukar guling
elif self.operations.picking_type_id.id == 75 and self.return_type == 'tukar_guling':