stock.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. # © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp import models, fields, api
  5. class StockProductionLot(models.Model):
  6. _inherit = 'stock.production.lot'
  7. _rec_name = 'display_name'
  8. expiry_date = fields.Date(string='Fecha de vencimiento')
  9. display_name = fields.Char(
  10. compute='compute_display_name_field',
  11. string='Número de Lote/Serie', store=True, readonly=True)
  12. @api.multi
  13. @api.depends('name', 'expiry_date')
  14. def compute_display_name_field(self):
  15. for lot in self:
  16. dname = lot.name
  17. if lot.expiry_date:
  18. dname = '[%s] %s' % (lot.expiry_date, dname)
  19. lot.display_name = dname
  20. class StockQuant(models.Model):
  21. _inherit = 'stock.quant'
  22. expiry_date = fields.Date(
  23. related='lot_id.expiry_date', store=True, readonly=True, string="Fecha de vencimiento")
  24. # method copy/pasted from the official product_expiry module
  25. # © Odoo SA
  26. @api.model
  27. def apply_removal_strategy(
  28. self, location, product, qty, domain, removal_strategy):
  29. if removal_strategy == 'fefo':
  30. order = 'expiry_date, location_id, package_id, lot_id, in_date, id'
  31. return self._quants_get_order(
  32. location, product, qty, domain, order)
  33. return super(StockQuant, self).apply_removal_strategy(
  34. location, product, qty, domain, removal_strategy)