Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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 import backend
- from trytond.model import fields
- from trytond.pyson import Eval
- from trytond.pool import PoolMeta, Pool
- __all__ = ['Configuration', 'ConfigurationSequence', 'Lot']
- __metaclass__ = PoolMeta
- class Configuration:
- __metaclass__ = PoolMeta
- __name__ = 'stock.configuration'
- stock_lot_sequence = fields.MultiValue(fields.Many2One(
- 'ir.sequence', "Stock Lot Sequence", required=True,
- domain=[
- ('company', 'in',
- [Eval('context', {}).get('company', -1), None]),
- ('code', '=', 'stock.lot'),
- ]))
- @classmethod
- def multivalue_model(cls, field):
- pool = Pool()
- if field == 'stock_lot_sequence':
- return pool.get('stock.configuration.sequence')
- return super(Configuration, cls).multivalue_model(field)
- @classmethod
- def default_stock_lot_sequence(cls, **pattern):
- return cls.multivalue_model('stock_lot_sequence'
- ).default_stock_lot_sequence()
- class ConfigurationSequence:
- __metaclass__ = PoolMeta
- __name__ = 'stock.configuration.sequence'
- stock_lot_sequence = fields.Many2One(
- 'ir.sequence', "Stock Lot Sequence", required=True,
- domain=[
- ('company', 'in', [Eval('company', -1), None]),
- ('code', '=', 'stock.lot'),
- ],
- depends=['company'])
- @classmethod
- def default_stock_lot_sequence(cls):
- pool = Pool()
- ModelData = pool.get('ir.model.data')
- try:
- return ModelData.get_id(
- 'my_custom_module', 'sequence_stock_lot')
- except KeyError:
- return None
- class Lot:
- __name__ = "stock.lot"
- @classmethod
- def __setup__(cls):
- super(Lot, cls).__setup__()
- cls.number.states['readonly'] = True
- @classmethod
- def __register__(cls, module_name):
- TableHandler = backend.get('TableHandler')
- table = TableHandler(cls, module_name)
- super(Lot, cls).__register__(module_name)
- # Drop required on number
- table.not_null_action('number', action='remove')
- @classmethod
- def create(cls, vlist):
- pool = Pool()
- Sequence = pool.get('ir.sequence')
- Config = pool.get('stock.configuration')
- config = Config(1)
- vlist = [v.copy() for v in vlist]
- for values in vlist:
- if values.get('number') is None:
- values['number'] = Sequence.get_id(
- config.stock_lot_sequence.id)
- return super(Lot, cls).create(vlist)
Advertisement
Add Comment
Please, Sign In to add comment