summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-08-21 16:19:50 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-08-21 16:19:50 +0700
commit1043e2f2b9630b8b622a9bc5070bf167d17e08d7 (patch)
tree8fe136db08053e3b05e187d820d1b4802fb19c31 /indoteknik_custom/models
parent0e4e1eaf30f79afb2b9885c897b8a8a2044f8509 (diff)
parentfc6f0a00ab98a72ad3d08f1d5ad6f8120e21814a (diff)
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into block_manual_input_stock_picking
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/account_move.py4
-rwxr-xr-xindoteknik_custom/models/product_template.py1
-rwxr-xr-xindoteknik_custom/models/purchase_order.py32
-rwxr-xr-xindoteknik_custom/models/sale_order.py39
-rw-r--r--indoteknik_custom/models/sale_order_line.py23
-rw-r--r--indoteknik_custom/models/stock_picking.py37
-rw-r--r--indoteknik_custom/models/tukar_guling.py3
7 files changed, 84 insertions, 55 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index b0ffd8b9..94774f0f 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -278,8 +278,9 @@ class AccountMove(models.Model):
'reply_to': 'finance@indoteknik.co.id',
}
- _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}")
template.send_mail(invs[0].id, force_send=True, email_values=values)
+ _logger.info(f"Mengirim email ke: {values['email_to']} > email CC: {values['email_cc']}")
+ _logger.info(f"Reminder terkirim ke {partner.name} ({values['email_to']}) → {len(invs)} invoice (dtd = {dtd})")
# flag
invs.write({'reminder_sent_date': today})
# Post ke chatter
@@ -293,7 +294,6 @@ class AccountMove(models.Model):
author_id=system_id,
)
- _logger.info(f"Reminder terkirim ke {partner.name} ({values['email_to']}) → {len(invs)} invoice (dtd = {dtd})")
@api.onchange('invoice_date')
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index f59bea6b..13e99707 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -1365,4 +1365,5 @@ class ImageCarousel(models.Model):
_order = 'product_id, id'
product_id = fields.Many2one('product.template', string='Product', required=True, ondelete='cascade', index=True, copy=False)
+ sequence = fields.Integer("Sequence", default=10)
image = fields.Binary(string='Image')
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 103a9131..50913a80 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -103,6 +103,11 @@ class PurchaseOrder(models.Model):
string="BU Related Count",
compute='_compute_bu_related_count'
)
+
+ bills_related_count = fields.Integer(
+ string="Bills DP & Pelunasan",
+ compute="_compute_bills_related_count"
+ )
manufacturing_id = fields.Many2one('mrp.production', string='Manufacturing Orders')
complete_bu_in_count = fields.Integer(
@@ -260,6 +265,33 @@ class PurchaseOrder(models.Model):
'target': 'current',
}
+ def action_view_bills(self):
+ self.ensure_one()
+
+ bill_ids = []
+ if self.bills_dp_id:
+ bill_ids.append(self.bills_dp_id.id)
+ if self.bills_pelunasan_id:
+ bill_ids.append(self.bills_pelunasan_id.id)
+
+ return {
+ 'name': 'Bills (DP & Pelunasan)',
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'account.move',
+ 'view_mode': 'tree,form',
+ 'target': 'current',
+ 'domain': [('id', 'in', bill_ids)],
+ }
+
+ def _compute_bills_related_count(self):
+ for order in self:
+ count = 0
+ if order.bills_dp_id:
+ count += 1
+ if order.bills_pelunasan_id:
+ count += 1
+ order.bills_related_count = count
+
# cek payment term
def _check_payment_term(self):
_logger.info("Check Payment Term Terpanggil")
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 53be999f..9a6f314d 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -391,9 +391,9 @@ class SaleOrder(models.Model):
payment_state_custom = fields.Selection([
('unpaid', 'Unpaid'),
('partial', 'Partially Paid'),
- ('paid', 'Paid'),
+ ('paid', 'Full Paid'),
('no_invoice', 'No Invoice'),
- ], string="Payment Status", compute="_compute_payment_state_custom", store=False)
+ ], string="Payment Status Invoice", compute="_compute_payment_state_custom", store=False)
@api.depends('invoice_ids.payment_state', 'invoice_ids.amount_total', 'invoice_ids.amount_residual')
def _compute_payment_state_custom(self):
@@ -431,21 +431,27 @@ class SaleOrder(models.Model):
continue
for move in line.move_ids:
- if move.state != 'done':
- # reserve qty (draft/assigned)
- if move.picking_type_id.code == 'internal':
+ if move.picking_type_id.code == 'internal':
+ if move.state != 'done':
+ # PICK belum done → qty reserved
reserved_qty += move.reserved_availability or 0.0
- continue
-
- # sudah done → cek alur lokasi
- if move.location_dest_id.usage == 'customer':
- # barang keluar → delivered
- delivered_qty += move.quantity_done
- elif move.location_id.usage == 'customer':
- # barang balik (return) → kurangi delivered
- delivered_qty -= move.quantity_done
-
- # clamp biar ga minus
+ else:
+ # PICK done → qty_done masih dianggap reserved (masuk BU/OUT)
+ reserved_qty += move.quantity_done or 0.0
+
+ elif move.state == 'done':
+ # OUT done (customer terima) → delivered
+ if move.location_dest_id.usage == 'customer':
+ delivered_qty += move.quantity_done
+ # sekaligus kurangi reserved (karena udah terkirim)
+ reserved_qty -= move.quantity_done
+ # Return dari customer
+ elif move.location_id.usage == 'customer':
+ delivered_qty -= move.quantity_done
+ reserved_qty += move.quantity_done # balik ke reserved
+
+ # clamp jangan sampai minus
+ reserved_qty = max(reserved_qty, 0)
delivered_qty = max(delivered_qty, 0)
order.reserved_percent = (reserved_qty / total_qty) * 100
@@ -455,6 +461,7 @@ class SaleOrder(models.Model):
order.reserved_percent = order.delivered_percent = order.unreserved_percent = 0
+
def _has_ccm(self):
if self.id:
self.ccm_id = self.env['tukar.guling'].search([('origin', 'ilike', self.name)], limit=1)
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index 2406995d..a20f93ef 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -66,21 +66,29 @@ class SaleOrderLine(models.Model):
if order_qty > 0:
for move in line.move_ids:
+ # --- CASE 1: Picking belum done ---
if move.state != 'done':
- # Reserve qty (hanya dari picking internal yang belum selesai)
if move.picking_type_id.code == 'internal':
reserved_qty += move.reserved_availability or 0.0
continue
- # Kalau sudah done → cek lokasi
- if move.location_dest_id.usage == 'customer':
- # Barang keluar → tambah delivered
+ # --- CASE 2: Picking sudah done ---
+ if move.picking_type_id.code == 'internal':
+ # PICK done → qty_done tetap dianggap reserved (masih nunggu OUT)
+ reserved_qty += move.quantity_done or 0.0
+
+ elif move.location_dest_id.usage == 'customer':
+ # OUT done (barang nyampe customer)
delivered_qty += move.quantity_done
+ reserved_qty -= move.quantity_done
+
elif move.location_id.usage == 'customer':
- # Barang balik dari customer (retur) → kurangi delivered
+ # Retur dari customer
delivered_qty -= move.quantity_done
+ reserved_qty += move.quantity_done
- # Jangan sampai delivered minus
+ # clamp supaya gak minus
+ reserved_qty = max(reserved_qty, 0)
delivered_qty = max(delivered_qty, 0)
# Hitung persentase
@@ -88,9 +96,6 @@ class SaleOrderLine(models.Model):
line.delivered_percent = (delivered_qty / order_qty) * 100 if order_qty else 0
line.unreserved_percent = 100 - line.reserved_percent - line.delivered_percent
-
-
-
def _get_outgoing_incoming_moves(self):
outgoing_moves = self.env['stock.move']
incoming_moves = self.env['stock.move']
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 534b1ff1..a48e0ed1 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -1330,18 +1330,20 @@ class StockPicking(models.Model):
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
self.date_reserved = current_time
+
# Validate Qty Demand Can't higher than Qty Product
- for move_line in self.move_line_ids_without_package:
- purchase_line = move_line.move_id.purchase_line_id
- if purchase_line:
- if purchase_line.product_uom_qty < move_line.product_uom_qty:
- raise UserError(
- _("Quantity demand (%s) tidak bisa lebih besar dari qty product (%s) untuk produk %s") % (
- move_line.product_uom_qty,
- purchase_line.product_uom_qty,
- move_line.product_id.display_name
+ if self.location_dest_id.id == 58 and 'BU/INPUT/' in self.name:
+ for move in self.move_ids_without_package:
+ purchase_line = move.purchase_line_id
+ if purchase_line:
+ if purchase_line.product_qty < move.quantity_done:
+ raise UserError(
+ _("Quantity demand (%s) tidak bisa lebih besar dari qty product (%s) untuk produk %s") % (
+ move.quantity_done,
+ purchase_line.product_qty,
+ move.product_id.display_name
+ )
)
- )
self.validation_minus_onhand_quantity()
self.responsible = self.env.user.id
@@ -2086,21 +2088,6 @@ class CheckProduct(models.Model):
status = fields.Char(string='Status', compute='_compute_status')
code_product = fields.Char(string='Code Product')
- def write(self, vals):
- if 'code_product' in vals and not self.env.context.get('from_barcode_scan'):
- raise UserError("Field Code Product hanya bisa diisi melalui barcode scan.")
- res = super().write(vals)
- # konsolidasi dll milik Anda tetap jalan
- if not self.env.context.get('skip_consolidate'):
- self.with_context(skip_consolidate=True)._consolidate_duplicate_lines()
- return res
-
- # Scanner handler
- def on_barcode_scanned(self, barcode):
- self.ensure_one()
- self.with_context(from_barcode_scan=True).write({'code_product': barcode})
- self._onchange_code_product()
-
@api.onchange('code_product')
def _onchange_code_product(self):
if not self.code_product:
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py
index 4b03d4b0..23b9f085 100644
--- a/indoteknik_custom/models/tukar_guling.py
+++ b/indoteknik_custom/models/tukar_guling.py
@@ -109,9 +109,6 @@ class TukarGuling(models.Model):
('invoice_line_ids.product_id', 'in', product_ids),
]
- if rec.partner_id:
- domain.append(('partner_id', '=', rec.partner_id.id))
-
extra = []
if rec.origin:
extra.append(('invoice_origin', 'ilike', rec.origin))