[MIG] stock_quant_manual_assign: Migration to 13.0

This commit is contained in:
Tony Gu
2020-04-01 20:48:55 +08:00
committed by Fanha Giang
parent 454ca05c6c
commit f45c84a38c
5 changed files with 46 additions and 31 deletions

View File

@@ -79,6 +79,10 @@ Contributors
* Jordi Ballester <jordi.ballester@eficent.com> * Jordi Ballester <jordi.ballester@eficent.com>
* Lois Rilo <lois.rilo@eficent.com> * Lois Rilo <lois.rilo@eficent.com>
* `Shine IT <https://www.openerp.cn>`_:
* Tony Gu <tony@openerp.cn>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~

View File

@@ -11,3 +11,7 @@
* Jordi Ballester <jordi.ballester@eficent.com> * Jordi Ballester <jordi.ballester@eficent.com>
* Lois Rilo <lois.rilo@eficent.com> * Lois Rilo <lois.rilo@eficent.com>
* `Shine IT <https://www.openerp.cn>`_:
* Tony Gu <tony@openerp.cn>

View File

@@ -9,6 +9,7 @@ class TestStockQuantManualAssign(TransactionCase):
def setUp(self): def setUp(self):
super(TestStockQuantManualAssign, self).setUp() super(TestStockQuantManualAssign, self).setUp()
self.quant_model = self.env["stock.quant"] self.quant_model = self.env["stock.quant"]
self.location_model = self.env["stock.location"]
self.move_model = self.env["stock.move"] self.move_model = self.env["stock.move"]
self.quant_assign_wizard = self.env["assign.manual.quants"] self.quant_assign_wizard = self.env["assign.manual.quants"]
self.product = self.env["product.product"].create( self.product = self.env["product.product"].create(
@@ -16,9 +17,27 @@ class TestStockQuantManualAssign(TransactionCase):
) )
self.location_src = self.env.ref("stock.stock_location_locations_virtual") self.location_src = self.env.ref("stock.stock_location_locations_virtual")
self.location_dst = self.env.ref("stock.stock_location_customers") self.location_dst = self.env.ref("stock.stock_location_customers")
self.location1 = self.env.ref("stock.location_inventory") self.location1 = self.location_model.create(
self.location2 = self.env.ref("stock.location_procurement") {
self.location3 = self.env.ref("stock.location_production") "name": "Location 1",
"usage": "internal",
"location_id": self.location_src.id,
}
)
self.location2 = self.location_model.create(
{
"name": "Location 2",
"usage": "internal",
"location_id": self.location_src.id,
}
)
self.location3 = self.location_model.create(
{
"name": "Location 3",
"usage": "internal",
"location_id": self.location_src.id,
}
)
self.quant1 = self.quant_model.sudo().create( self.quant1 = self.quant_model.sudo().create(
{ {
"product_id": self.product.id, "product_id": self.product.id,

View File

@@ -9,14 +9,11 @@ from odoo import _, api, fields, models
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_compare from odoo.tools.float_utils import float_compare
from odoo.addons import decimal_precision as dp
class AssignManualQuants(models.TransientModel): class AssignManualQuants(models.TransientModel):
_name = "assign.manual.quants" _name = "assign.manual.quants"
_description = "Assign Manual Quants" _description = "Assign Manual Quants"
@api.multi
@api.constrains("quants_lines") @api.constrains("quants_lines")
def _check_qty(self): def _check_qty(self):
precision_digits = self.env["decimal.precision"].precision_get( precision_digits = self.env["decimal.precision"].precision_get(
@@ -44,19 +41,18 @@ class AssignManualQuants(models.TransientModel):
lines_qty = fields.Float( lines_qty = fields.Float(
string="Reserved qty", string="Reserved qty",
compute="_compute_qties", compute="_compute_qties",
digits=dp.get_precision("Product Unit of Measure"), digits="Product Unit of Measure",
) )
move_qty = fields.Float( move_qty = fields.Float(
string="Remaining qty", string="Remaining qty",
compute="_compute_qties", compute="_compute_qties",
digits=dp.get_precision("Product Unit of Measure"), digits="Product Unit of Measure",
) )
quants_lines = fields.One2many( quants_lines = fields.One2many(
"assign.manual.quants.lines", "assign_wizard", string="Quants" "assign.manual.quants.lines", "assign_wizard", string="Quants"
) )
move_id = fields.Many2one(comodel_name="stock.move", string="Move",) move_id = fields.Many2one(comodel_name="stock.move", string="Move",)
@api.multi
def assign_quants(self): def assign_quants(self):
move = self.move_id move = self.move_id
move._do_unreserve() move._do_unreserve()
@@ -82,14 +78,15 @@ class AssignManualQuants(models.TransientModel):
) )
quants_lines = [] quants_lines = []
for quant in available_quants: for quant in available_quants:
line = {} line = {
line["quant_id"] = quant.id "quant_id": quant.id,
line["on_hand"] = quant.quantity "on_hand": quant.quantity,
line["location_id"] = quant.location_id.id "location_id": quant.location_id.id,
line["lot_id"] = quant.lot_id.id "lot_id": quant.lot_id.id,
line["package_id"] = quant.package_id.id "package_id": quant.package_id.id,
line["owner_id"] = quant.owner_id.id "owner_id": quant.owner_id.id,
line["selected"] = False "selected": False,
}
move_lines = move.move_line_ids.filtered( move_lines = move.move_line_ids.filtered(
lambda ml: ( lambda ml: (
ml.location_id == quant.location_id ml.location_id == quant.location_id
@@ -120,11 +117,7 @@ class AssignManualQuantsLines(models.TransientModel):
ondelete="cascade", ondelete="cascade",
) )
quant_id = fields.Many2one( quant_id = fields.Many2one(
comodel_name="stock.quant", comodel_name="stock.quant", string="Quant", required=True, ondelete="cascade",
string="Quant",
required=True,
ondelete="cascade",
oldname="quant",
) )
location_id = fields.Many2one( location_id = fields.Many2one(
comodel_name="stock.location", comodel_name="stock.location",
@@ -152,15 +145,11 @@ class AssignManualQuantsLines(models.TransientModel):
) )
# This is not correctly shown as related or computed, so we make it regular # This is not correctly shown as related or computed, so we make it regular
on_hand = fields.Float( on_hand = fields.Float(
readonly=True, readonly=True, string="On Hand", digits="Product Unit of Measure",
string="On Hand",
digits=dp.get_precision("Product Unit of Measure"),
)
reserved = fields.Float(
string="Others Reserved", digits=dp.get_precision("Product Unit of Measure")
) )
reserved = fields.Float(string="Others Reserved", digits="Product Unit of Measure")
selected = fields.Boolean(string="Select") selected = fields.Boolean(string="Select")
qty = fields.Float(string="QTY", digits=dp.get_precision("Product Unit of Measure")) qty = fields.Float(string="QTY", digits="Product Unit of Measure")
@api.onchange("selected") @api.onchange("selected")
def _onchange_selected(self): def _onchange_selected(self):
@@ -177,7 +166,6 @@ class AssignManualQuantsLines(models.TransientModel):
remaining_qty = record.assign_wizard.move_qty remaining_qty = record.assign_wizard.move_qty
record.qty = min(quant_qty, remaining_qty) record.qty = min(quant_qty, remaining_qty)
@api.multi
@api.constrains("qty") @api.constrains("qty")
def _check_qty(self): def _check_qty(self):
precision_digits = self.env["decimal.precision"].precision_get( precision_digits = self.env["decimal.precision"].precision_get(

View File

@@ -46,7 +46,7 @@
<act_window <act_window
name="Manual assignment" name="Manual assignment"
res_model="assign.manual.quants" res_model="assign.manual.quants"
src_model="stock.move" binding_model="stock.move"
view_mode="form" view_mode="form"
target="new" target="new"
id="assign_manual_quants_action" id="assign_manual_quants_action"