[MIG] stock_orderpoint_manual_procurement: Migration to 13.0

This commit is contained in:
Joan Sisquella
2020-01-20 15:25:32 +01:00
parent de6fa7c0d9
commit b864614ec0
5 changed files with 28 additions and 33 deletions

View File

@@ -1,13 +1,12 @@
# Copyright 2016-17 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# Copyright 2016-20 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Stock Orderpoint Manual Procurement",
"summary": "Allows to create procurement orders from orderpoints instead "
"of relying only on the scheduler.",
"version": "12.0.1.1.0",
"author": "Eficent, " "Odoo Community Association (OCA)",
"version": "13.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management",
"depends": ["purchase_stock"],

View File

@@ -1,5 +1,4 @@
# Copyright 2016-17 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# Copyright 2016-20 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from datetime import datetime
@@ -7,10 +6,6 @@ from datetime import datetime
from odoo import api, fields, models
from odoo.tools import float_compare, float_round
from odoo.addons import decimal_precision as dp
UNIT = dp.get_precision("Product Unit of Measure")
class StockWarehouseOrderpoint(models.Model):
_inherit = "stock.warehouse.orderpoint"
@@ -18,13 +13,12 @@ class StockWarehouseOrderpoint(models.Model):
procure_recommended_qty = fields.Float(
string="Procure Recommendation",
compute="_compute_procure_recommended",
digits=UNIT,
digits="Product Unit of Measure",
)
procure_recommended_date = fields.Date(
string="Recommended Request Date", compute="_compute_procure_recommended"
)
@api.multi
def _get_procure_recommended_qty(self, virtual_qty, op_qtys):
self.ensure_one()
procure_recommended_qty = 0.0
@@ -45,7 +39,6 @@ class StockWarehouseOrderpoint(models.Model):
procure_recommended_qty = qty_rounded
return procure_recommended_qty
@api.multi
@api.depends("product_min_qty", "product_id", "qty_multiple")
def _compute_procure_recommended(self):
op_qtys = self._quantity_in_progress()

View File

@@ -1,4 +1,5 @@
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Lois Rilo Antelo <lois.rilo@eficent.com>
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
* Lois Rilo Antelo <lois.rilo@forgeflow.com>
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
* Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
* Joan Sisquella Andrés <joan.sisquella@forgeflow.com>

View File

@@ -1,5 +1,4 @@
# Copyright 2016-17 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# Copyright 2016-20 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
@@ -58,7 +57,7 @@ class TestStockWarehouseOrderpoint(common.TransactionCase):
# Add default quantity
quantity = 20.00
self._update_product_qty(self.product, self.location, quantity)
self._update_product_qty(self.product, quantity)
# Create Reordering Rule
self.reorder = self.create_orderpoint()
@@ -97,12 +96,12 @@ class TestStockWarehouseOrderpoint(common.TransactionCase):
)
return product
def _update_product_qty(self, product, location, quantity):
def _update_product_qty(self, product, quantity):
"""Update Product quantity."""
change_product_qty = self.stock_change_model.create(
{
"location_id": location.id,
"product_id": product.id,
"product_tmpl_id": product.product_tmpl_id.id,
"new_quantity": quantity,
}
)
@@ -111,7 +110,7 @@ class TestStockWarehouseOrderpoint(common.TransactionCase):
def create_orderpoint(self):
"""Create a Reordering Rule"""
reorder = self.reordering_rule_model.sudo(self.user).create(
reorder = self.reordering_rule_model.with_user(self.user).create(
{
"name": "Order-point",
"product_id": self.product.id,
@@ -130,7 +129,7 @@ class TestStockWarehouseOrderpoint(common.TransactionCase):
"active_id": self.reorder.id,
}
wizard = (
self.make_procurement_orderpoint_model.sudo(self.user)
self.make_procurement_orderpoint_model.with_user(self.user)
.with_context(context)
.create({})
)
@@ -153,6 +152,7 @@ class TestStockWarehouseOrderpoint(common.TransactionCase):
[("orderpoint_id", "=", self.reorder.id), ("order_id", "=", purchase.id)]
)
self.assertEquals(len(purchase_line), 1)
self.reorder._compute_procure_recommended()
self.assertNotEqual(
self.reorder.procure_recommended_qty, purchase_line.product_qty
)

View File

@@ -1,5 +1,4 @@
# Copyright 2016-17 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# Copyright 2016-20 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
@@ -59,13 +58,13 @@ class MakeProcurementOrderpoint(models.TransientModel):
res["item_ids"] = items
return res
@api.multi
def make_procurement(self):
self.ensure_one()
errors = []
# User requesting the procurement is passed by context to be able to
# update final MO, PO or trasfer with that information.
pg_obj = self.env["procurement.group"].with_context(requested_uid=self.env.user)
procurements = []
for item in self.item_ids:
if not item.qty:
raise ValidationError(_("Quantity must be positive."))
@@ -75,21 +74,25 @@ class MakeProcurementOrderpoint(models.TransientModel):
values["date_planned"] = fields.Datetime.to_string(
fields.Date.from_string(item.date_planned)
)
# Run procurement
try:
pg_obj.run(
procurements.append(
pg_obj.Procurement(
item.orderpoint_id.product_id,
item.qty,
item.uom_id,
item.orderpoint_id.location_id,
item.orderpoint_id.name,
item.orderpoint_id.name,
item.orderpoint_id.company_id,
values,
)
except UserError as error:
errors.append(error.name)
if errors:
raise UserError("\n".join(errors))
)
try:
# Run procurement
pg_obj.run(procurements)
except UserError as error:
errors.append(error.name)
if errors:
raise UserError("\n".join(errors))
return {"type": "ir.actions.act_window_close"}
@@ -123,7 +126,6 @@ class MakeProcurementOrderpointItem(models.TransientModel):
string="Location", comodel_name="stock.location", readonly=True
)
@api.multi
@api.onchange("uom_id")
def onchange_uom_id(self):
for rec in self: