summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-07-08 10:16:46 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-07-08 10:16:46 +0700
commita8886eb056d62ace630f15fb3eaa5d55a360b277 (patch)
treefe2ad261719501bd214cd7914897a2d4b6370e52
parent52ed14a408f63bc7d93b7bc393a8a6eb4cd1ac08 (diff)
<miqdad> rev 77 check invoice
-rw-r--r--indoteknik_custom/models/tukar_guling.py14
-rw-r--r--indoteknik_custom/views/tukar_guling.xml2
2 files changed, 8 insertions, 8 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py
index 1aa5af5c..9fe7527c 100644
--- a/indoteknik_custom/models/tukar_guling.py
+++ b/indoteknik_custom/models/tukar_guling.py
@@ -193,18 +193,17 @@ class TukarGuling(models.Model):
('state', '!=', 'cancel')
]) > 0
- @api.onchange('return_type', 'operations')
- def _onchange_check_invoice(self):
+ @api.constrains('return_type', 'operations')
+ def _check_invoice_on_revisi_so(self):
for record in self:
if record.return_type == 'revisi_so' and record.origin:
- # Cek invoice yang berhubungan dengan origin SO
invoices = self.env['account.move'].search([
('invoice_origin', 'ilike', record.origin),
('state', 'not in', ['draft', 'cancel'])
])
if invoices:
- raise UserError(
- _("Tidak bisa memilih Return Type 'Revisi SO' karena dokumen SO %s sudah dibuat invoice.") % record.origin
+ raise ValidationError(
+ _("Tidak bisa memilih Return Type 'Revisi SO' karena dokumen %s sudah dibuat invoice.") % record.origin
)
@api.model
@@ -252,6 +251,7 @@ class TukarGuling(models.Model):
return new_record
def write(self, vals):
+ self._check_invoice_on_revisi_so()
if self.operations.picking_type_id.id == 30 and self.return_type == 'tukar_guling':
raise UserError ("BU/PICK tidak boleh retur tukar guling")
# if self.operations.picking_type_id.id != 30:
@@ -304,7 +304,7 @@ class TukarGuling(models.Model):
if self.operations.picking_type_id.id != 30:
if self._is_already_returned(self.operations):
raise UserError("BU ini sudah pernah diretur oleh dokumen lain.")
- self._onchange_check_invoice()
+ self._check_invoice_on_revisi_so()
self._validate_product_lines()
@@ -315,7 +315,7 @@ class TukarGuling(models.Model):
def action_approve(self):
self.ensure_one()
self._validate_product_lines()
- self._onchange_check_invoice()
+ self._check_invoice_on_revisi_so()
if self.operations.picking_type_id.id == 30 and self.return_type == 'tukar_guling':
raise UserError ("BU/PICK tidak boleh retur tukar guling")
diff --git a/indoteknik_custom/views/tukar_guling.xml b/indoteknik_custom/views/tukar_guling.xml
index dc5abec7..201031c4 100644
--- a/indoteknik_custom/views/tukar_guling.xml
+++ b/indoteknik_custom/views/tukar_guling.xml
@@ -65,7 +65,7 @@
type="object"
class="oe_stat_button"
icon="fa-truck"
- attrs="{'invisible': [('picking_ids', '=', False)]}">
+ attrs="{'invisible': [('picking_ids', '=', False), ('state', 'in', ['draft', 'approval_sales', 'approval_logistic', 'approval_finance'])]}">
<field name="picking_ids" widget="statinfo" string="Delivery"/>
</button>
</div>