Add input location

This commit is contained in:
Sergi Almacellas Abellana 2016-04-08 10:07:23 +02:00
parent 891ed5259f
commit 940ad3b321
5 changed files with 58 additions and 6 deletions

View file

@ -6,10 +6,22 @@ msgctxt "error:stock.location:"
msgid "You do not have permisons to move products from location \"%s\"."
msgstr "No teniu permisos per moure productes des de la ubicació \"%s\"."
msgctxt "field:stock.location,inputs_group:"
msgid "Inputs Group"
msgstr "Group entrades"
msgctxt "field:stock.location,outputs_group:"
msgid "Outputs Group"
msgstr "Grup sortides"
msgctxt "help:stock.location,inputs_group:"
msgid ""
"If defined only users from this group will be allowed to make moves to this "
"location"
msgstr ""
"Si es defineix només els usuaris d'aquest grup podran realitzar moviments "
"cap a aquesta ubicació"
msgctxt "help:stock.location,outputs_group:"
msgid ""
"If defined only users from this group will be allowed to make moves from "

View file

@ -6,10 +6,22 @@ msgctxt "error:stock.location:"
msgid "You do not have permisons to move products from location \"%s\"."
msgstr "No tienes permisos para mover productos desde la ubicación \"%s\"."
msgctxt "field:stock.location,inputs_group:"
msgid "Inputs Group"
msgstr "Grupo entradas"
msgctxt "field:stock.location,outputs_group:"
msgid "Outputs Group"
msgstr "Grupo salidas"
msgctxt "help:stock.location,inputs_group:"
msgid ""
"If defined only users from this group will be allowed to make moves to this "
"location"
msgstr ""
"Si se define, solo los usuarios de este grupo podrán realizar movimientos "
"hacia esta ubiación"
msgctxt "help:stock.location,outputs_group:"
msgid ""
"If defined only users from this group will be allowed to make moves from "

View file

@ -16,6 +16,10 @@ class Location:
states=STATES, depends=DEPENDS,
help='If defined only users from this group will be allowed to make '
'moves from this location')
inputs_group = fields.Many2One('res.group', 'Inputs Group',
states=STATES, depends=DEPENDS,
help='If defined only users from this group will be allowed to make '
'moves to this location')
@classmethod
def __setup__(cls):
@ -27,20 +31,30 @@ class Location:
})
@classmethod
def check_location_outputs_group(cls, locations):
def _check_location_group(cls, locations, type_):
pool = Pool()
User = pool.get('res.user')
user_id = Transaction().user
if user_id == 0:
return
groups = set(User(user_id).groups)
field_name = '%s_group' % type_
for location in locations:
if not location.outputs_group:
group = getattr(location, field_name)
if not group:
continue
if location.outputs_group not in groups:
if group not in groups:
cls.raise_user_error('no_permissions_for_output_moves',
location.rec_name)
@classmethod
def check_location_outputs_group(cls, locations):
return cls._check_location_group(locations, 'outputs')
@classmethod
def check_location_inputs_group(cls, locations):
return cls._check_location_group(locations, 'inputs')
class Move:
__name__ = 'stock.move'
@ -50,8 +64,10 @@ class Move:
pool = Pool()
Location = pool.get('stock.location')
super(Move, cls).validate(moves)
locations = set([])
from_locations, to_locations = set(), set()
for move in moves:
if move.state == 'done' and move.internal_quantity:
locations.add(move.from_location)
Location.check_location_outputs_group(list(locations))
from_locations.add(move.from_location)
to_locations.add(move.to_location)
Location.check_location_inputs_group(to_locations)
Location.check_location_outputs_group(from_locations)

View file

@ -57,6 +57,7 @@ class TestCase(unittest.TestCase):
}])
supplier, = self.location.search([('code', '=', 'SUP')])
storage, = self.location.search([('code', '=', 'STO')])
customer, = self.location.search([('code', '=', 'CUS')])
company, = self.company.search([
('rec_name', '=', 'Dunder Mifflin'),
])
@ -96,12 +97,21 @@ class TestCase(unittest.TestCase):
# No problem doing input move
do_move(storage, supplier)
do_move(storage, customer)
# Restricted input location
self.location.write([customer], {'inputs_group': group.id})
with self.assertRaises(UserError) as cm:
do_move(storage, customer)
self.assertEqual(cm.exception.message,
access_error % customer.rec_name)
# No problem if user belongs to restricted group
self.user.write([self.user(USER)], {
'groups': [('add', [group.id])],
})
do_move(supplier, storage)
do_move(storage, customer)
def suite():

View file

@ -5,5 +5,7 @@
<xpath expr="/form/field[@name='type']" position="after">
<label name="outputs_group"/>
<field name="outputs_group"/>
<label name="inputs_group"/>
<field name="inputs_group"/>
</xpath>
</data>