stock_warehouse_transfer_line.py 3.8 KB

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