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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
from odoo import fields, models, api, _
from odoo.exceptions import AccessError, UserError, ValidationError
class StockPicking(models.Model):
_inherit = 'stock.picking'
is_internal_use = fields.Boolean('Internal Use', help='flag which is internal use or not')
account_id = fields.Many2one('account.account', string='Account')
efaktur_id = fields.Many2one('vit.efaktur', string='Faktur Pajak')
is_efaktur_exported = fields.Boolean(string='Is eFaktur Exported')
date_efaktur_exported = fields.Datetime(string='eFaktur Exported Date')
delivery_status = fields.Char(string='Delivery Status', compute='compute_delivery_status', readonly=True)
summary_qty_detail = fields.Float('Total Qty Detail', compute='_compute_summary_qty')
summary_qty_operation = fields.Float('Total Qty Operation', compute='_compute_summary_qty')
count_line_detail = fields.Float('Total Item Detail', compute='_compute_summary_qty')
count_line_operation = fields.Float('Total Item Operation', compute='_compute_summary_qty')
real_shipping_id = fields.Many2one(
'res.partner', string='Real Delivery Address',
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
help="Dipakai untuk alamat tempel")
# Delivery Order
driver_departure_date = fields.Datetime(
string='Driver Departure Date',
readonly=True,
copy=False
)
driver_arrival_date = fields.Datetime(
string='Driver Arrival Date',
readonly=True,
copy=False
)
delivery_tracking_no = fields.Char(
string='Delivery Tracking Number',
readonly=True,
copy=False
)
driver_id = fields.Many2one(
comodel_name='res.users',
string='Driver',
readonly=True,
copy=False
)
picking_code = fields.Char(
string="Picking Code",
readonly=True,
copy=False
)
approval_status = fields.Selection([
('pengajuan1', 'Approval Accounting'),
('approved', 'Approved'),
], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
def action_assign(self):
res = super(StockPicking, self).action_assign()
self.real_shipping_id = self.sale_id.real_shipping_id
return res
def ask_approval(self):
if self.env.user.is_accounting:
raise UserError("Bisa langsung Validate")
for pick in self:
if not pick.is_internal_use:
raise UserError("Selain Internal Use bisa langsung Validate")
for line in pick.move_line_ids_without_package:
if line.qty_done <= 0:
raise UserError("Qty tidak boleh 0")
pick.approval_status = 'pengajuan1'
def calculate_line_no(self):
line_no = 0
for picking in self:
for line in picking.move_ids_without_package:
if line.product_id.type == 'product':
line_no += 1
line.line_no = line_no
# _logger.info('Calculate PO Line No %s' % line.id)
def _compute_summary_qty(self):
sum_qty_detail = sum_qty_operation = count_line_detail = count_line_operation = 0
for picking in self:
for detail in picking.move_line_ids_without_package: # detailed operations
sum_qty_detail += detail.qty_done
count_line_detail += 1
for operation in picking.move_ids_without_package: # operations
sum_qty_operation += operation.product_uom_qty
count_line_operation += 1
picking.summary_qty_detail = sum_qty_detail
picking.count_line_detail = count_line_detail
picking.summary_qty_operation = sum_qty_operation
picking.count_line_operation = count_line_operation
@api.onchange('picking_type_id')
def _onchange_operation_type(self):
self.is_internal_use = self.picking_type_id.is_internal_use
return
def button_validate(self):
if not self.picking_code:
self.picking_code = self.env['ir.sequence'].next_by_code('stock.picking.code') or '0'
if self.picking_type_id.code == 'incoming' and self.group_id.id == False and self.is_internal_use == False:
raise UserError(_('Tidak bisa Validate jika tidak dari Document SO / PO'))
if self.is_internal_use and not self.env.user.is_accounting:
raise UserError("Harus di Approve oleh Accounting")
res = super(StockPicking, self).button_validate()
return res
@api.model
def create(self, vals):
self._use_faktur(vals)
return super(StockPicking, self).create(vals)
def write(self, vals):
self._use_faktur(vals)
return super(StockPicking, self).write(vals)
def _use_faktur(self, vals):
if vals.get('efaktur_id', False):
self.env['vit.efaktur'].search(
[
('id', '=', vals['efaktur_id'])
],
limit=1
).is_used = True
if self.efaktur_id.id != vals['efaktur_id']:
self.efaktur_id.is_used = False
return True
def compute_delivery_status(self):
for picking in self:
if not picking.driver_departure_date and picking.picking_code:
picking.delivery_status = "Sedang Dikemas"
elif picking.driver_departure_date and not picking.driver_arrival_date:
picking.delivery_status = "Dalam Perjalanan"
elif picking.driver_departure_date and picking.driver_arrival_date and picking.carrier_id == 1:
picking.delivery_status = "Diterima Konsumen"
elif picking.driver_departure_date and picking.driver_arrival_date and picking.carrier_id != 1:
picking.delivery_status = "Diterima Ekspedisi"
else:
picking.delivery_status = "Diterima Konsumen"
|