[IMP] Take into account owner for move quants

TT28438
This commit is contained in:
sergio-teruel
2021-02-24 22:26:08 +01:00
parent 0355624bcc
commit 277b893f0a
5 changed files with 33 additions and 9 deletions

View File

@@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-11-02 20:30+0000\n"
"PO-Revision-Date: 2020-11-02 21:37+0100\n"
"POT-Creation-Date: 2021-02-25 08:19+0000\n"
"PO-Revision-Date: 2021-02-25 09:20+0100\n"
"Last-Translator: Sergio Teruel <sergio.teruel@tecnativa.com>\n"
"Language-Team: none\n"
"Language: es\n"
@@ -77,6 +77,11 @@ msgstr "Nombre mostrado"
msgid "Edit Locations"
msgstr "(editar)"
#. module: stock_move_location
#: model:ir.model.fields,field_description:stock_move_location.field_wiz_stock_move_location_line__owner_id
msgid "From Owner"
msgstr "Propietario"
#. module: stock_move_location
#: model:ir.model.fields,field_description:stock_move_location.field_wiz_stock_move_location__id
#: model:ir.model.fields,field_description:stock_move_location.field_wiz_stock_move_location_line__id
@@ -229,13 +234,11 @@ msgstr "Si este movimiento es parte de movimiento de ubicaciones"
#. module: stock_move_location
#: model:ir.model,name:stock_move_location.model_wiz_stock_move_location
#, fuzzy
msgid "Wizard move location"
msgstr "Asistente para mover desde ubicación"
#. module: stock_move_location
#: model:ir.model,name:stock_move_location.model_wiz_stock_move_location_line
#, fuzzy
msgid "Wizard move location line"
msgstr "Asistente para mover desde ubicación"

View File

@@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-02-25 08:19+0000\n"
"PO-Revision-Date: 2021-02-25 08:19+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
@@ -73,6 +75,11 @@ msgstr ""
msgid "Edit Locations"
msgstr ""
#. module: stock_move_location
#: model:ir.model.fields,field_description:stock_move_location.field_wiz_stock_move_location_line__owner_id
msgid "From Owner"
msgstr ""
#. module: stock_move_location
#: model:ir.model.fields,field_description:stock_move_location.field_wiz_stock_move_location__id
#: model:ir.model.fields,field_description:stock_move_location.field_wiz_stock_move_location_line__id
@@ -140,6 +147,7 @@ msgstr ""
#. module: stock_move_location
#: code:addons/stock_move_location/wizard/stock_move_location_line.py:0
#: code:addons/stock_move_location/wizard/stock_move_location_line.py:0
#, python-format
msgid "Move quantity can not exceed max quantity or be negative"
msgstr ""

View File

@@ -93,6 +93,7 @@ class StockMoveLocationWizard(models.TransientModel):
"reserved_quantity": quant.reserved_quantity,
"origin_location_id": quant.location_id.id,
"lot_id": quant.lot_id.id,
"owner_id": quant.owner_id.id,
"product_uom_id": quant.product_uom_id.id,
"custom": False,
},
@@ -196,6 +197,7 @@ class StockMoveLocationWizard(models.TransientModel):
("product_id", "=", line.product_id.id),
("location_id", "=", line.origin_location_id.id),
("lot_id", "=", line.lot_id.id),
("owner_id", "=", line.owner_id.id),
("product_uom_qty", ">", 0.0),
]
)
@@ -234,11 +236,11 @@ class StockMoveLocationWizard(models.TransientModel):
# Using sql as search_group doesn't support aggregation functions
# leading to overhead in queries to DB
query = """
SELECT product_id, lot_id, SUM(quantity) AS quantity,
SELECT product_id, lot_id, owner_id, SUM(quantity) AS quantity,
SUM(reserved_quantity) AS reserved_quantity
FROM stock_quant
WHERE location_id = %s
GROUP BY product_id, lot_id
GROUP BY product_id, lot_id, owner_id
"""
self.env.cr.execute(query, (location_id.id,))
return self.env.cr.dictfetchall()
@@ -264,6 +266,7 @@ class StockMoveLocationWizard(models.TransientModel):
"destination_location_id": location_dest_id,
# cursor returns None instead of False
"lot_id": group.get("lot_id") or False,
"owner_id": group.get("owner_id") or False,
"product_uom_id": product.uom_id.id,
"custom": False,
}

View File

@@ -77,6 +77,10 @@
groups="stock.group_production_lot"
options="{'no_create': True}"
/>
<field
name="owner_id"
groups="stock.group_tracking_owner"
/>
<field name="move_quantity" />
<field name="custom" invisible="1" />
<field

View File

@@ -45,6 +45,7 @@ class StockMoveLocationWizardLine(models.TransientModel):
string="Reserved quantity", digits="Product Unit of Measure"
)
custom = fields.Boolean(string="Custom line", default=True)
owner_id = fields.Many2one(comodel_name="res.partner", string="From Owner",)
@staticmethod
def _compare(qty1, qty2, precision_rounding):
@@ -96,6 +97,7 @@ class StockMoveLocationWizardLine(models.TransientModel):
return {
"product_id": self.product_id.id,
"lot_id": self.lot_id.id,
"owner_id": self.owner_id.id,
"location_id": self.origin_location_id.id,
"location_dest_id": location_dest_id,
"product_uom_qty": qty_todo,
@@ -112,7 +114,7 @@ class StockMoveLocationWizardLine(models.TransientModel):
more than exists."""
self.ensure_one()
if not self.product_id:
return 0
return 0, 0
if self.env.context.get("planned"):
# for planned transfer we don't care about the amounts at all
return self.move_quantity, 0
@@ -124,16 +126,20 @@ class StockMoveLocationWizardLine(models.TransientModel):
search_args.append(("lot_id", "=", self.lot_id.id))
else:
search_args.append(("lot_id", "=", False))
if self.owner_id:
search_args.append(("owner_id", "=", self.owner_id.id))
else:
search_args.append(("owner_id", "=", False))
res = self.env["stock.quant"].read_group(search_args, ["quantity"], [])
available_qty = res[0]["quantity"]
if not available_qty:
# if it is immediate transfer and product doesn't exist in that
# location -> make the transfer of 0.
return 0
return 0, 0
rounding = self.product_uom_id.rounding
available_qty_lt_move_qty = (
self._compare(available_qty, self.move_quantity, rounding) == -1
)
if available_qty_lt_move_qty:
return available_qty
return 0, available_qty
return 0, self.move_quantity