83 lines
3.2 KiB
Python
83 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# This file is part of the cashbook-module from m-ds.de for Tryton.
|
|
# The COPYRIGHT file at the top level of this repository contains the
|
|
# full copyright notices and license terms.
|
|
|
|
from trytond.model import fields
|
|
from trytond.pyson import Eval, Bool, Or
|
|
from trytond.pool import Pool
|
|
from trytond.transaction import Transaction
|
|
from trytond.modules.product.uom import uom_conversion_digits
|
|
from trytond.modules.cashbook.mixin import STATES, DEPENDS
|
|
from decimal import Decimal
|
|
|
|
STATESQ = {}
|
|
STATESQ.update(STATES)
|
|
DEPENDSQ = []
|
|
DEPENDSQ.extend(DEPENDS)
|
|
|
|
|
|
class SecondUomMixin(object):
|
|
""" two fields for second uom: quantity, rate
|
|
"""
|
|
quantity_2nd_uom = fields.Numeric(string='Quantity Second UOM',
|
|
digits=(16, Eval('quantity2nd_digits', 4)),
|
|
states={
|
|
'readonly': Or(
|
|
STATESQ['readonly'],
|
|
~Bool(Eval('quantity2nd'))
|
|
),
|
|
'required': Bool(Eval('quantity2nd')),
|
|
'invisible': ~Bool(Eval('quantity2nd')),
|
|
}, depends=DEPENDSQ+['quantity2nd_digits', 'quantity2nd'])
|
|
factor_2nd_uom = fields.Function(fields.Numeric(string='Conversion factor',
|
|
help='Conversion factor between the units of the participating cash books.',
|
|
digits=(16, uom_conversion_digits),
|
|
states={
|
|
'readonly': Or(
|
|
STATESQ['readonly'],
|
|
~Bool(Eval('quantity2nd'))
|
|
),
|
|
'required': Bool(Eval('quantity2nd')),
|
|
'invisible': ~Bool(Eval('quantity2nd')),
|
|
}, depends=DEPENDSQ+['quantity2nd_digits', 'quantity2nd']),
|
|
'on_change_with_rate_2nd_uom', setter='set_rate_2nd_uom')
|
|
|
|
quantity2nd = fields.Function(fields.Many2One(model_name='product.uom',
|
|
string="2nd UOM", readonly=True), 'on_change_with_quantity2nd')
|
|
quantity2nd_digits = fields.Function(fields.Integer(string='2nd UOM Digits',
|
|
readonly=True), 'on_change_with_quantity2nd_digits')
|
|
|
|
@fields.depends('quantity', 'quantity_2nd_oum')
|
|
def on_change_with_factor_2nd_uom(self, name=None):
|
|
""" get factor from uom
|
|
"""
|
|
Rate = Pool().get('currency.currency.rate')
|
|
|
|
if (self.quantity is not None) and \
|
|
(self.quantity_2nd_oum is not None):
|
|
if self.quantity != Decimal('0.0'):
|
|
exp = Decimal(Decimal(1) / 10 ** Rate.rate.digits[1])
|
|
return (self.quantity_2nd_oum / self.quantity).quantize(exp)
|
|
|
|
@fields.depends('booktransf', '_parent_booktransf.quantity_uom', 'quantity_uom')
|
|
def on_change_with_quantity2nd(self, name=None):
|
|
""" uom of transfer-target
|
|
"""
|
|
if self.booktransf:
|
|
if self.quantity_uom:
|
|
if self.booktransf.quantity_uom:
|
|
if self.quantity_uom.id != \
|
|
self.booktransf.quantity_uom.id:
|
|
return self.booktransf.quantity_uom.id
|
|
|
|
@fields.depends('booktransf', '_parent_booktransf.quantity_digits')
|
|
def on_change_with_quantity2nd_digits(self, name=None):
|
|
""" uom of transfer-target
|
|
"""
|
|
if self.booktransf:
|
|
return self.booktransf.quantity_digits
|
|
else:
|
|
return 2
|
|
|
|
# end SecondUomMixin
|