Files
stock-logistics-warehouse/stock_request/models/stock_move.py
mreficent d9150b8335 [FIX] Various fixes:
- Error with the sequence number.
- Visible texts that should be in uppercases.
- order_id should only be visible if group_stock_request_order
  option is enabled.
- adds more tests
- adds consistency between models company-wise
2021-04-19 15:50:02 +07:00

40 lines
1.5 KiB
Python

# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
class StockMove(models.Model):
_inherit = 'stock.move'
allocation_ids = fields.One2many(comodel_name='stock.request.allocation',
inverse_name='stock_move_id',
string='Stock Request Allocation')
stock_request_ids = fields.One2many(comodel_name='stock.request',
string='Stock Requests',
compute='_compute_stock_request_ids')
@api.depends('allocation_ids')
def _compute_stock_request_ids(self):
for rec in self:
rec.stock_request_ids = rec.allocation_ids.mapped(
'stock_request_id')
def _merge_moves_fields(self):
res = super(StockMove, self)._merge_moves_fields()
res['allocation_ids'] = [(4, m.id) for m in
self.mapped('allocation_ids')]
return res
@api.constrains('company_id')
def _check_company_stock_request(self):
if any(self.env['stock.request.allocation'].search(
[('company_id', '!=', rec.company_id.id),
('stock_move_id', '=', rec.id)], limit=1)
for rec in self):
raise ValidationError(
_('The company of the stock request must match with '
'that of the location.'))