summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-09-15 11:02:36 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-09-15 11:02:36 +0000
commit2bb9e9f01c795f3b72593c1286a9a56ea6e2e120 (patch)
treed51422169ea4b005c9076e7efdcd83589d0c2e1f
parente432f70b5588c1ab86add20ee15df20d2f2a3876 (diff)
parentcc51c51ac0e89e3edf762b1a7a809ce8304dc53c (diff)
Merged in cr_lsj (pull request #413)
<Miqdad> add line no
-rw-r--r--indoteknik_custom/models/logbook_sj.py5
-rw-r--r--indoteknik_custom/models/report_logbook_sj.py58
-rw-r--r--indoteknik_custom/views/report_logbook_sj.xml2
3 files changed, 62 insertions, 3 deletions
diff --git a/indoteknik_custom/models/logbook_sj.py b/indoteknik_custom/models/logbook_sj.py
index 75b2622f..0cda9c8b 100644
--- a/indoteknik_custom/models/logbook_sj.py
+++ b/indoteknik_custom/models/logbook_sj.py
@@ -24,6 +24,7 @@ class LogbookSJ(models.TransientModel):
}
report_logbook = self.env['report.logbook.sj'].create([parameters_header])
+ seq=1
for line in logbook_line:
picking = self.env['stock.picking'].search([('picking_code', '=', line.name)], limit=1)
if not picking:
@@ -43,9 +44,11 @@ class LogbookSJ(models.TransientModel):
'tracking_no': stock.delivery_tracking_no,
'partner_id': parent_id,
'report_logbook_sj_id': report_logbook.id,
- 'note': line.note
+ 'note': line.note,
+ 'line_num': seq
}
self.env['report.logbook.sj.line'].create([data])
+ seq += 1
report_logbook_ids.append(report_logbook.id)
line.unlink()
diff --git a/indoteknik_custom/models/report_logbook_sj.py b/indoteknik_custom/models/report_logbook_sj.py
index 17119c12..66edbf99 100644
--- a/indoteknik_custom/models/report_logbook_sj.py
+++ b/indoteknik_custom/models/report_logbook_sj.py
@@ -1,3 +1,5 @@
+from operator import index
+
from odoo import models, fields, api
from odoo.exceptions import UserError
from pytz import timezone
@@ -60,9 +62,30 @@ class ReportLogbookSJ(models.Model):
self.state = 'terima_semua'
else:
raise UserError('Hanya Accounting yang bisa Approve')
-
+
+
+ def write(self, vals):
+ res = super(ReportLogbookSJ, self).write(vals)
+ if 'report_logbook_sj_line' in vals or any(f in vals for f in ()):
+ self._resequence_lines()
+ return res
+
+ def _resequence_lines(self):
+ for rec in self:
+ lines = rec.report_logbook_sj_line.sorted(key=lambda l: (l.line_num or 0, l.id))
+ for idx, line in enumerate(lines, start=1):
+ if line.line_num != idx:
+ line.line_num = idx
+
+ @api.onchange('report_logbook_sj_line')
+ def _onchange_report_logbook_sj_line(self):
+ self._resequence_lines()
+
+from odoo import models, fields, api
+
class ReportLogbookSJLine(models.Model):
_name = 'report.logbook.sj.line'
+ _order = 'sequence, id' # urut default di UI & ORM (drag pakai sequence)
name = fields.Char(string='SJ Number')
driver_id = fields.Many2one(comodel_name='res.users', string='Driver')
@@ -70,10 +93,41 @@ class ReportLogbookSJLine(models.Model):
arrival_date = fields.Char(string='Arrival Date')
carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method')
tracking_no = fields.Char(string='Tracking No')
- logbook_sj_id = fields.Many2one('report.logbook.sj', string='Logbook SJ') # Corrected model name
+
+ # NOTE: field ini duplikat relasi; pakai salah satu saja.
+ # kamu boleh hapus logbook_sj_id kalau tidak dipakai di tempat lain.
+ logbook_sj_id = fields.Many2one('report.logbook.sj', string='Logbook SJ')
+
partner_id = fields.Many2one('res.partner', string='Customer')
picking_id = fields.Many2one('stock.picking', string='Picking')
sale_id = fields.Many2one('sale.order', string='Sale Order')
+
report_logbook_sj_id = fields.Many2one('report.logbook.sj', string='Logbook SJ')
not_exist = fields.Boolean(string='Not Exist')
note = fields.Char(string='Note')
+
+ sequence = fields.Integer(string='Sequence', default=0, index=True)
+
+ line_num = fields.Integer(string='No', compute='_compute_line_num', store=False)
+
+ @api.depends(
+ 'report_logbook_sj_id.report_logbook_sj_line',
+ 'report_logbook_sj_id.report_logbook_sj_line.sequence'
+ )
+ def _compute_line_num(self):
+ for parent in self.mapped('report_logbook_sj_id'):
+ lines = parent.report_logbook_sj_line.sorted(key=lambda l: (l.sequence or 0, l.id))
+ for i, l in enumerate(lines, start=1):
+ l.line_num = i
+ for rec in self.filtered(lambda r: not r.report_logbook_sj_id):
+ rec.line_num = 0
+
+ @api.model
+ def create(self, vals):
+ if not vals.get('sequence') and vals.get('report_logbook_sj_id'):
+ last = self.search(
+ [('report_logbook_sj_id', '=', vals['report_logbook_sj_id'])],
+ order='sequence desc, id desc', limit=1
+ )
+ vals['sequence'] = (last.sequence or 0) + 1
+ return super().create(vals)
diff --git a/indoteknik_custom/views/report_logbook_sj.xml b/indoteknik_custom/views/report_logbook_sj.xml
index 94f6c2ab..2b7cfa22 100644
--- a/indoteknik_custom/views/report_logbook_sj.xml
+++ b/indoteknik_custom/views/report_logbook_sj.xml
@@ -21,6 +21,8 @@
<field name="model">report.logbook.sj.line</field>
<field name="arch" type="xml">
<tree editable="bottom">
+<!-- <field name="sequence" widget="handle"/>-->
+ <field name="line_num" string="No" readonly="1"/>
<field name="name"/>
<field name="driver_id"/>
<field name="departure_date"/>