mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_reserve: black, isort
This commit is contained in:
committed by
aliciagarzo
parent
b5c2535f84
commit
17e10dfdba
@@ -7,7 +7,7 @@ from odoo.tools.translate import _
|
||||
|
||||
|
||||
class StockReservation(models.Model):
|
||||
""" Allow to reserve products.
|
||||
"""Allow to reserve products.
|
||||
|
||||
The fields mandatory for the creation of a reservation are:
|
||||
|
||||
@@ -45,15 +45,15 @@ class StockReservation(models.Model):
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
""" Fix default values
|
||||
"""Fix default values
|
||||
|
||||
- Ensure default value of computed field `product_qty` is not set
|
||||
as it would raise an error
|
||||
- Compute default `location_id` based on default `picking_type_id`.
|
||||
Note: `default_picking_type_id` may be present in context,
|
||||
so code that looks for default `location_id` is implemented here,
|
||||
because it relies on already calculated default
|
||||
`picking_type_id`.
|
||||
- Ensure default value of computed field `product_qty` is not set
|
||||
as it would raise an error
|
||||
- Compute default `location_id` based on default `picking_type_id`.
|
||||
Note: `default_picking_type_id` may be present in context,
|
||||
so code that looks for default `location_id` is implemented here,
|
||||
because it relies on already calculated default
|
||||
`picking_type_id`.
|
||||
"""
|
||||
# if there is 'location_id' field requested, ensure that
|
||||
# picking_type_id is also requested, because it is required
|
||||
@@ -94,7 +94,7 @@ class StockReservation(models.Model):
|
||||
|
||||
@api.model
|
||||
def get_location_from_ref(self, ref):
|
||||
""" Get a location from a xmlid if allowed
|
||||
"""Get a location from a xmlid if allowed
|
||||
:param ref: tuple (module, xmlid)
|
||||
"""
|
||||
try:
|
||||
@@ -116,7 +116,7 @@ class StockReservation(models.Model):
|
||||
return self.get_location_from_ref(ref)
|
||||
|
||||
def reserve(self):
|
||||
""" Confirm reservations
|
||||
"""Confirm reservations
|
||||
|
||||
The reservation is done using the default UOM of the product.
|
||||
A date until which the product is reserved can be specified.
|
||||
@@ -144,7 +144,7 @@ class StockReservation(models.Model):
|
||||
|
||||
@api.model
|
||||
def release_validity_exceeded(self, ids=None):
|
||||
""" Release all the reservation having an exceeded validity date """
|
||||
"""Release all the reservation having an exceeded validity date"""
|
||||
domain = [
|
||||
("date_validity", "<", fields.date.today()),
|
||||
("state", "!=", "cancel"),
|
||||
@@ -155,13 +155,13 @@ class StockReservation(models.Model):
|
||||
return True
|
||||
|
||||
def unlink(self):
|
||||
""" Release the reservation before the unlink """
|
||||
"""Release the reservation before the unlink"""
|
||||
self.release_reserve()
|
||||
return super().unlink()
|
||||
|
||||
@api.onchange("product_id")
|
||||
def _onchange_product_id(self):
|
||||
""" set product_uom and name from product onchange """
|
||||
"""set product_uom and name from product onchange"""
|
||||
# save value before reading of self.move_id as this last one erase
|
||||
# product_id value
|
||||
self.move_id.product_id = self.product_id
|
||||
@@ -171,7 +171,7 @@ class StockReservation(models.Model):
|
||||
|
||||
@api.onchange("product_uom_qty")
|
||||
def _onchange_quantity(self):
|
||||
""" On change of product quantity avoid negative quantities """
|
||||
"""On change of product quantity avoid negative quantities"""
|
||||
if not self.product_id or self.product_uom_qty <= 0.0:
|
||||
self.product_uom_qty = 0.0
|
||||
|
||||
@@ -183,7 +183,8 @@ class StockReservation(models.Model):
|
||||
# open directly in the form view
|
||||
view_id = self.env.ref("stock.view_move_form").id
|
||||
action_dict.update(
|
||||
views=[(view_id, "form")], res_id=self.move_id.id,
|
||||
views=[(view_id, "form")],
|
||||
res_id=self.move_id.id,
|
||||
)
|
||||
return action_dict
|
||||
|
||||
|
||||
@@ -30,16 +30,16 @@ class TestStockReserve(common.TransactionCase):
|
||||
form_reservation_1.location_id = self.warehouse.lot_stock_id
|
||||
reservation_1 = form_reservation_1.save()
|
||||
reservation_1.reserve()
|
||||
self.assertEquals(self.product.virtual_available, 4)
|
||||
self.assertEqual(self.product.virtual_available, 4)
|
||||
form_reservation_2 = Form(self.env["stock.reservation"])
|
||||
form_reservation_2.product_id = self.product
|
||||
form_reservation_2.product_uom_qty = 1
|
||||
form_reservation_2.location_id = self.warehouse.lot_stock_id
|
||||
reservation_2 = form_reservation_2.save()
|
||||
reservation_2.reserve()
|
||||
self.assertEquals(self.product.virtual_available, 3)
|
||||
self.assertEqual(self.product.virtual_available, 3)
|
||||
reservation_1.release_reserve()
|
||||
self.assertEquals(self.product.virtual_available, 9)
|
||||
self.assertEqual(self.product.virtual_available, 9)
|
||||
|
||||
def test_cron_release(self):
|
||||
form_reservation_1 = Form(self.env["stock.reservation"])
|
||||
@@ -49,10 +49,10 @@ class TestStockReserve(common.TransactionCase):
|
||||
form_reservation_1.date_validity = fields.Date.from_string("2021-01-01")
|
||||
reservation_1 = form_reservation_1.save()
|
||||
reservation_1.reserve()
|
||||
self.assertEquals(self.product.virtual_available, 4)
|
||||
self.assertEqual(self.product.virtual_available, 4)
|
||||
cron = self.env.ref("stock_reserve.ir_cron_release_stock_reservation")
|
||||
cron.method_direct_trigger()
|
||||
self.assertEquals(self.product.virtual_available, 10)
|
||||
self.assertEqual(self.product.virtual_available, 10)
|
||||
|
||||
def test_cron_reserve(self):
|
||||
form_reservation_1 = Form(self.env["stock.reservation"])
|
||||
@@ -61,7 +61,7 @@ class TestStockReserve(common.TransactionCase):
|
||||
form_reservation_1.location_id = self.warehouse.lot_stock_id
|
||||
reservation_1 = form_reservation_1.save()
|
||||
reservation_1.reserve()
|
||||
self.assertEquals(reservation_1.state, "partially_available")
|
||||
self.assertEqual(reservation_1.state, "partially_available")
|
||||
self.env["stock.quant"].create(
|
||||
{
|
||||
"product_id": self.product.id,
|
||||
@@ -71,5 +71,5 @@ class TestStockReserve(common.TransactionCase):
|
||||
)
|
||||
cron = self.env.ref("stock_reserve.ir_cron_reserve_waiting_confirmed")
|
||||
cron.method_direct_trigger()
|
||||
self.assertEquals(reservation_1.state, "assigned")
|
||||
self.assertEquals(self.product.virtual_available, 9)
|
||||
self.assertEqual(reservation_1.state, "assigned")
|
||||
self.assertEqual(self.product.virtual_available, 9)
|
||||
|
||||
Reference in New Issue
Block a user