Guest User

Untitled

a guest
Jan 31st, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.77 KB | None | 0 0
  1. # This file is part of Tryton.  The COPYRIGHT file at the top level of
  2. # this repository contains the full copyright notices and license terms.
  3.  
  4. from trytond import backend
  5. from trytond.model import fields
  6. from trytond.pyson import Eval
  7. from trytond.pool import PoolMeta, Pool
  8.  
  9. __all__ = ['Configuration', 'ConfigurationSequence', 'Lot']
  10. __metaclass__ = PoolMeta
  11.  
  12.  
  13. class Configuration:
  14.     __metaclass__ = PoolMeta
  15.     __name__ = 'stock.configuration'
  16.     stock_lot_sequence = fields.MultiValue(fields.Many2One(
  17.             'ir.sequence', "Stock Lot Sequence", required=True,
  18.             domain=[
  19.                 ('company', 'in',
  20.                     [Eval('context', {}).get('company', -1), None]),
  21.                 ('code', '=', 'stock.lot'),
  22.                 ]))
  23.  
  24.     @classmethod
  25.     def multivalue_model(cls, field):
  26.         pool = Pool()
  27.         if field == 'stock_lot_sequence':
  28.             return pool.get('stock.configuration.sequence')
  29.         return super(Configuration, cls).multivalue_model(field)
  30.  
  31.     @classmethod
  32.     def default_stock_lot_sequence(cls, **pattern):
  33.         return cls.multivalue_model('stock_lot_sequence'
  34.             ).default_stock_lot_sequence()
  35.  
  36.  
  37. class ConfigurationSequence:
  38.     __metaclass__ = PoolMeta
  39.     __name__ = 'stock.configuration.sequence'
  40.     stock_lot_sequence = fields.Many2One(
  41.         'ir.sequence', "Stock Lot Sequence", required=True,
  42.         domain=[
  43.             ('company', 'in', [Eval('company', -1), None]),
  44.             ('code', '=', 'stock.lot'),
  45.             ],
  46.         depends=['company'])
  47.  
  48.     @classmethod
  49.     def default_stock_lot_sequence(cls):
  50.         pool = Pool()
  51.         ModelData = pool.get('ir.model.data')
  52.         try:
  53.             return ModelData.get_id(
  54.                 'my_custom_module', 'sequence_stock_lot')
  55.         except KeyError:
  56.             return None
  57.  
  58.  
  59. class Lot:
  60.     __name__ = "stock.lot"
  61.  
  62.     @classmethod
  63.     def __setup__(cls):
  64.         super(Lot, cls).__setup__()
  65.         cls.number.states['readonly'] = True
  66.  
  67.     @classmethod
  68.     def __register__(cls, module_name):
  69.         TableHandler = backend.get('TableHandler')
  70.         table = TableHandler(cls, module_name)
  71.  
  72.         super(Lot, cls).__register__(module_name)
  73.  
  74.         # Drop required on number
  75.         table.not_null_action('number', action='remove')
  76.  
  77.     @classmethod
  78.     def create(cls, vlist):
  79.         pool = Pool()
  80.         Sequence = pool.get('ir.sequence')
  81.         Config = pool.get('stock.configuration')
  82.  
  83.         config = Config(1)
  84.         vlist = [v.copy() for v in vlist]
  85.         for values in vlist:
  86.             if values.get('number') is None:
  87.                 values['number'] = Sequence.get_id(
  88.                     config.stock_lot_sequence.id)
  89.         return super(Lot, cls).create(vlist)
Advertisement
Add Comment
Please, Sign In to add comment