stock_warehouse_transfer_line.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. product_qty = fields.Float(
  33. string='Cantidad',
  34. default=_get_default_product_qty)
  35. product_uom_id = fields.Many2one(
  36. comodel_name='product.uom',
  37. string='Unidad de Medida')
  38. transfer = fields.Many2one(
  39. comodel_name='stock.warehouse.transfer',
  40. string='Transfer')
  41. note = fields.Text(string='Note')
  42. source_location = fields.Many2one(
  43. comodel_name='stock.location',
  44. string='Source Location',
  45. compute='_get_transfer_locations',
  46. store=True)
  47. dest_location = fields.Many2one(
  48. comodel_name='stock.location',
  49. string='Destination Location',
  50. compute='_get_transfer_locations',
  51. store=True)
  52. @api.one
  53. @api.onchange('product_id')
  54. def product_id_change(self):
  55. self.product_uom_id = self.product_id.uom_id and self.product_id.uom_id.id or False
  56. @api.multi
  57. @api.depends('transfer.source_warehouse', 'transfer.dest_warehouse')
  58. def _get_transfer_locations(self):
  59. for rec in self:
  60. rec.source_location = rec.transfer.source_warehouse.lot_stock_id.id
  61. dest_location = False
  62. transit_locations = self.env['stock.location'].search(
  63. [
  64. ('usage', '=', 'inventory')
  65. ]
  66. )
  67. for location in transit_locations:
  68. if location.get_warehouse(location) == rec.transfer.dest_warehouse.id:
  69. dest_location = location.id
  70. if not dest_location:
  71. rec.dest_location = rec.transfer.dest_warehouse.lot_stock_id.id
  72. else:
  73. rec.dest_location = dest_location
  74. @api.multi
  75. def get_move_vals(self, picking, group):
  76. """
  77. Get the correct move values
  78. :param picking:
  79. :param group:
  80. :return: dict
  81. """
  82. self.ensure_one()
  83. return {
  84. 'name' : 'Warehouse Transfer',
  85. 'product_id' : self.product_id.id,
  86. 'product_uom' : self.product_uom_id.id,
  87. 'product_uom_qty' : self.product_qty,
  88. 'location_id' : self.source_location.id,
  89. 'location_dest_id' : self.dest_location.id,
  90. 'picking_id' : picking.id,
  91. 'group_id': group.id,
  92. 'note': self.note
  93. }