product_product_label_print.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. #
  6. # Copyright (c) 2015 ICTSTUDIO (www.ictstudio.eu).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp import models, fields, api
  23. class ProductProductLabel(models.TransientModel):
  24. _name = "product.product.label"
  25. label_lines = fields.One2many(
  26. comodel_name='product.product.label.line',
  27. inverse_name='label_id',
  28. string='Labels'
  29. )
  30. @api.model
  31. def default_get(self, fields):
  32. res = super(ProductProductLabel, self).default_get(fields)
  33. label_lines = self.lines_get()
  34. res['label_lines'] = label_lines
  35. return res
  36. @api.multi
  37. def lines_get(self):
  38. context = self._context or {}
  39. products = self.env['product.product'].browse(context.get('active_ids', []))
  40. label_list = []
  41. for product in products:
  42. label_list.append([0,0,{
  43. 'product_id': product.id,
  44. 'quantity': 1
  45. }])
  46. return label_list
  47. @api.multi
  48. def print_labels(self):
  49. records = self
  50. return self.env['report'].get_action(records,
  51. 'product_labels.product_product_label'
  52. )
  53. class ProductProductLabelLine(models.TransientModel):
  54. _name = "product.product.label.line"
  55. label_id = fields.Many2one(
  56. comodel_name="product.product.label",
  57. string="Product Label"
  58. )
  59. product_id = fields.Many2one(
  60. comodel_name="product.product",
  61. string="Product"
  62. )
  63. quantity = fields.Integer(string="Label Qty", default=1)
  64. @api.one
  65. def get_label_data(self):
  66. return {
  67. 'label_id': self.label_id.id,
  68. 'name': self.product_id.name,
  69. 'code': self.product_id.default_code or False,
  70. 'barcode': self.product_id.ean13 or False,
  71. 'price': self.product_id.lst_price or 0.0, # Agregando el precio del producto
  72. }