File: account.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 (48 lines) | stat: -rw-r--r-- 1,625 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
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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 ModelSQL, fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval


__all__ = ['InvoiceLineStockMove', 'InvoiceLine']


class InvoiceLineStockMove(ModelSQL):
    'Invoice Line - Stock Move'
    __name__ = 'account.invoice.line-stock.move'

    invoice_line = fields.Many2One('account.invoice.line', 'Invoice Line',
        required=True, select=True, ondelete='CASCADE')
    stock_move = fields.Many2One('stock.move', 'Stock Move', required=True,
        select=True, ondelete='CASCADE')


class InvoiceLine(metaclass=PoolMeta):
    __name__ = 'account.invoice.line'
    stock_moves = fields.Many2Many('account.invoice.line-stock.move',
        'invoice_line', 'stock_move', 'Stock Moves',
        states={
            'invisible': Eval('type') != 'line',
            },
        depends=['type'])

    @property
    def moved_quantity(self):
        'The quantity from linked stock moves in line unit'
        pool = Pool()
        Uom = pool.get('product.uom')
        quantity = 0
        for stock_move in self.stock_moves:
            quantity += Uom.compute_qty(stock_move.uom, stock_move.quantity,
                self.unit)
        return quantity

    @classmethod
    def copy(cls, lines, default=None):
        if default is None:
            default = {}
        else:
            default = default.copy()
        default.setdefault('stock_moves', None)
        return super(InvoiceLine, cls).copy(lines, default=default)