parent
6614725a41
commit
6b54b6bd89
26
sale.py
26
sale.py
|
@ -7,26 +7,24 @@ from trytond.model import fields
|
||||||
from trytond.pyson import Eval
|
from trytond.pyson import Eval
|
||||||
from trytond.pool import Pool, PoolMeta
|
from trytond.pool import Pool, PoolMeta
|
||||||
from trytond.modules.product import price_digits
|
from trytond.modules.product import price_digits
|
||||||
|
from trytond.modules.currency.fields import Monetary
|
||||||
|
|
||||||
__all__ = ['Sale', 'SaleLine']
|
__all__ = ['Sale', 'SaleLine']
|
||||||
|
|
||||||
_ZERO = Decimal(0)
|
_ZERO = Decimal(0)
|
||||||
|
|
||||||
|
|
||||||
class Sale(metaclass=PoolMeta):
|
class Sale(metaclass=PoolMeta):
|
||||||
__name__ = 'sale.sale'
|
__name__ = 'sale.sale'
|
||||||
margin = fields.Function(fields.Numeric('Margin',
|
margin = fields.Function(Monetary('Margin',
|
||||||
digits=(16, Eval('currency_digits', 2),),
|
currency='currency', digits='currency',
|
||||||
depends=['currency_digits'],
|
|
||||||
help=('It gives profitability by calculating the difference '
|
help=('It gives profitability by calculating the difference '
|
||||||
'between the Unit Price and Cost Price.')),
|
'between the Unit Price and Cost Price.')),
|
||||||
'get_margin')
|
'get_margin')
|
||||||
margin_cache = fields.Numeric('Margin Cache',
|
margin_cache = Monetary('Margin Cache',
|
||||||
digits=(16, Eval('currency_digits', 2)),
|
currency='currency', digits='currency', readonly=True)
|
||||||
readonly=True,
|
|
||||||
depends=['currency_digits'])
|
|
||||||
margin_percent = fields.Function(fields.Numeric('Margin (%)',
|
margin_percent = fields.Function(fields.Numeric('Margin (%)',
|
||||||
digits=(16, 4)),
|
digits=(16, 4)), 'get_margin_percent')
|
||||||
'get_margin_percent')
|
|
||||||
margin_percent_cache = fields.Numeric('Margin (%) Cache',
|
margin_percent_cache = fields.Numeric('Margin (%) Cache',
|
||||||
digits=(16, 4), readonly=True)
|
digits=(16, 4), readonly=True)
|
||||||
|
|
||||||
|
@ -88,19 +86,17 @@ class SaleLine(metaclass=PoolMeta):
|
||||||
'readonly': ~Eval('sale_state').in_(['draft', 'quotation']),
|
'readonly': ~Eval('sale_state').in_(['draft', 'quotation']),
|
||||||
},
|
},
|
||||||
depends=['type', 'sale_state'])
|
depends=['type', 'sale_state'])
|
||||||
margin = fields.Function(fields.Numeric('Margin',
|
margin = fields.Function(Monetary('Margin',
|
||||||
digits=(16, Eval('_parent_sale', {}).get('currency_digits', 2)),
|
currency='currency', digits='currency',
|
||||||
states={
|
states={
|
||||||
'invisible': ~Eval('type').in_(['line', 'subtotal']),
|
'invisible': ~Eval('type').in_(['line', 'subtotal']),
|
||||||
'readonly': ~Eval('_parent_sale'),
|
'readonly': ~Eval('_parent_sale'),
|
||||||
},
|
},
|
||||||
depends=['type', 'amount']),
|
depends=['type', 'amount']), 'on_change_with_margin')
|
||||||
'on_change_with_margin')
|
|
||||||
margin_percent = fields.Function(fields.Numeric('Margin (%)',
|
margin_percent = fields.Function(fields.Numeric('Margin (%)',
|
||||||
digits=(16, 4), states={
|
digits=(16, 4), states={
|
||||||
'invisible': ~Eval('type').in_(['line', 'subtotal']),
|
'invisible': ~Eval('type').in_(['line', 'subtotal']),
|
||||||
}, depends=['type']),
|
}, depends=['type']), 'on_change_with_margin_percent')
|
||||||
'on_change_with_margin_percent')
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
|
|
Loading…
Reference in New Issue