stock_analysis.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. # © 2016 Lorenzo Battistini - Agile Business Group
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import tools
  5. from openerp import models, fields
  6. class StockAnalysis(models.Model):
  7. _name = 'stock.analysis'
  8. _auto = False
  9. _rec_name = 'product_id'
  10. product_id = fields.Many2one(
  11. 'product.product', string='Producto', readonly=True)
  12. location_id = fields.Many2one(
  13. 'stock.location', string='Ubicacion', readonly=True)
  14. qty = fields.Float(string='Cantidad', readonly=True)
  15. lot_id = fields.Many2one(
  16. 'stock.production.lot', string='Lote', readonly=True)
  17. package_id = fields.Many2one(
  18. 'stock.quant.package', string='Paquete', readonly=True)
  19. in_date = fields.Datetime('Fecha entrante', readonly=True)
  20. categ_id = fields.Many2one(
  21. 'product.category', string='Categoria', readonly=True)
  22. company_id = fields.Many2one(
  23. 'res.company', string='Compañia', readonly=True)
  24. def init(self, cr):
  25. tools.drop_view_if_exists(cr, self._table)
  26. cr.execute(
  27. """CREATE or REPLACE VIEW %s as (
  28. SELECT
  29. quant.id AS id,
  30. quant.product_id AS product_id,
  31. quant.location_id AS location_id,
  32. quant.qty AS qty,
  33. quant.lot_id AS lot_id,
  34. quant.package_id AS package_id,
  35. quant.in_date AS in_date,
  36. quant.company_id,
  37. template.categ_id AS categ_id
  38. FROM stock_quant AS quant
  39. JOIN product_product prod ON prod.id = quant.product_id
  40. JOIN product_template template
  41. ON template.id = prod.product_tmpl_id
  42. )"""
  43. % (self._table)
  44. )