product_margin.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import time
  4. from odoo import api, fields, models, _
  5. class ProductMargin(models.TransientModel):
  6. _name = 'product.margin'
  7. _description = 'Product Margin'
  8. from_date = fields.Date('From', default=time.strftime('%Y-01-01'))
  9. to_date = fields.Date('To', default=time.strftime('%Y-12-31'))
  10. invoice_state = fields.Selection([
  11. ('paid', 'Paid'),
  12. ('open_paid', 'Open and Paid'),
  13. ('draft_open_paid', 'Draft, Open and Paid'),
  14. ], 'Invoice State', required=True, default="open_paid")
  15. def action_open_window(self):
  16. self.ensure_one()
  17. context = dict(self.env.context, create=False, edit=False)
  18. def ref(xml_id):
  19. proxy = self.env['ir.model.data']
  20. return proxy._xmlid_lookup(xml_id)[2]
  21. search_view_id = ref('product.product_search_form_view')
  22. graph_view_id = ref('product_margin.view_product_margin_graph')
  23. form_view_id = ref('product_margin.view_product_margin_form')
  24. tree_view_id = ref('product_margin.view_product_margin_tree')
  25. context.update(invoice_state=self.invoice_state)
  26. if self.from_date:
  27. context.update(date_from=self.from_date)
  28. if self.to_date:
  29. context.update(date_to=self.to_date)
  30. views = [
  31. (tree_view_id, 'tree'),
  32. (form_view_id, 'form'),
  33. (graph_view_id, 'graph')
  34. ]
  35. return {
  36. 'name': _('Product Margins'),
  37. 'context': context,
  38. "view_mode": 'tree,form,graph',
  39. 'res_model': 'product.product',
  40. 'type': 'ir.actions.act_window',
  41. 'views': views,
  42. 'view_id': False,
  43. 'search_view_id': [search_view_id],
  44. }