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
|
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class StockLocation(models.Model):
_inherit = 'stock.location'
rack_level = fields.Integer(
string='Sequence',
default=1,
help='Indicates the vertical rack level (1 = lowest, 4 = highest).'
)
# level = fields.Integer(
# string='Rack Level',
# default=1,
# help='Indicates the vertical rack level (1 = lowest, 4 = highest).'
# )
is_locked = fields.Boolean(
string="Locked",
default=False,
help="Jika dicentang, lokasi ini tidak dapat digunakan untuk reservasi atau penerimaan barang."
)
@api.constrains('rack_level')
def _check_rack_level(self):
for rec in self:
if rec.rack_level < 1 or rec.rack_level > 4:
raise ValidationError(_("Rack level harus antara 1 sampai 4."))
@api.constrains('is_locked')
def _sync_locked_quant(self):
Quant = self.env['stock.quant']
for rec in self:
quants = Quant.search([('location_id', '=', rec.id)])
if quants:
if rec.is_locked:
quants.write({'note': 'Locked'})
else:
quants.write({'note': False})
|