stock_warehouse_transfer_line.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Copyright (C) 2015 ICTSTUDIO (<http://www.ictstudio.eu>).
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from openerp import models, fields, api, _
  21. import logging
  22. _logger = logging.getLogger(__name__)
  23. class StockWarehouseTransferLine(models.Model):
  24. _name = 'stock.warehouse.transfer.line'
  25. _rec_name = 'product_id'
  26. @api.model
  27. def _get_default_product_qty(self):
  28. return 1.0
  29. product_id = fields.Many2one(
  30. comodel_name='product.product',
  31. string='Producto')
  32. ean13 = fields.Char('Ean13', related="product_id.ean13", store=True)
  33. default_code = fields.Char('Referencia interna', related="product_id.default_code", store=True)
  34. factory_reference = fields.Char(
  35. comodel_name='product.product',
  36. string='Referencia')
  37. product_qty = fields.Float(
  38. string='Cantidad',
  39. default=_get_default_product_qty)
  40. product_uom_id = fields.Many2one(
  41. comodel_name='product.uom',
  42. string='Unidad de Medida')
  43. transfer = fields.Many2one(
  44. comodel_name='stock.warehouse.transfer',
  45. string='Transferencia')
  46. note = fields.Text(string='Note')
  47. source_location = fields.Many2one(
  48. comodel_name='stock.location',
  49. string='Déposito de origen',
  50. compute='_get_transfer_locations',
  51. store=True)
  52. dest_location = fields.Many2one(
  53. comodel_name='stock.location',
  54. string='Déposito de destino',
  55. compute='_get_transfer_locations',
  56. store=True)
  57. @api.one
  58. @api.onchange('product_id')
  59. def product_id_change(self):
  60. vals = {}
  61. self.product_uom_id = self.product_id.uom_id and self.product_id.uom_id.id or False
  62. self.default_code = self.product_id.default_code
  63. self.ean13 = self.product_id.ean13
  64. @api.multi
  65. @api.depends('transfer.source_warehouse', 'transfer.dest_warehouse')
  66. def _get_transfer_locations(self):
  67. for rec in self:
  68. rec.source_location = rec.transfer.source_warehouse.lot_stock_id.id
  69. dest_location = False
  70. transit_locations = self.env['stock.location'].search(
  71. [
  72. ('usage', '=', 'transit')
  73. ]
  74. )
  75. for location in transit_locations:
  76. if location.get_warehouse(location) == rec.transfer.dest_warehouse.id:
  77. dest_location = location.id
  78. if not dest_location:
  79. rec.dest_location = rec.transfer.dest_warehouse.lot_stock_id.id
  80. else:
  81. rec.dest_location = dest_location
  82. @api.multi
  83. def get_move_vals(self, picking, group):
  84. """
  85. Get the correct move values
  86. :param picking:
  87. :param group:
  88. :return: dict
  89. """
  90. self.ensure_one()
  91. return {
  92. 'name' : 'Transferencia de déposito',
  93. 'product_id' : self.product_id.id,
  94. 'product_uom' : self.product_uom_id.id,
  95. 'product_uom_qty' : self.product_qty,
  96. 'location_id' : self.source_location.id,
  97. 'location_dest_id' : self.dest_location.id,
  98. 'picking_id' : picking.id,
  99. 'group_id': group.id,
  100. 'note': self.note
  101. }