summaryrefslogtreecommitdiff
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
parentd115f21b64e72af553d7c8965b9426b2802a0e3c (diff)
<miqdad> inv and bil return option
-rw-r--r--indoteknik_custom/models/account_move.py1
-rw-r--r--indoteknik_custom/models/tukar_guling.py41
-rw-r--r--indoteknik_custom/models/tukar_guling_po.py65
-rw-r--r--indoteknik_custom/views/tukar_guling.xml3
-rw-r--r--indoteknik_custom/views/tukar_guling_po.xml3
5 files changed, 93 insertions, 20 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index 4be6c984..b03d0a80 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -18,6 +18,7 @@ _logger = logging.getLogger(__name__)
class AccountMove(models.Model):
_inherit = 'account.move'
_description = 'Account Move'
+ tukar_guling_po_id = fields.Many2one('tukar.guling.po', string='Tukar Guling PO Ref')
invoice_day_to_due = fields.Integer(string="Day to Due", compute="_compute_invoice_day_to_due")
bill_day_to_due = fields.Date(string="Day to Due", compute="_compute_bill_day_to_due")
date_send_fp = fields.Datetime(string="Tanggal Kirim Faktur Pajak")
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py
index 3f81393a..d511779e 100644
--- a/indoteknik_custom/models/tukar_guling.py
+++ b/indoteknik_custom/models/tukar_guling.py
@@ -74,6 +74,38 @@ class TukarGuling(models.Model):
date_sales = fields.Datetime('Approved Date Sales', tracking=3, readonly=True)
date_logistic = fields.Datetime('Approved Date Logistic', tracking=3, readonly=True)
+ val_inv_opt = fields.Selection([
+ ('tanpa_cancel', 'Tanpa Cancel Invoice'),
+ ('cancel_invoice', 'Cancel Invoice'),
+ ], tracking=3, string='Invoice Option')
+
+ is_has_invoice = fields.Boolean('Has Invoice?', compute='_compute_is_has_invoice', readonly=True, default=False)
+
+ invoice_id = fields.Many2one('account.move', string='Invoice Ref', readonly=True)
+
+ @api.depends('origin')
+ def _compute_is_has_invoice(self):
+ for rec in self:
+ invoices = self.env['account.move'].search([
+ ('invoice_origin', 'ilike', rec.origin),
+ ('move_type', '=', 'out_invoice'), # hanya invoice
+ ('state', 'not in', ['draft', 'cancel'])
+ ])
+ if invoices:
+ rec.is_has_invoice = True
+ rec.invoice_id = invoices
+ else:
+ rec.is_has_invoice = False
+
+ def set_opt(self):
+ if not self.val_inv_opt and self.is_has_invoice == True:
+ raise UserError("Kalau sudah ada invoice Return Invoice Option harus diisi!")
+ for rec in self:
+ if rec.val_inv_opt == 'cancel_invoice' and self.is_has_invoice == True:
+ raise UserError("Tidak bisa mengubah Return karena sudah ada invoice dan belum di cancel.")
+ elif rec.val_inv_opt == 'tanpa_cancel' and self.is_has_invoice == True:
+ continue
+
# @api.onchange('operations')
# def get_partner_id(self):
# if self.operations and self.operations.partner_id and self.operations.partner_id.name:
@@ -288,7 +320,6 @@ class TukarGuling(models.Model):
# ('state', '!=', 'cancel')
# ]) > 0
- @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:
@@ -348,7 +379,7 @@ class TukarGuling(models.Model):
self.ensure_one()
if self.operations.picking_type_id.id not in [29, 30]:
raise UserError("❌ Picking type harus BU/OUT atau BU/PICK")
- self._check_invoice_on_revisi_so()
+ # self._check_invoice_on_revisi_so()
operasi = self.operations.picking_type_id.id
tipe = self.return_type
pp = vals.get('return_type', tipe)
@@ -455,7 +486,7 @@ class TukarGuling(models.Model):
raise UserError(
_("Qty di Koli tidak sesuai dengan qty retur untuk produk %s") % line.product_id.display_name)
- self._check_invoice_on_revisi_so()
+ # self._check_invoice_on_revisi_so()
self._validate_product_lines()
if self.state != 'draft':
@@ -506,7 +537,7 @@ class TukarGuling(models.Model):
def action_approve(self):
self.ensure_one()
self._validate_product_lines()
- self._check_invoice_on_revisi_so()
+ # self._check_invoice_on_revisi_so()
self._check_not_allow_tukar_guling_on_bu_pick()
operasi = self.operations.picking_type_id.id
@@ -546,6 +577,8 @@ class TukarGuling(models.Model):
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.")
+ rec._check_invoice_on_revisi_so()
+ rec.set_opt()
rec.state = 'approval_logistic'
rec.date_finance = now
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
diff --git a/indoteknik_custom/views/tukar_guling.xml b/indoteknik_custom/views/tukar_guling.xml
index c23995d3..88e5b883 100644
--- a/indoteknik_custom/views/tukar_guling.xml
+++ b/indoteknik_custom/views/tukar_guling.xml
@@ -84,8 +84,11 @@
<field name="operations"
attrs="{'readonly': [('state', 'not in', 'draft')]}"/>
<field name="origin" readonly="1"/>
+ <field name="is_has_invoice" readonly="1"/>
+ <field name="invoice_id" readonly="1"/>
</group>
<group>
+ <field name="val_inv_opt" attrs="{'invisible': [('is_has_invoice', '=', False)]}"/>
<field name="ba_num" string="Nomor BA"/>
<field name="notes"/>
<field name="date_sales" readonly="1"/>
diff --git a/indoteknik_custom/views/tukar_guling_po.xml b/indoteknik_custom/views/tukar_guling_po.xml
index accf7dbc..d3c41405 100644
--- a/indoteknik_custom/views/tukar_guling_po.xml
+++ b/indoteknik_custom/views/tukar_guling_po.xml
@@ -90,9 +90,12 @@
'required': [('return_type', 'in', ['revisi_po', 'tukar_guling'])]
}"/>
<field name="origin" readonly="1"/>
+ <field name="is_has_bill" readonly="1"/>
+ <field name="bill_id" readonly="1"/>
<!-- <field name="origin_so" readonly="1"/>-->
</group>
<group>
+ <field name="val_bil_opt" attrs="{'invisible': [('is_has_bill', '=', False)]}"/>
<field name="ba_num" string="Nomor BA"/>
<field name="notes"/>
<field name="date_purchase" readonly="1"/>