File: stock.py

package info (click to toggle)
tryton-modules-account-invoice-stock 5.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 316 kB
  • sloc: python: 196; xml: 34; makefile: 6; sh: 3
file content (35 lines) | stat: -rw-r--r-- 1,197 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This file is part of 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.pool import Pool, PoolMeta
from trytond.transaction import Transaction


__all__ = ['StockMove']


class StockMove(metaclass=PoolMeta):
    __name__ = 'stock.move'
    invoice_lines = fields.Many2Many('account.invoice.line-stock.move',
        'stock_move', 'invoice_line', 'Invoice Lines')

    @property
    def invoiced_quantity(self):
        'The quantity from linked invoice lines in move unit'
        pool = Pool()
        Uom = pool.get('product.uom')
        quantity = 0
        for invoice_line in self.invoice_lines:
            quantity += Uom.compute_qty(invoice_line.unit,
                invoice_line.quantity, self.uom)
        return quantity

    @classmethod
    def copy(cls, moves, default=None):
        if default is None:
            default = {}
        else:
            default = default.copy()
        if not Transaction().context.get('_stock_move_split'):
            default.setdefault('invoice_lines', None)
        return super(StockMove, cls).copy(moves, default=default)