Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Lot(metaclass=PoolMeta):
- __name__ = "stock.lot"
- id_supplier_packing = fields.Char('Id Supplier Packing')
- id_preciball_po = fields.Char('Id Preciball PO')
- id_supplier_pallet = fields.Char('Id Supplier Pallet')
- packaging = fields.Selection([
- ('box', 'Box'),
- ('crate', 'Crate'),
- ('bottle', 'Bottle'),
- ('bag', 'Bag'),
- ('drum', 'Drum'),
- ('other', 'Other'),
- ], 'Packaging',
- states={'required': Bool(Eval('packaging_description')), },
- depends=['packaging_description'],
- help="The packaging used for this lot.")
- packaging_description = fields.Char('Packaging Description',
- help="Short description about quantity and unit in packaging.")
- barcode = fields.Function(fields.Binary('Barcode',
- states={
- 'invisible': ~Eval('barcode'),
- }), 'get_barcode')
- @classmethod
- def __setup__(cls):
- super(Lot, cls).__setup__()
- cls.number.readonly = True
- @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 not values.get('number'):
- values['number'] = Sequence.get_id(
- config.stock_lot_sequence.id)
- return super(Lot, cls).create(vlist)
- @classmethod
- def validate(cls, lots):
- super().validate(lots)
- for lot in lots:
- lot.check_description_length()
- def check_description_length(self):
- Warning = Pool().get('res.user.warning')
- if (self.packaging_description
- and len(self.packaging_description) > 20):
- # Old key
- # key = '%s@%s' % (self.__name__, self.id)
- # New Key without ID
- key = '%s@%s-%s' % (self.__name__, self.number,
- self.product.rec_name)
- # DEBUG
- print('##########################################')
- print(key)
- print(str(self.number))
- print(self.product.rec_name)
- print('###########################################')
- # END DEBUG
- if Warning.check(key):
- raise LotPackagingWarning(key, gettext(
- 'preciball.msg_lot_packaging_description_length'))
- @classmethod
- def copy(cls, lots, default=None):
- if default is None:
- default = {}
- default = default.copy()
- default.setdefault('number')
- return super().copy(lots, default=default)
- def get_rec_name(self, name):
- name = super().get_rec_name(name)
- context = Transaction().context
- if context.get('lot_package') and self.packaging:
- packaging = self.packaging
- if self.packaging_description:
- packaging = '%s - %s' % (packaging,
- self.packaging_description[0:20])
- name = '%s (%s)' % (name, packaging)
- return name
- def get_barcode(self, name):
- fd = BytesIO()
- barcode.generate(
- 'code128', str(self.number),
- writer=ImageWriter(), output=fd)
- fd.seek(0)
- return fields.Binary.cast(fd.read())
Add Comment
Please, Sign In to add comment