44 lines
1.5 KiB
Python
Executable File
44 lines
1.5 KiB
Python
Executable File
# 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 ModelView, ModelSQL, fields
|
|
|
|
|
|
class ProductPosition(ModelSQL, ModelView):
|
|
"Product Position"
|
|
__name__ = "product.position"
|
|
name = fields.Char('Name', required=True)
|
|
warehouse = fields.Many2One('stock.location', 'Warehouse', states={
|
|
'required': True
|
|
}, domain=[('type', '=', 'warehouse')]
|
|
)
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super(ProductPosition, cls).__setup__()
|
|
cls._order.insert(0, ('name', 'ASC'))
|
|
|
|
# @classmethod
|
|
# def __register__(cls, module_name):
|
|
# table = cls.__table_handler__(module_name)
|
|
|
|
# # correction
|
|
# if table.column_exist('parent'):
|
|
# table.drop_column('parent')
|
|
|
|
|
|
class ProductTemplatePosition(ModelSQL, ModelView):
|
|
"Product Template Position"
|
|
__name__ = 'product_template.position'
|
|
|
|
# _rec_name = 'position'
|
|
position = fields.Many2One('product.position', 'Position', required=True, ondelete='CASCADE')
|
|
template = fields.Many2One('product.template', 'Template', required=True, ondelete='RESTRICT')
|
|
warehouse =fields.Function(fields.Many2One('stock.location', 'Warehouse'), 'on_change_with_warehouse')
|
|
|
|
|
|
@fields.depends('position')
|
|
def on_change_with_warehouse(self, name=None):
|
|
warehouse = None
|
|
if self.position:
|
|
warehouse = self.position.warehouse.id
|
|
return warehouse |