product_product.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. # For copyright and license notices, see __openerp__.py file in root directory
  4. ##############################################################################
  5. from openerp import models, fields, api, _
  6. class ProductProduct(models.Model):
  7. _inherit = 'product.product'
  8. sup_inv_lines_count = fields.Float(
  9. string='Supplier Lines',
  10. compute='_supplier_lines_count')
  11. cus_inv_lines_count = fields.Float(
  12. string='Customer Lines',
  13. compute='_customer_lines_count')
  14. @api.multi
  15. def _supplier_lines_count(self):
  16. for prod in self:
  17. prod.sup_inv_lines_count = self.env[
  18. 'account.invoice.line'].search_count(
  19. prod._get_product_supplier_domain())
  20. @api.multi
  21. def _customer_lines_count(self):
  22. for prod in self:
  23. prod.cus_inv_lines_count = self.env[
  24. 'account.invoice.line'].search_count(
  25. prod._get_product_customer_domain())
  26. @api.multi
  27. def _get_product_supplier_domain(self):
  28. return [
  29. ('product_id', 'in', self.ids),
  30. ('invoice_id.type', 'in', ['in_invoice', 'in_refund']),
  31. ('invoice_id.state', '!=', 'cancel')]
  32. @api.multi
  33. def _get_product_customer_domain(self):
  34. return [
  35. ('product_id', 'in', self.ids),
  36. ('invoice_id.type', 'in', ['out_invoice', 'out_refund']),
  37. ('invoice_id.state', '!=', 'cancel')]
  38. @api.multi
  39. def action_view_supplier_invoice_lines(self):
  40. tree_view = self.env.ref(
  41. 'product_invoiced_line.product_account_invoice_line_tree')
  42. search_view = self.env.ref(
  43. 'product_invoiced_line.product_account_invoice_line_search')
  44. return {
  45. 'name': _('Supplier Lines invoiced'),
  46. 'domain': self._get_product_supplier_domain(),
  47. 'res_model': 'account.invoice.line',
  48. 'type': 'ir.actions.act_window',
  49. 'views': [(tree_view.id, 'tree')],
  50. 'view_mode': 'tree',
  51. 'search_view_id': search_view.id,
  52. 'view_type': 'form',
  53. 'context': {
  54. 'search_default_inv_open': 1,
  55. 'search_default_inv_paid': 1}}
  56. @api.multi
  57. def action_view_customer_invoice_lines(self):
  58. tree_view = self.env.ref(
  59. 'product_invoiced_line.product_account_invoice_line_tree')
  60. search_view = self.env.ref(
  61. 'product_invoiced_line.product_account_invoice_line_search')
  62. return {
  63. 'name': _('Customer Lines invoiced'),
  64. 'domain': self._get_product_customer_domain(),
  65. 'res_model': 'account.invoice.line',
  66. 'type': 'ir.actions.act_window',
  67. 'views': [(tree_view.id, 'tree')],
  68. 'view_mode': 'tree',
  69. 'search_view_id': search_view.id,
  70. 'view_type': 'form',
  71. 'context': {
  72. 'search_default_inv_open': 1,
  73. 'search_default_inv_paid': 1}}