line: disable column 'quantity_balance' if cashbook-feature != asset

This commit is contained in:
Frederik Jaeckel 2023-01-15 11:03:33 +01:00
parent 8acfa35289
commit 4ef14cd44b
5 changed files with 50 additions and 7 deletions

18
line.py
View file

@ -58,9 +58,11 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
}, depends=['currency_digits', 'quantity_digits', 'feature']),
'on_change_with_asset_rate')
quantity_balance = fields.Function(fields.Numeric(string='Quantity',
digits=(16, Eval('quantity_digits', 4)),
digits=(16, Eval('quantity_digits', 4)), readonly=True,
help='Number of shares in the cashbook up to the current row if the default sort applies.',
readonly=True, depends=['quantity_digits']),
states={
'invisible': Eval('feature', '') != 'asset',
}, depends=['quantity_digits', 'feature']),
'on_change_with_quantity_balance')
@classmethod
@ -134,7 +136,7 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
})
return result
@fields.depends('id', 'date', 'cashbook', \
@fields.depends('id', 'date', 'cashbook', 'feature',\
'_parent_cashbook.id', 'reconciliation', \
'_parent_reconciliation.start_quantity',\
'_parent_reconciliation.state')
@ -142,10 +144,12 @@ class Line(SecondUomMixin, metaclass=PoolMeta):
""" get quantity-balance
"""
Line2 = Pool().get('cashbook.line')
return Line2.get_balance_of_line(self,
field_name='quantity',
credit_name='quantity_credit',
debit_name='quantity_debit')
if self.feature == 'asset':
return Line2.get_balance_of_line(self,
field_name='quantity',
credit_name='quantity_credit',
debit_name='quantity_debit')
@fields.depends('quantity', 'amount', 'currency_digits', 'quantity_digits')
def on_change_with_asset_rate(self, name=None):

View file

@ -11,5 +11,16 @@ full copyright notices and license terms. -->
<field name="name">line_form</field>
</record>
<record model="ir.ui.view" id="line_view_list">
<field name="model">cashbook.line</field>
<field name="inherit" ref="cashbook.line_view_list"/>
<field name="name">line_list</field>
</record>
<record model="ir.ui.view" id="line_recon_view_list">
<field name="model">cashbook.line</field>
<field name="inherit" ref="cashbook.line_recon_view_list"/>
<field name="name">line_recon_list</field>
</record>
</data>
</tryton>

View file

@ -105,6 +105,9 @@ class SecondUomMixin(object):
for line in lines:
if line.booktransf is None:
continue
if (line.cashbook.quantity_uom is None) or \
(line.booktransf.quantity_uom is None):
continue
if line.cashbook.quantity_uom.id == line.booktransf.quantity_uom.id:
continue

13
view/line_list.xml Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!-- 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. -->
<data>
<xpath expr="/tree/field[@name='balance']" position="after">
<field name="quantity_credit"/>
<field name="quantity_debit"/>
<field name="quantity_balance"/>
</xpath>
</data>

12
view/line_recon_list.xml Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!-- 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. -->
<data>
<xpath expr="/tree/field[@name='debit']" position="after">
<field name="quantity_credit"/>
<field name="quantity_debit"/>
</xpath>
</data>