product_template.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 ProductTemplate(models.Model):
  7. _inherit = 'product.template'
  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 template in self:
  17. template.sup_inv_lines_count = sum(
  18. [p.sup_inv_lines_count for p in template.product_variant_ids])
  19. @api.multi
  20. def _customer_lines_count(self):
  21. for template in self:
  22. template.cus_inv_lines_count = sum(
  23. [p.cus_inv_lines_count for p in template.product_variant_ids])
  24. @api.multi
  25. def _get_product_template_supplier_domain(self):
  26. return [
  27. ('product_id', 'in', self._get_products()),
  28. ('invoice_id.type', 'in', ['in_invoice', 'in_refund']),
  29. ('invoice_id.state', '!=', 'cancel')]
  30. @api.multi
  31. def _get_product_template_customer_domain(self):
  32. return [
  33. ('product_id', 'in', self._get_products()),
  34. ('invoice_id.type', 'in', ['out_invoice', 'out_refund']),
  35. ('invoice_id.state', '!=', 'cancel')]
  36. @api.multi
  37. def action_view_pt_supplier_invoice_lines(self):
  38. tree_view = self.env.ref(
  39. 'product_invoiced_line.product_account_invoice_line_tree')
  40. search_view = self.env.ref(
  41. 'product_invoiced_line.product_account_invoice_line_search')
  42. return {
  43. 'name': _('Supplier Lines invoiced'),
  44. 'domain': self._get_product_template_supplier_domain(),
  45. 'res_model': 'account.invoice.line',
  46. 'type': 'ir.actions.act_window',
  47. 'views': [(tree_view.id, 'tree')],
  48. 'view_mode': 'tree',
  49. 'search_view_id': search_view.id,
  50. 'view_type': 'form',
  51. 'context': {
  52. 'search_default_inv_open': 1,
  53. 'search_default_inv_paid': 1}}
  54. @api.multi
  55. def action_view_pt_customer_invoice_lines(self):
  56. tree_view = self.env.ref(
  57. 'product_invoiced_line.product_account_invoice_line_tree')
  58. search_view = self.env.ref(
  59. 'product_invoiced_line.product_account_invoice_line_search')
  60. return {
  61. 'name': _('Customer Lines invoiced'),
  62. 'domain': self._get_product_template_customer_domain(),
  63. 'res_model': 'account.invoice.line',
  64. 'type': 'ir.actions.act_window',
  65. 'views': [(tree_view.id, 'tree')],
  66. 'view_mode': 'tree',
  67. 'search_view_id': search_view.id,
  68. 'view_type': 'form',
  69. 'context': {
  70. 'search_default_inv_open': 1,
  71. 'search_default_inv_paid': 1}}