123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- # -*- encoding: utf-8 -*-
- ##############################################################################
- #
- # Copyright (C) 2015 ICTSTUDIO (<http://www.ictstudio.eu>).
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as
- # published by the Free Software Foundation, either version 3 of the
- # License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- ##############################################################################
- from openerp import models, fields, api, _
- import logging
- _logger = logging.getLogger(__name__)
- class StockWarehouseTransferLine(models.Model):
- _name = 'stock.warehouse.transfer.line'
- _rec_name = 'product_id'
- @api.model
- def _get_default_product_qty(self):
- return 1.0
- product_id = fields.Many2one(
- comodel_name='product.product',
- string='Producto')
- ean13 = fields.Char('Ean13', related="product_id.ean13", store=True)
- default_code = fields.Char('Referencia interna', related="product_id.default_code", store=True)
- factory_reference = fields.Char(
- comodel_name='product.product',
- string='Referencia')
- product_qty = fields.Float(
- string='Cantidad',
- default=_get_default_product_qty)
- product_uom_id = fields.Many2one(
- comodel_name='product.uom',
- string='Unidad de Medida')
- transfer = fields.Many2one(
- comodel_name='stock.warehouse.transfer',
- string='Transferencia')
- note = fields.Text(string='Note')
- source_location = fields.Many2one(
- comodel_name='stock.location',
- string='Déposito de origen',
- compute='_get_transfer_locations',
- store=True)
- dest_location = fields.Many2one(
- comodel_name='stock.location',
- string='Déposito de destino',
- compute='_get_transfer_locations',
- store=True)
- @api.one
- @api.onchange('product_id')
- def product_id_change(self):
- vals = {}
- self.product_uom_id = self.product_id.uom_id and self.product_id.uom_id.id or False
- self.default_code = self.product_id.default_code
- self.ean13 = self.product_id.ean13
- @api.multi
- @api.depends('transfer.source_warehouse', 'transfer.dest_warehouse')
- def _get_transfer_locations(self):
- for rec in self:
- rec.source_location = rec.transfer.source_warehouse.lot_stock_id.id
- dest_location = False
- transit_locations = self.env['stock.location'].search(
- [
- ('usage', '=', 'transit')
- ]
- )
- for location in transit_locations:
- if location.get_warehouse(location) == rec.transfer.dest_warehouse.id:
- dest_location = location.id
- if not dest_location:
- rec.dest_location = rec.transfer.dest_warehouse.lot_stock_id.id
- else:
- rec.dest_location = dest_location
- @api.multi
- def get_move_vals(self, picking, group):
- """
- Get the correct move values
- :param picking:
- :param group:
- :return: dict
- """
- self.ensure_one()
- return {
- 'name' : 'Transferencia de déposito',
- 'product_id' : self.product_id.id,
- 'product_uom' : self.product_uom_id.id,
- 'product_uom_qty' : self.product_qty,
- 'location_id' : self.source_location.id,
- 'location_dest_id' : self.dest_location.id,
- 'picking_id' : picking.id,
- 'group_id': group.id,
- 'note': self.note
- }
|