asset: produkt, einheit + test
This commit is contained in:
parent
0d8ef5081e
commit
13007f30c8
9 changed files with 253 additions and 1 deletions
57
asset.py
57
asset.py
|
@ -8,6 +8,7 @@ from trytond.exceptions import UserError
|
|||
from trytond.i18n import gettext
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, Bool
|
||||
|
||||
|
||||
class Asset(ModelSQL, ModelView):
|
||||
|
@ -16,6 +17,21 @@ class Asset(ModelSQL, ModelView):
|
|||
|
||||
company = fields.Many2One(string='Company', model_name='company.company',
|
||||
required=True, ondelete="RESTRICT")
|
||||
product = fields.Many2One(string='Product', required=True,
|
||||
model_name='product.product', ondelete='RESTRICT',
|
||||
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')
|
||||
uom = fields.Many2One(string='UOM', required=True,
|
||||
model_name='product.uom', ondelete='RESTRICT',
|
||||
states={
|
||||
'readonly': ~Bool(Eval('product')),
|
||||
},
|
||||
domain=[
|
||||
('category', '=', Eval('product_uom')),
|
||||
], depends=['product_uom', 'product'])
|
||||
|
||||
company_currency = fields.Function(fields.Many2One(readonly=True,
|
||||
string='Company Currency', states={'invisible': True},
|
||||
|
@ -46,6 +62,35 @@ class Asset(ModelSQL, ModelView):
|
|||
def default_company():
|
||||
return Transaction().context.get('company') or None
|
||||
|
||||
@classmethod
|
||||
def default_currency_digits(cls):
|
||||
""" default: 2
|
||||
"""
|
||||
return 2
|
||||
|
||||
@fields.depends('product', 'uom')
|
||||
def on_change_product(self):
|
||||
""" update unit by product
|
||||
"""
|
||||
if self.product:
|
||||
self.uom = self.product.default_uom
|
||||
return
|
||||
self.uom = None
|
||||
|
||||
@fields.depends('currency', 'currency_digits')
|
||||
def on_change_currency(self):
|
||||
""" update currency_digits by value on currency
|
||||
"""
|
||||
if self.currency:
|
||||
self.currency_digits = self.currency.digits
|
||||
|
||||
@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
|
||||
|
||||
@fields.depends('currency')
|
||||
def on_change_with_currency_digits(self, name=None):
|
||||
""" currency of cashbook
|
||||
|
@ -65,4 +110,16 @@ class Asset(ModelSQL, ModelView):
|
|||
if self.company.currency.id != self.currency.id:
|
||||
return self.company.currency.id
|
||||
|
||||
def get_rec_name(self, name):
|
||||
if self.product:
|
||||
return self.product.rec_name
|
||||
else:
|
||||
return self.id
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
""" search in rec_name
|
||||
"""
|
||||
return [('product.rec_name',) + tuple(clause[1:])]
|
||||
|
||||
# end Asset
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue