summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-04-24 13:49:35 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-04-24 13:49:35 +0700
commit4706b80d3d3b1e55c198d2b4cfb93f7fa47c9732 (patch)
tree259b9fd8cd9a0d4ea0d37af5778c00c88136e122
parentbeb2ef24d462075dc390018afe1127db313fb404 (diff)
validation duplicate barcode product and barcode box, cr date doc kirim, validation duplicate product id on so line
-rw-r--r--indoteknik_custom/models/approval_date_doc.py9
-rw-r--r--indoteknik_custom/models/barcoding_product.py13
-rwxr-xr-xindoteknik_custom/models/sale_order.py10
-rw-r--r--indoteknik_custom/models/stock_picking.py12
-rw-r--r--indoteknik_custom/views/stock_picking.xml1
5 files changed, 36 insertions, 9 deletions
diff --git a/indoteknik_custom/models/approval_date_doc.py b/indoteknik_custom/models/approval_date_doc.py
index 751bae82..1a2749d5 100644
--- a/indoteknik_custom/models/approval_date_doc.py
+++ b/indoteknik_custom/models/approval_date_doc.py
@@ -39,12 +39,15 @@ class ApprovalDateDoc(models.Model):
if not self.env.user.is_accounting:
raise UserError("Hanya Accounting Yang Bisa Approve")
self.check_invoice_so_picking
- self.picking_id.driver_departure_date = self.driver_departure_date
- self.picking_id.date_doc_kirim = self.driver_departure_date
+ # Tambahkan context saat mengupdate date_doc_kirim
+ self.picking_id.with_context(from_button_approve=True).write({
+ 'driver_departure_date': self.driver_departure_date,
+ 'date_doc_kirim': self.driver_departure_date
+ })
self.state = 'done'
self.approve_date = datetime.utcnow()
self.approve_by = self.env.user.id
-
+
def button_cancel(self):
self.state = 'cancel'
diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py
index 353f94d5..e28473ff 100644
--- a/indoteknik_custom/models/barcoding_product.py
+++ b/indoteknik_custom/models/barcoding_product.py
@@ -16,9 +16,22 @@ class BarcodingProduct(models.Model):
barcode = fields.Char(string="Barcode")
qty_pcs_box = fields.Char(string="Quantity Pcs Box")
+ def check_duplicate_barcode(self):
+ barcode_product = self.env['product.product'].search([('barcode', '=', self.barcode)])
+
+ if barcode_product:
+ raise UserError('Barcode sudah digunakan {}'.format(barcode_product.display_name))
+
+ barcode_box = self.env['product.product'].search([('barcode_box', '=', self.barcode)])
+
+ if barcode_box:
+ raise UserError('Barcode box sudah digunakan {}'.format(barcode_box.display_name))
+
+
@api.constrains('barcode')
def _send_barcode_to_product(self):
for record in self:
+ record.check_duplicate_barcode()
if record.type == 'barcoding_box':
record.product_id.barcode_box = record.barcode
record.product_id.qty_pcs_box = record.qty_pcs_box
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 39d6fd0b..02d61387 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -1069,7 +1069,16 @@ class SaleOrder(models.Model):
raise UserError("Product BOM belum dikonfirmasi di Manufacturing Orders. Silakan hubungi MD.")
else:
raise UserError("Product BOM tidak di temukan di manufacturing orders, silahkan hubungi MD")
+
+ def check_duplicate_product(self):
+ for order in self:
+ for line in order.order_line:
+ search_product = self.env['sale.order.line'].search([('product_id', '=', line.product_id.id), ('order_id', '=', order.id)])
+ if len(search_product) > 1:
+ raise UserError("Terdapat DUPLIKASI data pada Product {}".format(line.product_id.display_name))
+
def sale_order_approve(self):
+ self.check_duplicate_product()
self.check_product_bom()
self.check_credit_limit()
self.check_limit_so_to_invoice()
@@ -1310,6 +1319,7 @@ class SaleOrder(models.Model):
def action_confirm(self):
for order in self:
+ order.check_duplicate_product()
order.check_product_bom()
order.check_credit_limit()
order.check_limit_so_to_invoice()
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 6168d3b2..f812df86 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -102,10 +102,9 @@ class StockPicking(models.Model):
], string='Approval Return Status', readonly=True, copy=False, index=True, tracking=3, help="Approval Status untuk Return")
date_doc_kirim = fields.Datetime(string='Tanggal Kirim di SJ', help="Tanggal Kirim di cetakan SJ, tidak berpengaruh ke Accounting", tracking=True, copy=False)
note_logistic = fields.Selection([
- ('hold', 'Hold by Sales'),
+ ('wait_so_together', 'Tunggu SO Barengan'),
('not_paid', 'Customer belum bayar'),
- ('partial', 'Kirim Parsial'),
- ('indent', 'Indent'),
+ ('reserve_stock', 'Reserve Stock'),
('waiting_schedule', 'Menunggu Jadwal Kirim'),
('self_pickup', 'Barang belum di pickup Customer'),
('expedition_closed', 'Eskpedisi belum buka')
@@ -141,7 +140,8 @@ class StockPicking(models.Model):
('done', 'Done'),
('cancel', 'Cancelled'),
], string='Status Reserve', tracking=True, copy=False, help="The current state of the stock picking.")
- notee = fields.Text(string="Note")
+ notee = fields.Text(string="Note SJ", help="Catatan untuk kirim barang")
+ note_info = fields.Text(string="Note", help="Catatan untuk pengiriman")
state_approve_md = fields.Selection([
('waiting', 'Waiting For Approve by MD'),
('pending', 'Pending (perlu koordinasi dengan MD)'),
@@ -253,7 +253,7 @@ class StockPicking(models.Model):
def _check_date_doc_kirim_modification(self):
for record in self:
- if record.last_update_date_doc_kirim:
+ if record.last_update_date_doc_kirim and not self.env.context.get('from_button_approve'):
kirim_date = fields.Datetime.from_string(record.last_update_date_doc_kirim)
now = fields.Datetime.now()
@@ -275,7 +275,7 @@ class StockPicking(models.Model):
if invoice and not self.env.context.get('active_model') == 'stock.picking':
rec._check_date_doc_kirim_modification()
- if rec.date_doc_kirim != invoice.invoice_date:
+ if rec.date_doc_kirim != invoice.invoice_date and not self.env.context.get('from_button_approve'):
get_approval_invoice_date = self.env['approval.invoice.date'].search([('picking_id', '=', rec.id),('state', '=', 'draft')], limit=1)
if get_approval_invoice_date and get_approval_invoice_date.state == 'draft':
diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml
index e99f8653..dd319bea 100644
--- a/indoteknik_custom/views/stock_picking.xml
+++ b/indoteknik_custom/views/stock_picking.xml
@@ -173,6 +173,7 @@
<page string="Delivery" name="delivery_order" attrs="{'invisible': [('location_dest_id', '=', 60)]}">
<group>
<group>
+ <field name="note_info"/>
<field name="notee"/>
<field name="note_logistic"/>
<field name="responsible" />