stock_warehouse_transfer_line.py 3.8 KB

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