[MIG] stock_reserve 15.0:

- Additionally include note field in stock reservation. It [was](71203e0aa2) removed
This commit is contained in:
Fernando La Chica
2022-09-14 17:29:52 +02:00
committed by Chris Mann
parent b2147a213b
commit 0f100e3ca4
8 changed files with 37 additions and 32 deletions

View File

@@ -57,6 +57,11 @@ To make a stock reservation:
You can release a reservation by clicking on the button *Release*
Known issues / Roadmap
======================
* Review multicompany. Take a look of https://github.com/OCA/stock-logistics-warehouse/pull/1346 PR
Bug Tracker
===========

View File

@@ -3,7 +3,7 @@
{
"name": "Stock Reservation",
"summary": "Stock reservations on products",
"version": "13.0.1.0.0",
"version": "15.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"category": "Warehouse",
"license": "AGPL-3",

View File

@@ -18,9 +18,10 @@ class ProductTemplate(models.Model):
def action_view_reservations(self):
self.ensure_one()
ref = "stock_reserve.action_stock_reservation_tree"
action_dict = self.env["ir.actions.act_window"]._for_xml_id(
"stock_reserve.action_stock_reservation_tree"
)
product_ids = self.mapped("product_variant_ids.id")
action_dict = self.env.ref(ref).read()[0]
action_dict["domain"] = [("product_id", "in", product_ids)]
action_dict["context"] = {
"search_default_draft": 1,
@@ -48,8 +49,9 @@ class ProductProduct(models.Model):
def action_view_reservations(self):
self.ensure_one()
ref = "stock_reserve.action_stock_reservation_tree"
action_dict = self.env.ref(ref).read()[0]
action_dict = self.env["ir.actions.act_window"]._for_xml_id(
"stock_reserve.action_stock_reservation_tree"
)
action_dict["domain"] = [("product_id", "=", self.id)]
action_dict["context"] = {
"search_default_draft": 1,

View File

@@ -33,6 +33,7 @@ class StockReservation(models.Model):
_description = "Stock Reservation"
_inherits = {"stock.move": "move_id"}
note = fields.Text(string="Notes")
move_id = fields.Many2one(
"stock.move",
"Reservation Move",
@@ -84,7 +85,7 @@ class StockReservation(models.Model):
picking = self.env["stock.picking"].new(
{"picking_type_id": picking_type_id}
)
picking.onchange_picking_type()
picking._onchange_picking_type()
res["location_id"] = picking.location_id.id
if "location_dest_id" in fields_list:
res["location_dest_id"] = self._default_location_dest_id()
@@ -121,7 +122,7 @@ class StockReservation(models.Model):
The reservation is done using the default UOM of the product.
A date until which the product is reserved can be specified.
"""
self.write({"date_expected": fields.Datetime.now()})
self.write({"date": fields.Datetime.now()})
self.mapped("move_id")._action_confirm(merge=False)
self.mapped("move_id.picking_id").action_assign()
return True
@@ -165,7 +166,7 @@ class StockReservation(models.Model):
# save value before reading of self.move_id as this last one erase
# product_id value
self.move_id.product_id = self.product_id
self.move_id.onchange_product_id()
self.move_id._onchange_product_id()
self.name = self.move_id.name
self.product_uom = self.move_id.product_uom
@@ -177,8 +178,9 @@ class StockReservation(models.Model):
def open_move(self):
self.ensure_one()
action = self.env.ref("stock.stock_move_action")
action_dict = action.read()[0]
action_dict = self.env["ir.actions.act_window"]._for_xml_id(
"stock.stock_move_action"
)
action_dict["name"] = _("Reservation Move")
# open directly in the form view
view_id = self.env.ref("stock.view_move_form").id

View File

@@ -6,3 +6,7 @@
* `Tecnativa <https://www.tecnativa.com>`_:
* Carlos Roca
* `GreenIce <https://www.greenice.com>`_:
* Fernando La Chica <fernandolachica@gmail.com>

View File

@@ -0,0 +1 @@
* Review multicompany. Take a look of [this](https://github.com/OCA/stock-logistics-warehouse/pull/1346) PR

View File

@@ -14,6 +14,7 @@ class TestStockReserve(common.TransactionCase):
product_form = Form(self.env["product.product"])
product_form.name = "Test Product"
product_form.type = "product"
product_form.detailed_type = "product"
self.product = product_form.save()
self.env["stock.quant"].create(
{
@@ -23,31 +24,26 @@ class TestStockReserve(common.TransactionCase):
}
)
def _create_stock_reservation(self, qty):
form_reservation = Form(self.env["stock.reservation"])
form_reservation.product_id = self.product
form_reservation.product_uom_qty = qty
form_reservation.location_id = self.warehouse.lot_stock_id
return form_reservation.save()
def test_reservation_and_reservation_release(self):
form_reservation_1 = Form(self.env["stock.reservation"])
form_reservation_1.product_id = self.product
form_reservation_1.product_uom_qty = 6
form_reservation_1.location_id = self.warehouse.lot_stock_id
reservation_1 = form_reservation_1.save()
reservation_1 = self._create_stock_reservation(6)
reservation_1.reserve()
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 = self._create_stock_reservation(1)
reservation_2.reserve()
self.assertEqual(self.product.virtual_available, 3)
reservation_1.release_reserve()
self.assertEqual(self.product.virtual_available, 9)
def test_cron_release(self):
form_reservation_1 = Form(self.env["stock.reservation"])
form_reservation_1.product_id = self.product
form_reservation_1.product_uom_qty = 6
form_reservation_1.location_id = self.warehouse.lot_stock_id
form_reservation_1.date_validity = fields.Date.from_string("2021-01-01")
reservation_1 = form_reservation_1.save()
reservation_1 = self._create_stock_reservation(6)
reservation_1.date_validity = fields.Date.from_string("2021-01-01")
reservation_1.reserve()
self.assertEqual(self.product.virtual_available, 4)
cron = self.env.ref("stock_reserve.ir_cron_release_stock_reservation")
@@ -55,11 +51,7 @@ class TestStockReserve(common.TransactionCase):
self.assertEqual(self.product.virtual_available, 10)
def test_cron_reserve(self):
form_reservation_1 = Form(self.env["stock.reservation"])
form_reservation_1.product_id = self.product
form_reservation_1.product_uom_qty = 11
form_reservation_1.location_id = self.warehouse.lot_stock_id
reservation_1 = form_reservation_1.save()
reservation_1 = self._create_stock_reservation(11)
reservation_1.reserve()
self.assertEqual(reservation_1.state, "partially_available")
self.env["stock.quant"].create(

View File

@@ -81,7 +81,6 @@
<field name="model">stock.reservation</field>
<field name="arch" type="xml">
<tree
string="Stock Reservations"
decoration-primary="state == 'draft'"
decoration-muted="state == 'cancel'"
>