trytond-stock_valued /

#This file is part stock_valued module for Tryton.
#The COPYRIGHT file at the top level of this repository contains 
#the full copyright notices and license terms.

from trytond.model import ModelView, ModelSQL, fields
from trytond.pyson import Not, Equal, Eval, Bool
from trytond.transaction import Transaction
from trytond.pool import Pool
from decimal import Decimal

_ZERO = Decimal('0.0')

class Move(ModelSQL, ModelView):
    _name = 'stock.move'

    amount = fields.Function(fields.Numeric('Amount',
            digits=(16, 4),
                'invisible': Not(Bool(Eval('unit_price_required'))),
                'required': Bool(Eval('unit_price_required')),
                'readonly': Not(Equal(Eval('state'), 'draft')),
                }, on_change_with=['quantity', 'unit_price'],

    def on_change_with_amount(self, vals):
        currency_obj = Pool().get('currency.currency')
        if vals.get('quantity') and vals.get('unit_price'):
            currency = (vals.get('_parent_invoice.currency')
                or vals.get('currency'))
            if isinstance(currency, (int, long)) and currency:
                currency = currency_obj.browse(currency)
            amount = Decimal(str(vals.get('quantity') or '0.0')) * \
                    (vals.get('unit_price') or Decimal('0.0'))
            if currency:
                return currency_obj.round(currency, amount)
            return amount
        return Decimal('0.0')

    def get_amount(self, ids, name):
        currency_obj = Pool().get('currency.currency')
        res = {}
        for move in self.browse(ids):
            res[] = _ZERO
            if move.quantity:
                res[] += currency_obj.round(
                            Decimal(str(move.quantity)) * move.unit_price)
        return res

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.