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

View file

@ -122,14 +122,6 @@ msgctxt "field:investment.asset,company:"
msgid "Company" msgid "Company"
msgstr "Unternehmen" 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:" msgctxt "field:investment.asset,currency:"
msgid "Currency" msgid "Currency"
msgstr "Währung" msgstr "Währung"
@ -154,7 +146,7 @@ msgctxt "field:investment.asset,uom:"
msgid "UOM" msgid "UOM"
msgstr "Einheit" msgstr "Einheit"
msgctxt "field:investment.asset,uom_symbol:" msgctxt "field:investment.asset,symbol:"
msgid "UOM" msgid "UOM"
msgstr "Einheit" msgstr "Einheit"

View file

@ -90,14 +90,6 @@ msgctxt "field:investment.asset,company:"
msgid "Company" msgid "Company"
msgstr "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:" msgctxt "field:investment.asset,currency:"
msgid "Currency" msgid "Currency"
msgstr "Currency" msgstr "Currency"
@ -122,7 +114,7 @@ msgctxt "field:investment.asset,uom:"
msgid "UOM" msgid "UOM"
msgstr "UOM" msgstr "UOM"
msgctxt "field:investment.asset,uom_symbol:" msgctxt "field:investment.asset,symbol:"
msgid "UOM" msgid "UOM"
msgstr "UOM" msgstr "UOM"

View file

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

View file

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