1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
from odoo import models, fields, api
from odoo.exceptions import UserError
from pytz import timezone
from datetime import datetime
class ReportLogbookSJ(models.Model):
_name = 'report.logbook.sj'
_description = "Logbook SJ"
_inherit = ['mail.thread']
_rec_name = 'name'
name = fields.Char(string='Name', default='Logbook SJ')
date = fields.Datetime(string='Date Created')
date_approve = fields.Datetime(string='Date Approve', tracking=3)
approve_by_finance = fields.Boolean(string='Approve By Finance', tracking=3)
approve_by = fields.Many2one(comodel_name='res.users', string='Approve By', tracking=3)
created_by = fields.Many2one(comodel_name='res.users', string='Created By', tracking=3)
report_logbook_sj_line = fields.One2many(
comodel_name='report.logbook.sj.line',
inverse_name='report_logbook_sj_id',
string='Logbook SJ Line'
)
state = fields.Selection(
[('belum_terima', 'Belum Terima'),
('terima_sebagian', 'Terima Sebagian'),
('terima_semua', 'Sudah di terima semua'),
],
default='terima_semua',
string='Status',
tracking=True,
)
sj_number = fields.Char(string='Picking', related='report_logbook_sj_line.name')
count_line = fields.Char(string='Count Line', compute='_compute_count_line')
@api.depends('report_logbook_sj_line')
def _compute_count_line(self):
for rec in self:
rec.count_line = len(rec.report_logbook_sj_line)
@api.model
def create(self, vals):
vals['name'] = self.env['ir.sequence'].next_by_code('report.logbook.sj') or '0'
result = super(ReportLogbookSJ, self).create(vals)
return result
def approve(self):
current_time = datetime.utcnow()
if self.env.user.is_accounting:
self.approve_by_finance = True
self.date_approve = current_time
self.approve_by = self.env.user.id
if any(line.not_exist for line in self.report_logbook_sj_line):
if all(line.not_exist for line in self.report_logbook_sj_line):
self.state = 'belum_terima'
else:
self.state = 'terima_sebagian'
else:
self.state = 'terima_semua'
else:
raise UserError('Hanya Accounting yang bisa Approve')
class ReportLogbookSJLine(models.Model):
_name = 'report.logbook.sj.line'
name = fields.Char(string='SJ Number')
driver_id = fields.Many2one(comodel_name='res.users', string='Driver')
departure_date = fields.Char(string='Departure Date')
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
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')
|