summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorAndriFP <113114423+andrifp@users.noreply.github.com>2025-09-10 17:56:31 +0700
committerAndriFP <113114423+andrifp@users.noreply.github.com>2025-09-10 17:56:31 +0700
commit10da5e27e658030f171f694d6696f93e4a472447 (patch)
tree14a5f684bae4bc0803ed3c61cb1ce1bed23e33f6 /indoteknik_custom/models
parent914bcd75dd2baddb2841cbfba6a64ebd453fecdb (diff)
parent4db6034c07414dcd09292e3c41d6fd4598868148 (diff)
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into pum-v2
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/account_move.py5
-rwxr-xr-xindoteknik_custom/models/purchase_order.py2
-rw-r--r--indoteknik_custom/models/purchase_order_sales_match.py2
-rw-r--r--indoteknik_custom/models/refund_sale_order.py30
-rwxr-xr-xindoteknik_custom/models/sale_order.py21
-rw-r--r--indoteknik_custom/models/stock_move.py5
-rw-r--r--indoteknik_custom/models/tukar_guling.py2
7 files changed, 31 insertions, 36 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index c44cad78..c93cfb76 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -179,9 +179,8 @@ class AccountMove(models.Model):
('state', '=', 'posted'),
('payment_state', 'not in', ['paid', 'in_payment', 'reversed']),
('invoice_date_due', 'in', target_dates),
- ('date_terima_tukar_faktur', '!=', False),
- ('partner_id', 'in' , [94603])
- ], limit=5)
+ ('date_terima_tukar_faktur', '!=', False)
+ ])
_logger.info(f"Invoices: {invoices}")
invoices = invoices.filtered(
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 50913a80..18811b85 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -66,7 +66,7 @@ class PurchaseOrder(models.Model):
sale_order = fields.Char(string='Sale Order')
matches_so = fields.Many2many('sale.order', string='Matches SO', compute='_compute_matches_so')
is_create_uangmuka = fields.Boolean(string='Uang Muka?')
- move_id = fields.Many2one('account.move', string='Journal Entries Uang Muka', domain=[('move_type', '=', 'entry')])
+ move_id = fields.Many2one('account.move', string='Journal Entries Uang Muka', domain=[('move_type', '=', 'entry')], copy=False)
logbook_bill_id = fields.Many2one('report.logbook.bill', string='Logbook Bill')
status_printed = fields.Selection([
('not_printed', 'Belum Print'),
diff --git a/indoteknik_custom/models/purchase_order_sales_match.py b/indoteknik_custom/models/purchase_order_sales_match.py
index b18864f3..084b93f7 100644
--- a/indoteknik_custom/models/purchase_order_sales_match.py
+++ b/indoteknik_custom/models/purchase_order_sales_match.py
@@ -39,7 +39,7 @@ class PurchaseOrderSalesMatch(models.Model):
('sale_line_id', '=', rec.sale_line_id.id),
])
if stock_move:
- rec.bu_pick = stock_move.picking_id.id
+ rec.bu_pick = stock_move[0].picking_id.id
else:
rec.bu_pick = None
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py
index 6d0b5741..9ab18f27 100644
--- a/indoteknik_custom/models/refund_sale_order.py
+++ b/indoteknik_custom/models/refund_sale_order.py
@@ -76,6 +76,7 @@ class RefundSaleOrder(models.Model):
transfer_move_id = fields.Many2one(
'account.move',
string="Journal Payment",
+ copy=False,
help="Pilih transaksi salah transfer dari jurnal Uang Muka (journal_id=11) yang tidak terkait SO."
)
@@ -392,6 +393,7 @@ class RefundSaleOrder(models.Model):
total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed'))
vals['total_invoice'] = total_invoice
uang_masuk = rec.uang_masuk
+
amount_refund = vals.get('amount_refund', rec.amount_refund)
if amount_refund <= 0:
@@ -401,36 +403,24 @@ class RefundSaleOrder(models.Model):
('sale_order_ids', 'in', so_ids),
('id', '!=', rec.id)
])
- total_refunded = sum(existing_refunds.mapped('amount_refund')) + amount_refund
- remaining = uang_masuk - total_refunded
+ total_refunded = sum(existing_refunds.mapped('amount_refund'))
+ if existing_refunds:
+ remaining = uang_masuk - total_refunded
+ else:
+ remaining = uang_masuk - amount_refund
if remaining < 0:
- raise ValidationError("❌ Dana uang masuk telah sepenuhnya di refund tidak bisa Mengubah Nominal Refund")
+ raise ValidationError("Semua dana sudah dikembalikan, tidak bisa mengajukan refund")
vals['remaining_refundable'] = remaining
return super().write(vals)
- @api.onchange('ongkir', 'amount_refund')
+ @api.onchange('amount_refund')
def _onchange_refund_fields(self):
for rec in self:
refund_input = rec.amount_refund or 0.0
-
- # ambil refund terakhir untuk SO
- existing_refund = self.env['refund.sale.order'].search([
- ('sale_order_ids', 'in', rec.sale_order_ids.ids)
- ], order='id desc', limit=1)
-
- if existing_refund:
- sisa_uang_masuk = existing_refund.remaining_refundable
- else:
- sisa_uang_masuk = rec.uang_masuk or 0.0
-
- # update field uang_masuk supaya form menampilkan sisa aktual
- rec.uang_masuk = sisa_uang_masuk
-
- # hitung remaining setelah input refund
- rec.remaining_refundable = sisa_uang_masuk - refund_input
+ rec.remaining_refundable = (rec.uang_masuk or 0.0) - refund_input
@api.depends('status_payment', 'status')
def _compute_is_locked(self):
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 903f834b..9952af9a 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -1899,26 +1899,30 @@ class SaleOrder(models.Model):
# raise UserError('Kelurahan Real Delivery Address harus diisi')
def generate_payment_link_midtrans_sales_order(self):
- # midtrans_url = 'https://app.sandbox.midtrans.com/snap/v1/transactions' # dev - sandbox
- # midtrans_auth = 'Basic U0ItTWlkLXNlcnZlci1uLVY3ZDJjMlpCMFNWRUQyOU95Q1dWWXA6' # dev - sandbox
- midtrans_url = 'https://app.midtrans.com/snap/v1/transactions' # production
- midtrans_auth = 'Basic TWlkLXNlcnZlci1SbGMxZ2gzWGpSVW5scl9JblZzTV9OTnU6' # production
+ # midtrans_url = 'https://app.sandbox.midtrans.com/snap/v1/transactions' # dev - sandbox
+ # midtrans_auth = 'Basic U0ItTWlkLXNlcnZlci1uLVY3ZDJjMlpCMFNWRUQyOU95Q1dWWXA6' # dev - sandbox
+ midtrans_url = 'https://app.midtrans.com/snap/v1/transactions' # production
+ midtrans_auth = 'Basic TWlkLXNlcnZlci1SbGMxZ2gzWGpSVW5scl9JblZzTV9OTnU6' # production
+
so_number = self.name
so_number = so_number.replace('/', '-')
so_grandtotal = math.floor(self.grand_total)
+
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': midtrans_auth,
}
- check_url = f'https://api.midtrans.com/v2/{so_number}/status'
- check_response = requests.get(check_url, headers=headers)
+ # ==== ENV ====
+ # check_url = f'https://api.sandbox.midtrans.com/v2/{so_number}/status' # dev - sandbox
+ check_url = f'https://api.midtrans.com/v2/{so_number}/status' # production
+ # =============================================
+ check_response = requests.get(check_url, headers=headers)
if check_response.status_code == 200:
status_response = check_response.json()
- if status_response.get('transaction_status') == 'expire' or status_response.get(
- 'transaction_status') == 'cancel':
+ if status_response.get('transaction_status') in ('expire', 'cancel'):
so_number = so_number + '-cpl'
json_data = {
@@ -1950,7 +1954,6 @@ class SaleOrder(models.Model):
buffer = BytesIO()
img.save(buffer, format="PNG")
qr_code_img = base64.b64encode(buffer.getvalue()).decode()
-
self.payment_qr_code = qr_code_img
@api.model
diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py
index 90ab30a4..24d405a6 100644
--- a/indoteknik_custom/models/stock_move.py
+++ b/indoteknik_custom/models/stock_move.py
@@ -1,6 +1,9 @@
from odoo import fields, models, api
from odoo.tools.misc import format_date, OrderedSet
from odoo.exceptions import UserError
+import logging
+
+_logger = logging.getLogger(__name__)
class StockMove(models.Model):
_inherit = 'stock.move'
@@ -15,7 +18,7 @@ class StockMove(models.Model):
barcode = fields.Char(string='Barcode', related='product_id.barcode')
vendor_id = fields.Many2one('res.partner' ,string='Vendor')
hold_outgoingg = fields.Boolean('Hold Outgoing', default=False)
-
+ product_image = fields.Binary(related="product_id.image_128", string="Product Image", readonly = True)
# @api.model_create_multi
# def create(self, vals_list):
# moves = super(StockMove, self).create(vals_list)
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py
index d2e00781..6e839bf0 100644
--- a/indoteknik_custom/models/tukar_guling.py
+++ b/indoteknik_custom/models/tukar_guling.py
@@ -134,7 +134,7 @@ class TukarGuling(models.Model):
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:
+ if rec.val_inv_opt == 'cancel_invoice' and self.is_has_invoice == True and rec.invoice_id.state != 'cancel':
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