[REF] stock: product: _compute_quantities
This method is used to set `qty_available`, `virtual_available`, `incoming_qty` and `outgoing_qty`. We change the depends because only looking on stock.move is enough (all changes on quants are made through stock moves, and we de not support to edit directly quants anyway). This method will call `_get_domain_locations` and we make sure that, when the `company_owned` key is present in the context, we also return domains to find products that are in a location that belongs to the current user's company. This is done in order to include transit location. Also, remove the comment from tde. As these fields are displayed in view, only using the context could alter the behavior.
This commit is contained in:
@@ -76,7 +76,7 @@ class Product(models.Model):
|
||||
reordering_min_qty = fields.Float(compute='_compute_nbr_reordering_rules')
|
||||
reordering_max_qty = fields.Float(compute='_compute_nbr_reordering_rules')
|
||||
|
||||
@api.depends('stock_quant_ids', 'stock_move_ids')
|
||||
@api.depends('stock_move_ids.product_qty', 'stock_move_ids.state')
|
||||
def _compute_quantities(self):
|
||||
res = self._compute_quantities_dict(self._context.get('lot_id'), self._context.get('owner_id'), self._context.get('package_id'), self._context.get('from_date'), self._context.get('to_date'))
|
||||
for product in self:
|
||||
@@ -154,9 +154,15 @@ class Product(models.Model):
|
||||
It will return all stock locations when no parameters are given
|
||||
Possible parameters are shop, warehouse, location, force_company, compute_child
|
||||
'''
|
||||
# TDE FIXME: clean that brol, context seems overused
|
||||
Warehouse = self.env['stock.warehouse']
|
||||
|
||||
if self.env.context.get('company_owned', False):
|
||||
company_id = self.env.user.company_id.id
|
||||
return (
|
||||
[('location_id.company_id', '=', company_id)],
|
||||
[('location_id.company_id', '=', False), ('location_dest_id.company_id', '=', company_id)],
|
||||
[('location_id.company_id', '=', company_id), ('location_dest_id.company_id', '=', False),
|
||||
])
|
||||
location_ids = []
|
||||
if self.env.context.get('location', False):
|
||||
if isinstance(self.env.context['location'], pycompat.integer_types):
|
||||
|
||||
@@ -12,6 +12,10 @@ class StockMove(TransactionCase):
|
||||
self.customer_location = self.env.ref('stock.stock_location_customers')
|
||||
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
|
||||
self.pack_location = self.env.ref('stock.location_pack_zone')
|
||||
self.transit_location = self.env['stock.location'].search([
|
||||
('company_id', '=', self.env.user.company_id.id),
|
||||
('usage', '=', 'transit'),
|
||||
], limit=1)
|
||||
self.uom_unit = self.env.ref('product.product_uom_unit')
|
||||
self.product1 = self.env['product.product'].create({
|
||||
'name': 'Product A',
|
||||
@@ -2632,3 +2636,39 @@ class StockMove(TransactionCase):
|
||||
self.assertEqual(quant.in_date, Datetime.to_string(initial_in_date_lot1))
|
||||
elif quant.lot_id == lot2:
|
||||
self.assertEqual(quant.in_date, initial_in_date_lot2)
|
||||
|
||||
def test_transit_1(self):
|
||||
""" Receive some products, send some to transit, check the product's `available_qty`
|
||||
computed field with or without the "company_owned" key in the context.
|
||||
"""
|
||||
move1 = self.env['stock.move'].create({
|
||||
'name': 'test_transit_1',
|
||||
'location_id': self.supplier_location.id,
|
||||
'location_dest_id': self.stock_location.id,
|
||||
'product_id': self.product1.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 10.0,
|
||||
'picking_type_id': self.env.ref('stock.picking_type_in').id,
|
||||
})
|
||||
move1.action_confirm()
|
||||
move1.action_assign()
|
||||
move1.move_line_ids.qty_done = 10
|
||||
move1.action_done()
|
||||
|
||||
self.assertEqual(self.product1.qty_available, 10.0)
|
||||
|
||||
move2 = self.env['stock.move'].create({
|
||||
'name': 'test_transit_1',
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.transit_location.id,
|
||||
'product_id': self.product1.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 5.0,
|
||||
})
|
||||
move2.action_confirm()
|
||||
move2.action_assign()
|
||||
move2.move_line_ids.qty_done = 5
|
||||
move2.action_done()
|
||||
|
||||
self.assertEqual(self.product1.qty_available, 5.0)
|
||||
self.assertEqual(self.product1.with_context(company_owned=True).qty_available, 10.0)
|
||||
|
||||
Reference in New Issue
Block a user