Guest User

Untitled

a guest
Dec 18th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.33 KB | None | 0 0
  1. class Lot(metaclass=PoolMeta):
  2.     __name__ = "stock.lot"
  3.     id_supplier_packing = fields.Char('Id Supplier Packing')
  4.     id_preciball_po = fields.Char('Id Preciball PO')
  5.     id_supplier_pallet = fields.Char('Id Supplier Pallet')
  6.     packaging = fields.Selection([
  7.         ('box', 'Box'),
  8.         ('crate', 'Crate'),
  9.         ('bottle', 'Bottle'),
  10.         ('bag', 'Bag'),
  11.         ('drum', 'Drum'),
  12.         ('other', 'Other'),
  13.         ], 'Packaging',
  14.         states={'required': Bool(Eval('packaging_description')), },
  15.         depends=['packaging_description'],
  16.         help="The packaging used for this lot.")
  17.     packaging_description = fields.Char('Packaging Description',
  18.         help="Short description about quantity and unit in packaging.")
  19.     barcode = fields.Function(fields.Binary('Barcode',
  20.         states={
  21.             'invisible': ~Eval('barcode'),
  22.             }), 'get_barcode')
  23.  
  24.     @classmethod
  25.     def __setup__(cls):
  26.         super(Lot, cls).__setup__()
  27.         cls.number.readonly = True
  28.  
  29.     @classmethod
  30.     def create(cls, vlist):
  31.         pool = Pool()
  32.         Sequence = pool.get('ir.sequence')
  33.         Config = pool.get('stock.configuration')
  34.  
  35.         config = Config(1)
  36.         vlist = [v.copy() for v in vlist]
  37.         for values in vlist:
  38.             if not values.get('number'):
  39.                 values['number'] = Sequence.get_id(
  40.                     config.stock_lot_sequence.id)
  41.         return super(Lot, cls).create(vlist)
  42.  
  43.     @classmethod
  44.     def validate(cls, lots):
  45.         super().validate(lots)
  46.         for lot in lots:
  47.             lot.check_description_length()
  48.  
  49.     def check_description_length(self):
  50.         Warning = Pool().get('res.user.warning')
  51.         if (self.packaging_description
  52.         and len(self.packaging_description) > 20):
  53.             # Old key
  54.             # key = '%s@%s' % (self.__name__, self.id)
  55.             # New Key without ID
  56.             key = '%s@%s-%s' % (self.__name__, self.number,
  57.                 self.product.rec_name)
  58.             # DEBUG
  59.             print('##########################################')
  60.             print(key)
  61.             print(str(self.number))
  62.             print(self.product.rec_name)
  63.             print('###########################################')
  64.             # END DEBUG
  65.             if Warning.check(key):
  66.                 raise LotPackagingWarning(key, gettext(
  67.                     'preciball.msg_lot_packaging_description_length'))
  68.  
  69.     @classmethod
  70.     def copy(cls, lots, default=None):
  71.         if default is None:
  72.             default = {}
  73.         default = default.copy()
  74.         default.setdefault('number')
  75.         return super().copy(lots, default=default)
  76.  
  77.     def get_rec_name(self, name):
  78.         name = super().get_rec_name(name)
  79.         context = Transaction().context
  80.         if context.get('lot_package') and self.packaging:
  81.             packaging = self.packaging
  82.             if self.packaging_description:
  83.                 packaging = '%s - %s' % (packaging,
  84.                     self.packaging_description[0:20])
  85.             name = '%s (%s)' % (name, packaging)
  86.         return name
  87.  
  88.     def get_barcode(self, name):
  89.         fd = BytesIO()
  90.         barcode.generate(
  91.             'code128', str(self.number),
  92.             writer=ImageWriter(), output=fd)
  93.         fd.seek(0)
  94.         return fields.Binary.cast(fd.read())
  95.  
  96.  
Add Comment
Please, Sign In to add comment