trytond-stock_product_categ.../product.py
Sergio Morillo a9c9bd921a Refactor modules.
This commit res #1266
2016-06-13 18:05:49 +02:00

40 lines
1.3 KiB
Python

# 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, Pool
__all__ = ['Category']
class Category:
__name__ = 'product.category'
__metaclass__ = PoolMeta
locations = fields.One2Many(
'stock.product.category.location', 'category', 'Default Locations')
default_location = fields.Function(fields.Many2One('stock.location', 'Default location'),
'get_default_location')
def get_default_location(self, **kwargs):
pool = Pool()
Location = pool.get('stock.product.category.location')
_domain = self._get_default_location_domain(**kwargs)
locations = Location.search(
_domain, order=self._get_default_location_order(),
limit=2)
if locations:
return locations[0].location.id
return None
def _get_default_location_domain(self, **kwargs):
_domain = [('category', '=', self.id),
('location.type', '=', kwargs.get('location_type', 'storage'))]
if kwargs.get('warehouse', None):
_domain.append(('warehouse', '=', kwargs['warehouse'].id))
return _domain
@staticmethod
def _get_default_location_order():
return [('sequence', 'ASC')]