report_gralsinvariantsale.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # You should have received a copy of the GNU Affero General Public License
  2. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  3. #
  4. ##############################################################################
  5. from datetime import datetime, timedelta
  6. import time
  7. from openerp.osv import fields, osv
  8. from openerp.tools.translate import _
  9. from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
  10. import openerp.addons.decimal_precision as dp
  11. from openerp import workflow
  12. # class product_product(osv.Model):
  13. # _inherit = 'product.product'
  14. # def _sales_count(self, cr, uid, ids, field_name, arg, context=None):
  15. # SaleOrderLine = self.pool['sale.order.line']
  16. # return {
  17. # product_id: SaleOrderLine.search_count(cr,uid, [('product_id', '=', product_id)], context=context)
  18. # for product_id in ids
  19. # }
  20. # _columns = {
  21. # 'sales_count': fields.function(_sales_count, string='# Sales', type='integer'),
  22. # }
  23. # class product_template(osv.Model):
  24. # _inherit = 'product.template'
  25. # def _sales_count(self, cr, uid, ids, field_name, arg, context=None):
  26. # res = dict.fromkeys(ids, 0)
  27. # for template in self.browse(cr, uid, ids, context=context):
  28. # res[template.id] = sum([p.sales_count for p in template.product_variant_ids])
  29. # return res
  30. # def action_view_sales(self, cr, uid, ids, context=None):
  31. # act_obj = self.pool.get('ir.actions.act_window')
  32. # mod_obj = self.pool.get('ir.model.data')
  33. # product_ids = []
  34. # for template in self.browse(cr, uid, ids, context=context):
  35. # product_ids += [x.id for x in template.product_variant_ids]
  36. # result = mod_obj.xmlid_to_res_id(cr, uid, 'sale.action_order_line_product_tree',raise_if_not_found=True)
  37. # result = act_obj.read(cr, uid, [result], context=context)[0]
  38. # result['domain'] = "[('product_id','in',[" + ','.join(map(str, product_ids)) + "])]"
  39. # return result
  40. # _columns = {
  41. # 'sales_count': fields.function(_sales_count, string='# Sales', type='integer'),
  42. # }
  43. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: