line/splitline: quantitiy-states korrigiert
This commit is contained in:
parent
b9b500624e
commit
bf84b092fc
3 changed files with 40 additions and 28 deletions
36
line.py
36
line.py
|
@ -6,22 +6,36 @@
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from trytond.model import fields
|
from trytond.model import fields
|
||||||
from trytond.pool import PoolMeta, Pool
|
from trytond.pool import PoolMeta, Pool
|
||||||
from trytond.pyson import Eval, Or, If
|
from trytond.pyson import Eval, Or, If, And
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
from trytond.i18n import gettext
|
from trytond.i18n import gettext
|
||||||
from trytond.report import Report
|
from trytond.report import Report
|
||||||
from trytond.modules.cashbook.line import STATES, DEPENDS
|
from trytond.modules.cashbook.line import STATES, DEPENDS
|
||||||
from .mixin import SecondUomMixin
|
from .mixin import SecondUomMixin
|
||||||
|
|
||||||
STATESQ = {
|
STATESQ1 = {
|
||||||
'required': Eval('feature', '') == 'asset',
|
'invisible': And(
|
||||||
'invisible': Eval('feature', '') != 'asset',
|
Eval('feature', '') != 'asset',
|
||||||
|
Eval('booktransf_feature', '') != 'asset',
|
||||||
|
),
|
||||||
|
'required': Or(
|
||||||
|
Eval('feature', '') == 'asset',
|
||||||
|
Eval('booktransf_feature', '') == 'asset',
|
||||||
|
),
|
||||||
'readonly': Or(
|
'readonly': Or(
|
||||||
STATES['readonly'],
|
STATES['readonly'],
|
||||||
Eval('bookingtype', '').in_(['spin', 'spout']),
|
Eval('bookingtype', '').in_(['spin', 'spout']),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
DEPENDSQ = DEPENDS+['feature', 'quantity_digits', 'bookingtype']
|
DEPENDSQ1 = ['feature', 'booktransf_feature', 'quantity_digits', 'bookingtype']
|
||||||
|
DEPENDSQ1.extend(DEPENDS)
|
||||||
|
|
||||||
|
|
||||||
|
STATESQ2 = {
|
||||||
|
'invisible': Eval('feature', '') != 'asset',
|
||||||
|
'required': Eval('feature', '') == 'asset',
|
||||||
|
}
|
||||||
|
DEPENDSQ2 = ['feature', 'quantity_digits', 'bookingtype']
|
||||||
|
|
||||||
|
|
||||||
class Line(SecondUomMixin, metaclass=PoolMeta):
|
class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
|
@ -29,19 +43,13 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
|
||||||
|
|
||||||
quantity = fields.Numeric(string='Quantity',
|
quantity = fields.Numeric(string='Quantity',
|
||||||
digits=(16, Eval('quantity_digits', 4)),
|
digits=(16, Eval('quantity_digits', 4)),
|
||||||
states=STATESQ, depends=DEPENDSQ)
|
states=STATESQ1, depends=DEPENDSQ1)
|
||||||
quantity_credit = fields.Numeric(string='Quantity Credit',
|
quantity_credit = fields.Numeric(string='Quantity Credit',
|
||||||
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
||||||
states={
|
states=STATESQ2, depends=DEPENDSQ2)
|
||||||
'invisible': STATESQ['invisible'],
|
|
||||||
'required': STATESQ['required'],
|
|
||||||
}, depends=DEPENDSQ)
|
|
||||||
quantity_debit = fields.Numeric(string='Quantity Debit',
|
quantity_debit = fields.Numeric(string='Quantity Debit',
|
||||||
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
digits=(16, Eval('quantity_digits', 4)), readonly=True,
|
||||||
states={
|
states=STATESQ2, depends=DEPENDSQ2)
|
||||||
'invisible': STATESQ['invisible'],
|
|
||||||
'required': STATESQ['required'],
|
|
||||||
}, depends=DEPENDSQ)
|
|
||||||
|
|
||||||
quantity_digits = fields.Function(fields.Integer(string='Digits',
|
quantity_digits = fields.Function(fields.Integer(string='Digits',
|
||||||
readonly=True, states={'invisible': True}),
|
readonly=True, states={'invisible': True}),
|
||||||
|
|
26
splitline.py
26
splitline.py
|
@ -6,27 +6,27 @@
|
||||||
|
|
||||||
from trytond.pool import PoolMeta, Pool
|
from trytond.pool import PoolMeta, Pool
|
||||||
from trytond.model import fields
|
from trytond.model import fields
|
||||||
from trytond.pyson import Eval, Or
|
from trytond.pyson import Eval, Or, And
|
||||||
|
from trytond.modules.cashbook.line import STATES
|
||||||
from .mixin import SecondUomMixin
|
from .mixin import SecondUomMixin
|
||||||
|
from .line import STATESQ1, DEPENDSQ1
|
||||||
|
|
||||||
|
STATESQ1A = {}
|
||||||
STATES = {
|
STATESQ1A.update(STATESQ1)
|
||||||
'readonly': Or(
|
STATESQ1A['readonly'] = ~And(
|
||||||
Eval('state', '') != 'edit',
|
~STATES['readonly'],
|
||||||
Eval('state_cashbook', '') != 'open',
|
Eval('bookingtype', '').in_(['spin', 'spout']),
|
||||||
),
|
Or(
|
||||||
'required': Eval('feature', '') == 'asset',
|
Eval('feature', '') == 'asset',
|
||||||
'invisible': Eval('feature', '') != 'asset',
|
Eval('booktransf_feature', '') == 'asset',
|
||||||
}
|
))
|
||||||
DEPENDS=['state', 'state_cashbook', 'feature']
|
|
||||||
|
|
||||||
|
|
||||||
class SplitLine(SecondUomMixin, metaclass=PoolMeta):
|
class SplitLine(SecondUomMixin, metaclass=PoolMeta):
|
||||||
__name__ = 'cashbook.split'
|
__name__ = 'cashbook.split'
|
||||||
|
|
||||||
quantity = fields.Numeric(string='Quantity',
|
quantity = fields.Numeric(string='Quantity',
|
||||||
digits=(16, Eval('quantity_digits', 4)),
|
digits=(16, Eval('quantity_digits', 4)),
|
||||||
states=STATES, depends=DEPENDS+['quantity_digits'])
|
states=STATESQ1A, depends=DEPENDSQ1)
|
||||||
quantity_digits = fields.Function(fields.Integer(string='Digits',
|
quantity_digits = fields.Function(fields.Integer(string='Digits',
|
||||||
readonly=True, states={'invisible': True}),
|
readonly=True, states={'invisible': True}),
|
||||||
'on_change_with_quantity_digits')
|
'on_change_with_quantity_digits')
|
||||||
|
|
|
@ -600,6 +600,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
||||||
self.assertEqual(book.lines[0].quantity_credit, None)
|
self.assertEqual(book.lines[0].quantity_credit, None)
|
||||||
self.assertEqual(book.lines[0].quantity_debit, None)
|
self.assertEqual(book.lines[0].quantity_debit, None)
|
||||||
self.assertEqual(book.lines[0].feature, 'gen')
|
self.assertEqual(book.lines[0].feature, 'gen')
|
||||||
|
self.assertEqual(book.lines[0].booktransf_feature, 'asset')
|
||||||
self.assertEqual(len(book2.lines), 0)
|
self.assertEqual(len(book2.lines), 0)
|
||||||
self.assertEqual(book.lines[0].rec_name,
|
self.assertEqual(book.lines[0].rec_name,
|
||||||
'05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 0.00 usd | Open | 0.0000 u]')
|
'05/01/2022|to|-1.00 usd|Transfer Out [Asset-Book | 0.00 usd | Open | 0.0000 u]')
|
||||||
|
@ -739,6 +740,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
||||||
self.assertEqual(book.lines[0].quantity_credit, None)
|
self.assertEqual(book.lines[0].quantity_credit, None)
|
||||||
self.assertEqual(book.lines[0].quantity_debit, None)
|
self.assertEqual(book.lines[0].quantity_debit, None)
|
||||||
self.assertEqual(book.lines[0].feature, 'gen')
|
self.assertEqual(book.lines[0].feature, 'gen')
|
||||||
|
self.assertEqual(book.lines[0].booktransf_feature, 'asset')
|
||||||
self.assertEqual(len(book2.lines), 0)
|
self.assertEqual(len(book2.lines), 0)
|
||||||
self.assertEqual(book.lines[0].rec_name,
|
self.assertEqual(book.lines[0].rec_name,
|
||||||
'05/01/2022|from|1.00 usd|Transfer In [Asset-Book | 0.00 usd | Open | 0.0000 u]')
|
'05/01/2022|from|1.00 usd|Transfer In [Asset-Book | 0.00 usd | Open | 0.0000 u]')
|
||||||
|
@ -863,6 +865,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
||||||
self.assertEqual(book.lines[0].quantity_credit, Decimal('1.5'))
|
self.assertEqual(book.lines[0].quantity_credit, Decimal('1.5'))
|
||||||
self.assertEqual(book.lines[0].quantity_debit, Decimal('0.0'))
|
self.assertEqual(book.lines[0].quantity_debit, Decimal('0.0'))
|
||||||
self.assertEqual(book.lines[0].feature, 'asset')
|
self.assertEqual(book.lines[0].feature, 'asset')
|
||||||
|
self.assertEqual(book.lines[0].booktransf_feature, 'asset')
|
||||||
self.assertEqual(len(book2.lines), 0)
|
self.assertEqual(len(book2.lines), 0)
|
||||||
self.assertEqual(book.lines[0].rec_name,
|
self.assertEqual(book.lines[0].rec_name,
|
||||||
'05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | 0.00 usd | Open | 0.0000 u]|1.5000 u')
|
'05/01/2022|from|1.00 usd|Transfer In [Asset-Book 1 | 0.00 usd | Open | 0.0000 u]|1.5000 u')
|
||||||
|
@ -1228,6 +1231,7 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
||||||
{
|
{
|
||||||
'lines': [('create', [{
|
'lines': [('create', [{
|
||||||
'bookingtype': 'spin',
|
'bookingtype': 'spin',
|
||||||
|
'date': date(2022, 5, 1),
|
||||||
'splitlines': [('create', [{
|
'splitlines': [('create', [{
|
||||||
'amount': Decimal('5.0'),
|
'amount': Decimal('5.0'),
|
||||||
'splittype': 'cat',
|
'splittype': 'cat',
|
||||||
|
@ -1251,6 +1255,6 @@ class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
|
||||||
self.assertEqual(book.lines[0].amount, Decimal('11.0'))
|
self.assertEqual(book.lines[0].amount, Decimal('11.0'))
|
||||||
self.assertEqual(book.lines[0].quantity, Decimal('4.0'))
|
self.assertEqual(book.lines[0].quantity, Decimal('4.0'))
|
||||||
self.assertEqual(book.lines[0].quantity_uom.symbol, 'u')
|
self.assertEqual(book.lines[0].quantity_uom.symbol, 'u')
|
||||||
self.assertEqual(book.lines[0].rec_name, '01/15/2023|Rev/Sp|11.00 usd|- [-]|4.00 u')
|
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev/Sp|11.00 usd|- [-]|4.00 u')
|
||||||
|
|
||||||
# end CbInvTestCase
|
# end CbInvTestCase
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue