summaryrefslogtreecommitdiff
path: root/fixco_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-06-16 14:37:23 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-06-16 14:37:23 +0700
commit4a65f46a5b7fd1bc48bc04cbf456119332fff0fe (patch)
tree97219770248095c25a673d44dd8d0053d792a0f2 /fixco_custom/models
parent55936047e729cadcd462a57c7838f77f7c57ee1a (diff)
uangmuka penjualan and cr schema shipment group
Diffstat (limited to 'fixco_custom/models')
-rwxr-xr-xfixco_custom/models/__init__.py1
-rwxr-xr-xfixco_custom/models/sale.py11
-rw-r--r--fixco_custom/models/shipment_group.py52
-rw-r--r--fixco_custom/models/uangmuka_penjualan.py118
4 files changed, 182 insertions, 0 deletions
diff --git a/fixco_custom/models/__init__.py b/fixco_custom/models/__init__.py
index 9eba2c6..6ef28e0 100755
--- a/fixco_custom/models/__init__.py
+++ b/fixco_custom/models/__init__.py
@@ -13,3 +13,4 @@ from . import shipment_group
from . import stock_picking_shipment_group
from . import print_picking_list
from . import stock_picking_print_picking_list
+from . import uangmuka_penjualan
diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py
index bc7a734..fc46f3d 100755
--- a/fixco_custom/models/sale.py
+++ b/fixco_custom/models/sale.py
@@ -72,3 +72,14 @@ class SaleOrder(models.Model):
}
}
+ def open_form_uangmuka_penjualan(self):
+ return {
+ 'name': _('Create uang muka penjualan'),
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'uangmuka.penjualan',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': {
+ 'so_ids': self.ids,
+ }
+ }
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py
index 71d7981..5f6c315 100644
--- a/fixco_custom/models/shipment_group.py
+++ b/fixco_custom/models/shipment_group.py
@@ -13,6 +13,58 @@ class ShipmentGroup(models.Model):
number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True)
shipment_line = fields.One2many('shipment.group.line', 'shipment_id', string='Shipment Group Lines', auto_join=True)
+ scan_invoice = fields.Char(string="Scan Invoice Marketplace")
+
+ @api.onchange('scan_invoice')
+ def _onchange_scan_invoice(self):
+ if self.scan_invoice:
+ result = self.add_lines_from_scan(self.scan_invoice)
+ self.scan_invoice = False # Reset field setelah scan
+ return result
+
+ def add_lines_from_scan(self, scan_value):
+ self.ensure_one()
+ picking = self.env['stock.picking'].search([
+ ('invoice_mp', '=', scan_value)
+ ], limit=1)
+
+ if not picking:
+ return {
+ 'warning': {
+ 'title': 'Not Found',
+ 'message': f'No picking found with invoice: {scan_value}'
+ }
+ }
+
+ # Cek duplikat
+ existing_lines = self.shipment_line.filtered(lambda l: l.picking_id == picking)
+ if existing_lines:
+ return {
+ 'warning': {
+ 'title': 'Duplicate',
+ 'message': 'This picking has already been added to the shipment group'
+ }
+ }
+
+ # Buat line untuk setiap move
+ created_lines = []
+ for move in picking.move_ids_without_package:
+ line = self.env['shipment.group.line'].create({
+ 'shipment_id': self.id,
+ 'product_id': move.product_id.id,
+ 'carrier': picking.carrier,
+ 'invoice_marketplace': picking.invoice_mp,
+ 'picking_id': picking.id,
+ })
+ created_lines.append(line.id)
+
+ return {
+ 'effect': {
+ 'fadeout': 'slow',
+ 'message': f'Added {len(created_lines)} products from {picking.name}',
+ 'type': 'rainbow_man',
+ }
+ }
@api.model
def create(self, vals):
diff --git a/fixco_custom/models/uangmuka_penjualan.py b/fixco_custom/models/uangmuka_penjualan.py
new file mode 100644
index 0000000..9673bf1
--- /dev/null
+++ b/fixco_custom/models/uangmuka_penjualan.py
@@ -0,0 +1,118 @@
+from odoo import fields, models, _, api
+from odoo.exceptions import UserError
+from datetime import datetime
+from odoo.http import request
+
+import logging, math
+
+_logger = logging.getLogger(__name__)
+
+
+class UangmukaPenjualan(models.TransientModel):
+ _name = 'uangmuka.penjualan'
+ _description = 'digunakan untuk membuat Uang Muka Penjualan'
+
+ pay_amt = fields.Float(string='Uang Muka', help='berapa nilai yang terbentuk untuk COA Uang Muka Penjualan')
+ account_id = fields.Many2one('account.account', string='Bank Intransit', default=389, help='pilih COA intransit bank')
+ ongkir_amt = fields.Float(string='Ongkir', help='masukan nilai yang akan menjadi Pendapatan Ongkos Kirim')
+ selisih_amt = fields.Float(string='Selisih', help='masukan nilai yang akan menjadi Selisih Pembayaran')
+ total_amt = fields.Float(string='Total', help='Total yang akan masuk di journal entries')
+
+ @api.onchange('pay_amt', 'ongkir_amt', 'selisih_amt')
+ def _compute_total_amt(self):
+ for o in self:
+ o.total_amt = o.pay_amt + o.ongkir_amt + o.selisih_amt
+
+ def create_uangmukapenjualan(self):
+ if self.pay_amt <= 0:
+ raise UserError('Payment Amount harus diisi')
+ if not self.account_id:
+ raise UserError('Bank Intransit harus diisi')
+
+ is_have_ongkir = is_have_selisih = False
+
+ if self.ongkir_amt > 0:
+ is_have_ongkir = True
+ if not math.isclose(self.selisih_amt, 0):
+ is_have_selisih = True
+ # elif self.selisih_amt > 0:
+ # is_have_selisih = True
+
+ orders = self.env['sale.order'].browse(self._context.get('active_ids',[]))
+ current_time = datetime.now()
+
+ for order in orders:
+ partner_name = order.partner_id.name
+ if order.partner_id.parent_id:
+ partner_name = order.partner_id.parent_id.name
+ ref_label = 'UANG MUKA PENJUALAN '+order.name+' '+partner_name
+ param_header = {
+ 'ref': ref_label,
+ 'date': current_time,
+ 'journal_id': 24,
+ 'sale_id': order.id,
+ }
+
+ account_move = request.env['account.move'].create([param_header])
+ account_move.sale_id = order.id
+ _logger.info('Success Create Uang Muka Penjualan %s' % account_move.name)
+ if order.partner_id.parent_id:
+ partner_id = order.partner_id.parent_id.id
+ else:
+ partner_id = order.partner_id.id
+
+ param_debit = {
+ 'move_id': account_move.id,
+ 'account_id': self.account_id.id, # intransit
+ 'partner_id': partner_id,
+ 'currency_id': 12,
+ 'debit': self.pay_amt + self.ongkir_amt + self.selisih_amt,
+ 'credit': 0,
+ 'name': ref_label,
+ }
+ # sisa di credit untuk uang muka penjualan, diluar ongkir dan selisih
+ param_credit = {
+ 'move_id': account_move.id,
+ 'account_id': 578, # penerimaan belum alokasi
+ 'partner_id': partner_id,
+ 'currency_id': 12,
+ 'debit': 0,
+ 'credit': self.pay_amt,
+ 'name': ref_label,
+ }
+ param_ongkir_credit = {
+ 'move_id': account_move.id,
+ 'account_id': 488, # pendapatan ongkos kirim
+ 'partner_id': partner_id,
+ 'currency_id': 12,
+ 'debit': 0,
+ 'credit': self.ongkir_amt,
+ 'name': ref_label,
+ }
+ param_selisih_credit = {
+ 'move_id': account_move.id,
+ 'account_id': 767, # selisih pembayaran
+ 'partner_id': partner_id,
+ 'currency_id': 12,
+ 'debit': 0,
+ 'credit': self.selisih_amt,
+ 'name': ref_label,
+ }
+
+ if is_have_ongkir and is_have_selisih:
+ request.env['account.move.line'].create([param_debit, param_credit, param_ongkir_credit, param_selisih_credit])
+ elif is_have_ongkir:
+ request.env['account.move.line'].create([param_debit, param_credit, param_ongkir_credit])
+ elif is_have_selisih:
+ request.env['account.move.line'].create([param_debit, param_credit, param_selisih_credit])
+ else:
+ request.env['account.move.line'].create([param_debit, param_credit])
+ return {
+ 'name': _('Journal Entries'),
+ 'view_mode': 'form',
+ 'res_model': 'account.move',
+ 'target': 'current',
+ 'view_id': False,
+ 'type': 'ir.actions.act_window',
+ 'res_id': account_move.id
+ }