Add a global method to set default warehouse
issue8396 review277371003
This commit is contained in:
1 parent
e8b713a3d1
commit
40a403c77b
10 files changed
+100
-16
No files matched your search
@@ -1,3 +1,5 @@
|
||||
* Let the user select a default warehouse
|
||||
* Add method to get default warehouse
|
||||
* Improve moves synchronisation on shipments
|
||||
* Allow move as move's origin
|
||||
* Open product quantities by warehouse to show moves
|
||||
|
||||
@@ -10,6 +10,7 @@ from . import product
|
||||
from . import inventory
|
||||
from . import configuration
|
||||
from . import party
|
||||
from . import res
|
||||
|
||||
from .move import StockMixin
|
||||
|
||||
@@ -47,6 +48,7 @@ def register():
|
||||
configuration.Configuration,
|
||||
configuration.ConfigurationSequence,
|
||||
configuration.ConfigurationLocation,
|
||||
res.User,
|
||||
module='stock', type_='model')
|
||||
Pool.register(
|
||||
shipment.AssignShipmentOut,
|
||||
|
||||
+29
@@ -9,6 +9,7 @@ from trytond.model import (
|
||||
ModelView, ModelSQL, MatchMixin, ValueMixin, DeactivableMixin, fields,
|
||||
sequence_ordered, tree)
|
||||
from trytond import backend
|
||||
from trytond.cache import Cache
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
@@ -29,6 +30,9 @@ DEPENDS = ['active']
|
||||
class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
"Stock Location"
|
||||
__name__ = 'stock.location'
|
||||
_default_warehouse_cache = Cache('stock.location.default_warehouse',
|
||||
context=False)
|
||||
|
||||
name = fields.Char("Name", size=None, required=True, states=STATES,
|
||||
depends=DEPENDS, translate=True)
|
||||
code = fields.Char("Code", size=None, states=STATES, depends=DEPENDS,
|
||||
@@ -295,6 +299,24 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
if locations:
|
||||
return locations[0].id
|
||||
|
||||
@classmethod
|
||||
def get_default_warehouse(cls):
|
||||
warehouse = Transaction().context.get('warehouse')
|
||||
if warehouse:
|
||||
return warehouse
|
||||
|
||||
warehouse = cls._default_warehouse_cache.get(None, -1)
|
||||
if warehouse == -1:
|
||||
warehouses = cls.search([
|
||||
('type', '=', 'warehouse'),
|
||||
], limit=2)
|
||||
if len(warehouses) == 1:
|
||||
warehouse = warehouses[0].id
|
||||
else:
|
||||
warehouse = None
|
||||
cls._default_warehouse_cache.set(None, warehouse)
|
||||
return warehouse
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
if clause[1].startswith('!') or clause[1].startswith('not '):
|
||||
@@ -436,6 +458,7 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
def create(cls, vlist):
|
||||
locations = super(Location, cls).create(vlist)
|
||||
cls._set_warehouse_parent(locations)
|
||||
cls._default_warehouse_cache.clear()
|
||||
return locations
|
||||
|
||||
@classmethod
|
||||
@@ -443,6 +466,7 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
super(Location, cls).write(*args)
|
||||
locations = sum(args[::2], [])
|
||||
cls._set_warehouse_parent(locations)
|
||||
cls._default_warehouse_cache.clear()
|
||||
|
||||
ids = [l.id for l in locations]
|
||||
warehouses = cls.search([
|
||||
@@ -469,6 +493,11 @@ class Location(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
location=location.rec_name,
|
||||
warehouse=warehouse.rec_name))
|
||||
|
||||
@classmethod
|
||||
def delete(cls, *args):
|
||||
super().delete(*args)
|
||||
cls._default_warehouse_cache.clear()
|
||||
|
||||
@classmethod
|
||||
def copy(cls, locations, default=None):
|
||||
if default is None:
|
||||
|
||||
+3
-7
@@ -462,14 +462,10 @@ class ProductQuantitiesByWarehouseContext(ModelView):
|
||||
],
|
||||
help="The warehouse for which the quantities will be calculated.")
|
||||
|
||||
@staticmethod
|
||||
def default_warehouse():
|
||||
@classmethod
|
||||
def default_warehouse(cls):
|
||||
Location = Pool().get('stock.location')
|
||||
warehouses = Location.search([
|
||||
('type', '=', 'warehouse'),
|
||||
])
|
||||
if len(warehouses) == 1:
|
||||
return warehouses[0].id
|
||||
return Location.get_default_warehouse()
|
||||
|
||||
|
||||
class OpenProductQuantitiesByWarehouse(Wizard):
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
|
||||
class User(metaclass=PoolMeta):
|
||||
__name__ = 'res.user'
|
||||
|
||||
warehouse = fields.Many2One('stock.location',
|
||||
"Current Warehouse",
|
||||
domain=[('type', '=', 'warehouse')],
|
||||
help="The warehouse that the user works at.")
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(User, cls).__setup__()
|
||||
cls._context_fields.insert(0, 'warehouse')
|
||||
|
||||
@classmethod
|
||||
def _get_preferences(cls, user, context_only=False):
|
||||
preferences = super()._get_preferences(user, context_only=context_only)
|
||||
if user.warehouse:
|
||||
preferences['warehouse'] = user.warehouse.id
|
||||
return preferences
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="user_view_form">
|
||||
<field name="model">res.user</field>
|
||||
<field name="inherit" ref="res.user_view_form"/>
|
||||
<field name="name">user_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="user_view_form_preferences">
|
||||
<field name="model">res.user</field>
|
||||
<field name="inherit" ref="res.user_view_form_preferences"/>
|
||||
<field name="name">user_form_preferences</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
+3
-9
@@ -236,9 +236,7 @@ class ShipmentIn(Workflow, ModelSQL, ModelView):
|
||||
@classmethod
|
||||
def default_warehouse(cls):
|
||||
Location = Pool().get('stock.location')
|
||||
locations = Location.search(cls.warehouse.domain)
|
||||
if len(locations) == 1:
|
||||
return locations[0].id
|
||||
return Location.get_default_warehouse()
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
@@ -995,9 +993,7 @@ class ShipmentOut(Workflow, ModelSQL, ModelView):
|
||||
@classmethod
|
||||
def default_warehouse(cls):
|
||||
Location = Pool().get('stock.location')
|
||||
locations = Location.search(cls.warehouse.domain)
|
||||
if len(locations) == 1:
|
||||
return locations[0].id
|
||||
return Location.get_default_warehouse()
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
@@ -1525,9 +1521,7 @@ class ShipmentOutReturn(Workflow, ModelSQL, ModelView):
|
||||
@classmethod
|
||||
def default_warehouse(cls):
|
||||
Location = Pool().get('stock.location')
|
||||
locations = Location.search(cls.warehouse.domain)
|
||||
if len(locations) == 1:
|
||||
return locations[0].id
|
||||
return Location.get_default_warehouse()
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
|
||||
@@ -17,3 +17,4 @@ xml:
|
||||
configuration.xml
|
||||
period.xml
|
||||
message.xml
|
||||
res.xml
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='user']/field[@name='employee']" position="after">
|
||||
<label name="warehouse"/>
|
||||
<field name="warehouse"/>
|
||||
</xpath>
|
||||
</data>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='user']/field[@name='employee']" position="after">
|
||||
<label name="warehouse"/>
|
||||
<field name="warehouse" help="The warehouse that you work at."/>
|
||||
</xpath>
|
||||
</data>
|
||||
Reference in new issue
Block a user