77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# This file is part of the cashbook-module from m-ds for 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.exceptions import UserError
|
|
from trytond.pool import PoolMeta
|
|
from trytond.pyson import Eval, Or, Len
|
|
from trytond.modules.cashbook.book import STATES2, DEPENDS2
|
|
|
|
|
|
class Book(metaclass=PoolMeta):
|
|
__name__ = 'cashbook.book'
|
|
|
|
asset = fields.Many2One(string='Asset',
|
|
model_name='investment.asset', ondelete='RESTRICT',
|
|
states={
|
|
'required': Eval('feature', '') == 'asset',
|
|
'invisible': Eval('feature', '') != 'asset',
|
|
'readonly': Or(
|
|
STATES2['readonly'],
|
|
Len(Eval('lines')) > 0,
|
|
),
|
|
}, depends=DEPENDS2+['feature', 'lines'])
|
|
quantity_digits = fields.Integer(string='Digits',
|
|
help='Quantity Digits',
|
|
domain=[
|
|
('quantity_digits', '>=', 0),
|
|
('quantity_digits', '<=', 6),
|
|
],
|
|
states={
|
|
'required': Eval('feature', '') == 'asset',
|
|
'invisible': Eval('feature', '') != 'asset',
|
|
'readonly': Or(
|
|
STATES2['readonly'],
|
|
Len(Eval('lines')) > 0,
|
|
),
|
|
}, depends=DEPENDS2+['feature', 'lines'])
|
|
asset_uomcat = fields.Function(fields.Many2One(string='UOM Category',
|
|
readonly=True, model_name='product.uom.category',
|
|
states={'invisible': True}), 'on_change_with_asset_uomcat')
|
|
quantity_uom = fields.Many2One(string='UOM',
|
|
model_name='product.uom', ondelete='RESTRICT',
|
|
domain=[
|
|
('category.id', '=', Eval('asset_uomcat', -1)),
|
|
],
|
|
states={
|
|
'required': Eval('feature', '') == 'asset',
|
|
'invisible': Eval('feature', '') != 'asset',
|
|
'readonly': Or(
|
|
STATES2['readonly'],
|
|
Len(Eval('lines')) > 0,
|
|
),
|
|
}, depends=DEPENDS2+['feature', 'lines', 'asset_uomcat'])
|
|
|
|
@fields.depends('asset', 'quantity_uom')
|
|
def on_change_asset(self):
|
|
""" get uom from asset
|
|
"""
|
|
if self.asset:
|
|
self.quantity_uom = self.asset.uom.id
|
|
|
|
@classmethod
|
|
def default_quantity_digits(cls):
|
|
""" default: 4
|
|
"""
|
|
return 4
|
|
|
|
@fields.depends('asset', '_parent_asset.uom')
|
|
def on_change_with_asset_uomcat(self, name=None):
|
|
""" get uom-category of asset
|
|
"""
|
|
if self.asset:
|
|
return self.asset.uom.category.id
|
|
|
|
# end Book
|