felder symbol, name, product_uom optimiert,

felder company_currency entfernt
This commit is contained in:
Frederik Jaeckel 2022-12-02 23:29:01 +01:00
parent 23d4790e3b
commit e972d54f54
5 changed files with 61 additions and 70 deletions

105
asset.py
View file

@ -13,6 +13,7 @@ from datetime import time
from sql.functions import CurrentDate, CurrentTimestamp, Round, Extract
from sql.conditionals import Case, Coalesce
from sql import Literal
from .diagram import Concat2
digits_percent = 2
@ -28,7 +29,7 @@ class Asset(ModelSQL, ModelView):
__name__ = 'investment.asset'
name = fields.Function(fields.Char(string='Name', readonly=True),
'on_change_with_name', searcher='search_rec_name')
'get_name_symbol', searcher='search_rec_name')
company = fields.Many2One(string='Company', model_name='company.company',
required=True, ondelete="RESTRICT")
product = fields.Many2One(string='Product', required=True,
@ -36,8 +37,7 @@ class Asset(ModelSQL, ModelView):
domain=[('type', '=', 'assets')])
product_uom = fields.Function(fields.Many2One(string='UOM Category',
readonly=True, model_name='product.uom.category',
help='Category of unit on the product.'),
'on_change_with_product_uom')
help='Category of unit on the product.'), 'get_name_symbol')
uom = fields.Many2One(string='UOM', required=True,
model_name='product.uom', ondelete='RESTRICT',
states={
@ -46,8 +46,8 @@ class Asset(ModelSQL, ModelView):
domain=[
('category', '=', Eval('product_uom')),
], depends=['product_uom', 'product'])
uom_symbol = fields.Function(fields.Char(string='UOM', readonly=True),
'on_change_with_uom_symbol', searcher='search_uom_symbol')
symbol = fields.Function(fields.Char(string='UOM', readonly=True),
'get_name_symbol', searcher='search_uom_symbol')
rates = fields.One2Many(string='Rates', field='asset',
model_name='investment.rate')
rate = fields.Function(fields.Numeric(string='Current Rate',
@ -58,14 +58,6 @@ class Asset(ModelSQL, ModelView):
help='Date of current rate'),
'get_rate_data', searcher='search_date')
company_currency = fields.Function(fields.Many2One(readonly=True,
string='Company Currency', states={'invisible': True},
model_name='currency.currency'),
'on_change_with_company_currency')
company_currency_digits = fields.Function(fields.Integer(
string='Currency Digits (Ref.)', readonly=True),
'on_change_with_currency_digits')
currency = fields.Many2One(string='Currency', select=True,
required=True, model_name='currency.currency', ondelete='RESTRICT')
currency_digits = fields.Integer(string='Digits', required=True)
@ -228,48 +220,64 @@ class Asset(ModelSQL, ModelView):
if self.currency:
self.currency_digits = self.currency.digits
@fields.depends('product')
def on_change_with_name(self, name=None):
""" get name of product
@classmethod
def get_name_symbol_sql(cls):
""" get sql for name, uom, digits, etc.
"""
if self.product:
return self.product.name
pool = Pool()
Product = pool.get('product.product')
ProdTempl = pool.get('product.template')
Uom = pool.get('product.uom')
Currency = pool.get('currency.currency')
tab_asset = cls.__table__()
tab_templ = ProdTempl.__table__()
tab_prod = Product.__table__()
tab_uom = Uom.__table__()
tab_uom2 = Uom.__table__()
tab_cur = Currency.__table__()
@fields.depends('product')
def on_change_with_product_uom(self, name=None):
""" get category of product-uom
"""
if self.product:
return self.product.default_uom.category.id
query = tab_asset.join(tab_prod,
condition=tab_asset.product==tab_prod.id,
).join(tab_templ,
condition=tab_templ.id==tab_prod.template,
).join(tab_uom,
condition=tab_templ.default_uom==tab_uom.id,
).join(tab_cur,
condition=tab_asset.currency==tab_cur.id,
).join(tab_uom2,
condition=tab_asset.uom==tab_uom2.id,
).select(
tab_asset.id,
tab_templ.name,
tab_uom.category.as_('product_uom'),
Concat2(tab_cur.symbol, '/', tab_uom2.symbol).as_('symbol'),
)
return (query, tab_asset)
@fields.depends('currency')
def on_change_with_currency_digits(self, name=None):
""" currency of cashbook
@classmethod
def get_name_symbol(cls, assets, names):
""" get date and rate of asset
"""
if self.currency:
return self.currency.digits
else:
return 2
cursor = Transaction().connection.cursor()
@fields.depends('company', 'currency')
def on_change_with_company_currency(self, name=None):
""" get company-currency if its different from current
asset-currency
"""
if self.company:
if self.currency:
if self.company.currency.id != self.currency.id:
return self.company.currency.id
(query, tab_asset) = cls.get_name_symbol_sql()
query.where=tab_asset.id.in_([x.id for x in assets])
@fields.depends('uom', 'currency')
def on_change_with_uom_symbol(self, name=None):
""" get symbl of uom
"""
return '%(currency)s/%(unit)s' % {
'currency': self.currency.symbol if self.currency is not None else '-',
'unit': self.uom.symbol if self.uom is not None else '-',
cursor.execute(*query)
records = cursor.fetchall()
result = {x:{y.id: None for y in assets} for x in names}
for record in records:
values = {
'name': record[1],
'product_uom': record[2],
'symbol': record[3],
}
for name in names:
result[name][record[0]] = values[name]
return result
@classmethod
def search_uom_symbol(cls, names, clause):
""" search in uom
@ -305,7 +313,6 @@ class Asset(ModelSQL, ModelView):
""" get date and rate of asset
"""
cursor = Transaction().connection.cursor()
(query, tab_asset) = cls.get_rate_data_sql()
query.where=tab_asset.id.in_([x.id for x in assets])
@ -798,7 +805,7 @@ class Asset(ModelSQL, ModelView):
"""
return '%(prod)s | %(rate)s %(unit)s | %(date)s' % {
'prod': getattr(self.product, 'rec_name', '-'),
'unit': self.uom_symbol,
'unit': self.symbol,
'rate': Report.format_number(self.rate, lang=None,
digits=self.currency_digits or 4) \
if self.rate is not None else '-',

View file

@ -122,14 +122,6 @@ msgctxt "field:investment.asset,company:"
msgid "Company"
msgstr "Unternehmen"
msgctxt "field:investment.asset,company_currency:"
msgid "Company Currency"
msgstr "Unternehmenswährung"
msgctxt "field:investment.asset,company_currency_digits:"
msgid "Currency Digits (Ref.)"
msgstr "Nachkommastellen Währung (Ref.)"
msgctxt "field:investment.asset,currency:"
msgid "Currency"
msgstr "Währung"
@ -154,7 +146,7 @@ msgctxt "field:investment.asset,uom:"
msgid "UOM"
msgstr "Einheit"
msgctxt "field:investment.asset,uom_symbol:"
msgctxt "field:investment.asset,symbol:"
msgid "UOM"
msgstr "Einheit"

View file

@ -90,14 +90,6 @@ msgctxt "field:investment.asset,company:"
msgid "Company"
msgstr "Company"
msgctxt "field:investment.asset,company_currency:"
msgid "Company Currency"
msgstr "Company Currency"
msgctxt "field:investment.asset,company_currency_digits:"
msgid "Currency Digits (Ref.)"
msgstr "Currency Digits (Ref.)"
msgctxt "field:investment.asset,currency:"
msgid "Currency"
msgstr "Currency"
@ -122,7 +114,7 @@ msgctxt "field:investment.asset,uom:"
msgid "UOM"
msgstr "UOM"
msgctxt "field:investment.asset,uom_symbol:"
msgctxt "field:investment.asset,symbol:"
msgid "UOM"
msgstr "UOM"

View file

@ -83,7 +83,7 @@ class AssetTestCase(ModuleTestCase):
asset = self.prep_asset_item(
company=company,
product = product)
self.assertEqual(asset.uom_symbol, 'usd/u')
self.assertEqual(asset.symbol, 'usd/u')
@with_transaction()
def test_asset_rec_name(self):

View file

@ -10,7 +10,7 @@ full copyright notices and license terms. -->
<field name="change_month6" />
<field name="date"/>
<field name="rate"/>
<field name="uom_symbol"/>
<field name="symbol"/>
<field name="isin"/>
<field name="wkn" />
</tree>