File: product.py

package info (click to toggle)
tryton-modules-stock-lot 5.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 464 kB
  • sloc: python: 665; xml: 278; makefile: 6; sh: 3
file content (41 lines) | stat: -rw-r--r-- 1,419 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
# 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.pyson import Eval
from trytond.pool import PoolMeta

__all__ = ['Template', 'Product', 'TemplateLotType']


class Template(metaclass=PoolMeta):
    __name__ = 'product.template'

    # TODO to replace with a Multiple Selection
    lot_required = fields.Many2Many('product.template-stock.lot.type',
        'template', 'type', 'Lot Required',
        help='The type of location for which lot is required',
        states={
            'invisible': ~Eval('type').in_(['goods', 'assets']),
            },
        depends=['type'])


class Product(metaclass=PoolMeta):
    __name__ = 'product.product'

    def lot_is_required(self, from_, to):
        'Is product lot required for move with "from_" and "to" location ?'
        lot_required = [t.code for t in self.lot_required]
        for location in (from_, to):
            if location.type in lot_required:
                return True


class TemplateLotType(ModelSQL):
    'Template - Stock Lot Type'
    __name__ = 'product.template-stock.lot.type'

    template = fields.Many2One('product.template', 'Template', required=True,
        select=True, ondelete='CASCADE')
    type = fields.Many2One('stock.lot.type', 'Type', required=True,
        ondelete='CASCADE')