summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-08-25 18:12:25 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-08-25 18:12:25 +0700
commit8fb3427f625867b7d47b7ed0d40f994fa52c00e6 (patch)
tree46c076eb8cdf72b5062aeb841cfa069352784096
parenta70798e97805e6c0befb6835abf6637dbac1dd8c (diff)
<hafid> integrate tukar guling
-rw-r--r--indoteknik_custom/models/refund_sale_order.py124
-rwxr-xr-xindoteknik_custom/models/sale_order.py1
-rw-r--r--indoteknik_custom/models/tukar_guling.py4
-rw-r--r--indoteknik_custom/views/refund_sale_order.xml17
4 files changed, 111 insertions, 35 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py
index 4f41a002..0b4d2893 100644
--- a/indoteknik_custom/models/refund_sale_order.py
+++ b/indoteknik_custom/models/refund_sale_order.py
@@ -62,6 +62,16 @@ class RefundSaleOrder(models.Model):
('salah_transfer', 'Salah Transfer')
], string='Refund Type', required=True)
+ tukar_guling_ids = fields.One2many(
+ 'tukar.guling', 'refund_id',
+ string="Tukar Guling"
+ )
+
+ tukar_guling_count = fields.Integer(
+ string="Tukar Guling Count",
+ compute="_compute_tukar_guling_count"
+ )
+
refund_type_display = fields.Char(string="Refund Type Label", compute="_compute_refund_type_display")
line_ids = fields.One2many('refund.sale.order.line', 'refund_id', string='Refund Lines')
@@ -157,7 +167,6 @@ class RefundSaleOrder(models.Model):
if vals.get('name', 'New') == 'New':
vals['name'] = self.env['ir.sequence'].next_by_code('refund.sale.order') or 'New'
- res = super().create(vals)
vals['created_date'] = fields.Date.context_today(self)
vals['create_uid'] = self.env.user.id
@@ -240,7 +249,7 @@ class RefundSaleOrder(models.Model):
raise ValidationError("❌ Tidak ada sisa transaksi untuk di-refund di SO ini. Semua dana sudah dikembalikan.")
vals['remaining_refundable'] = remaining
- return super().create(vals)
+ return super().create(vals)
def write(self, vals):
@@ -455,7 +464,7 @@ class RefundSaleOrder(models.Model):
line_vals.append((0, 0, {
'product_id': line.product_id.id,
'quantity': line.product_uom_qty,
- 'product_from': line.order_id.name,
+ 'ref_id': line.order_id.id,
'reason': '',
}))
@@ -488,7 +497,7 @@ class RefundSaleOrder(models.Model):
for move in picking.move_lines:
line_vals.append((0, 0, {
'product_id': move.product_id.id,
- 'product_from': picking.name,
+ 'ref_id': picking.id,
'quantity': move.product_uom_qty,
'reason': '',
}))
@@ -499,7 +508,7 @@ class RefundSaleOrder(models.Model):
for move in picking.move_lines:
line_vals.append((0, 0, {
'product_id': move.product_id.id,
- 'product_from': picking.name,
+ 'ref_id': picking.ref_id,
'quantity': move.product_uom_qty,
'reason': '',
}))
@@ -508,7 +517,7 @@ class RefundSaleOrder(models.Model):
for move in picking.move_lines:
line_vals.append((0, 0, {
'product_id': move.product_id.id,
- 'product_from': picking.name,
+ 'ref_id': picking.ref_id,
'quantity': move.product_uom_qty,
'reason': '',
}))
@@ -570,31 +579,6 @@ class RefundSaleOrder(models.Model):
pengurangan = rec.total_invoice + rec.ongkir
refund = rec.uang_masuk - pengurangan
rec.amount_refund = refund if refund > 0 else 0.0
-
- @api.model
- def default_get(self, fields_list):
- res = super().default_get(fields_list)
- sale_order_id = self.env.context.get('default_sale_order_id')
- if sale_order_id:
- so = self.env['sale.order'].browse(sale_order_id)
- res['sale_order_ids'] = [(6, 0, [so.id])]
- invoice_ids = so.invoice_ids.filtered(
- lambda inv: inv.move_type in ['out_invoice', 'out_refund'] and inv.state != 'cancel'
- ).ids
- res['invoice_ids'] = [(6, 0, invoice_ids)]
- res['uang_masuk'] = 0.0
- res['ongkir'] = so.delivery_amt or 0.0
- line_vals = []
- for line in so.order_line:
- line_vals.append((0, 0, {
- 'product_id': line.product_id.id,
- 'quantity': line.product_uom_qty,
- 'product_from': line.order_id.name,
- 'reason': '',
- }))
- res['line_ids'] = line_vals
- res['refund_type'] = 'uang' if invoice_ids else False
- return res
@api.onchange('invoice_ids')
def _onchange_invoice_ids(self):
@@ -870,7 +854,81 @@ class RefundSaleOrder(models.Model):
('picking_type_id', '=', 73),
('sale_id', 'in', rec.sale_order_ids.ids)
])
- rec.show_return_alert = not retur_ort and not retur_srt
+ rec.show_return_alert = not retur_ort and not retur_srt and rec.refund_type in ['retur', 'retur_half']
+
+ def action_create_tukar_guling(self):
+ for refund in self:
+ if refund.refund_type not in ['retur', 'retur_half']:
+ raise UserError("Refund Type harus Retur Full atau Retur Sebagian untuk membuat Tukar Guling.")
+
+ tg_records = []
+ for picking in refund.line_ids.mapped('ref_id'):
+ if not picking:
+ continue
+
+ lines = refund.line_ids.filtered(lambda l: l.ref_id.id == picking.id)
+ line_vals = []
+ koli_lines = []
+ for r_line in lines:
+ qty_done = 0.0
+ move_line = r_line.ref_id.move_line_ids_without_package.filtered(
+ lambda ml: ml.product_id.id == r_line.product_id.id
+ )
+ if move_line:
+ qty_done = sum(move_line.mapped('qty_done'))
+ line_vals.append((0, 0, {
+ 'product_id': r_line.product_id.id,
+ 'product_uom_qty': r_line.quantity,
+ 'name':r_line.product_id.name,
+ 'product_uom':r_line.product_id.uom_id.id
+ }))
+
+ if r_line.ref_id.konfirm_koli_lines.pick_id:
+ koli_lines.append((0, 0,{
+ 'pick_id': r_line.ref_id.konfirm_koli_lines.pick_id.id,
+ 'product_id': r_line.product_id.id,
+ 'qty_done': qty_done,
+ 'qty_return': r_line.quantity,
+ }))
+
+ tg = self.env['tukar.guling'].create({
+ 'partner_id': refund.partner_id.id,
+ 'origin': ','.join(refund.sale_order_ids.mapped('name')),
+ 'origin_so': refund.sale_order_ids.id,
+ 'operations': picking.id,
+ 'return_type': 'revisi_so',
+ 'is_has_invoice': bool(refund.invoice_ids.ids),
+ 'invoice_id': refund.invoice_ids.ids if refund.invoice_ids.ids else None,
+ 'refund_id': refund.id,
+ 'line_ids': line_vals,
+ 'mapping_koli_ids': koli_lines
+ })
+ tg_records.append(tg.id)
+
+ return {
+ 'type': 'ir.actions.act_window',
+ 'name': 'Pengajuan Retur SO',
+ 'res_model': 'tukar.guling',
+ 'view_mode': 'tree,form',
+ 'domain': [('id', 'in', tg_records)],
+ }
+
+ def _compute_tukar_guling_count(self):
+ for rec in self:
+ rec.tukar_guling_count = len(rec.tukar_guling_ids)
+
+
+ def action_open_tukar_guling(self):
+ self.ensure_one()
+ return {
+ 'name': 'Pengajuan Return SO',
+ 'type': 'ir.actions.act_window',
+ 'view_mode': 'tree,form',
+ 'res_model': 'tukar.guling',
+ 'domain': [('id', 'in', self.tukar_guling_ids.ids)],
+ 'context': dict(self.env.context, default_refund_id=self.id),
+ }
+
class RefundSaleOrderLine(models.Model):
_name = 'refund.sale.order.line'
@@ -881,4 +939,4 @@ class RefundSaleOrderLine(models.Model):
product_id = fields.Many2one('product.product', string='Product')
quantity = fields.Float(string='Qty')
reason = fields.Char(string='Reason')
- product_from = fields.Char(string='Product Reference')
+ ref_id = fields.Many2one('stock.picking',string='Product Reference')
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 2acee890..a357eb70 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -3231,6 +3231,7 @@ class SaleOrder(models.Model):
'type': 'ir.actions.act_window',
'res_model': 'refund.sale.order',
'view_mode': 'form',
+ 'target':'new',
'target': 'current',
'context': {
'default_sale_order_ids': [(6, 0, [self.id])],
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py
index 4b03d4b0..1309fcfe 100644
--- a/indoteknik_custom/models/tukar_guling.py
+++ b/indoteknik_custom/models/tukar_guling.py
@@ -27,6 +27,10 @@ class TukarGuling(models.Model):
if_so = fields.Boolean('Is SO', default=True)
if_po = fields.Boolean('Is PO', default=False)
real_shipping_id = fields.Many2one('res.partner', string='Shipping Address')
+ refund_id = fields.Many2one(
+ 'refund.sale.order',
+ string="Refund Ref"
+ )
picking_ids = fields.One2many(
'stock.picking',
'tukar_guling_id',
diff --git a/indoteknik_custom/views/refund_sale_order.xml b/indoteknik_custom/views/refund_sale_order.xml
index 3c60cc57..a2538f42 100644
--- a/indoteknik_custom/views/refund_sale_order.xml
+++ b/indoteknik_custom/views/refund_sale_order.xml
@@ -68,6 +68,11 @@
type="object"
class="oe_highlight"
attrs="{'invisible': ['|', ('journal_refund_state', 'in', ['posted', 'draft']), ('status', 'not in', ['pengajuan3','refund'])]}"/>
+ <button name="action_create_tukar_guling"
+ string="Create Return"
+ type="object"
+ class="oe_highlight"
+ attrs="{'invisible': [('refund_type', 'not in', ['retur_half', 'retur'])]}"/>
<field name="status"
widget="statusbar"
@@ -81,7 +86,7 @@
</header>
<xpath expr="//sheet" position="inside">
<field name="show_return_alert" invisible="1"/>
- <div class="alert alert-info" role="alert"
+ <div class="alert alert-danger" role="alert"
attrs="{'invisible': [('show_return_alert', '=', False)]}">
⚠️ SO belum melakukan retur barang. Silakan buat pengajuan retur.
</div>
@@ -96,6 +101,13 @@
attrs="{'invisible': [('journal_refund_move_id', '=', False)]}">
<field name="journal_refund_move_id" string="Journal Refund" widget="statinfo"/>
</button>
+ <button name="action_open_tukar_guling"
+ type="object"
+ class="oe_stat_button"
+ icon="fa-refresh"
+ attrs="{'invisible': ['|', ('refund_type', 'not in', ['retur', 'retur_half']), ('tukar_guling_count', '=', 0)]}">
+ <field name="tukar_guling_count" string="Pengajuan Return SO" widget="statinfo"/>
+ </button>
</div>
<widget name="web_ribbon"
title="PAID"
@@ -131,6 +143,7 @@
<field name="amount_refund" attrs="{'readonly': [('is_locked', '=', True)]}"/>
<field name="amount_refund_text" readonly="1"/>
<field name="sale_order_count" invisible="1"/>
+ <field name="tukar_guling_ids" invisible="1"/>
<field name="remaining_refundable" readonly="1" attrs="{'invisible': [('sale_order_count', '>', 1)]}"/>
<field name="uang_masuk_type" required="1" attrs="{'readonly': [('is_locked', '=', True)]}"/>
<field name="bukti_uang_masuk_image" widget="image"
@@ -144,7 +157,7 @@
<page string="Produk Line">
<field name="line_ids" attrs="{'readonly': [('is_locked', '=', True)]}">
<tree editable="bottom" create="0" delete="1">
- <field name="product_from"/>
+ <field name="ref_id"/>
<field name="product_id"/>
<field name="quantity"/>
<field name="reason"/>