product_detail.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. #################################################################################
  3. #
  4. # Odoo, Open Source Management Solution
  5. # Copyright (C) 2018-Today Ascetic Business Solution <www.asceticbs.com>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. #################################################################################
  21. from openerp import api, fields, models, _
  22. class ProductDetail(models.TransientModel):
  23. _name = "product.detail"
  24. start_date = fields.Date(string="Desde la fecha", required='1')
  25. end_date = fields.Date(string="Hasta la fecha", required='1')
  26. top_products = fields.Selection([
  27. ('by_units', 'Units'),
  28. ('by_amounts', 'Sales')
  29. ], string='Segun', default = 'by_units')
  30. no_of_products = fields.Integer(string='Numero de productos a mostrar', default = '20')
  31. @api.multi
  32. def check_report(self):
  33. data = {}
  34. data['form'] = self.read(['start_date', 'end_date', 'top_products', 'no_of_products'])[0]
  35. return self._print_report(data)
  36. def _print_report(self, data):
  37. data['form'].update(self.read(['start_date', 'end_date', 'top_products', 'no_of_products'])[0])
  38. if data['form']['top_products'] == 'by_units':
  39. return self.env['report'].get_action(self, 'abs_top_sold_products.report_products', data=data)
  40. else:
  41. return self.env['report'].get_action(self, 'abs_top_sold_products.report_products_amount', data=data)