Skip to content

Commit

Permalink
[IMP] stock_picking_operation_quick_change: black, isort
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 committed May 19, 2021
1 parent 0f041b6 commit 7d9a32b
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 164 deletions.
6 changes: 6 additions & 0 deletions setup/stock_picking_operation_quick_change/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
12 changes: 3 additions & 9 deletions stock_picking_operation_quick_change/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
"version": "12.0.1.0.0",
"category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Tecnativa, "
"Odoo Community Association (OCA)",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": [
"stock",
],
"data": [
"wizards/stock_picking_wizard_view.xml",
"views/stock_picking_view.xml",
],
"depends": ["stock",],
"data": ["wizards/stock_picking_wizard_view.xml", "views/stock_picking_view.xml",],
}
Original file line number Diff line number Diff line change
@@ -1,136 +1,147 @@
# © 2017 Sergio Teruel <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase


class TestOperationQuickChange(TransactionCase):

def setUp(self):
super(TestOperationQuickChange, self).setUp()
self.Location = self.env['stock.location']
self.PickingType = self.env['stock.picking.type']
self.Picking = self.env['stock.picking']
self.Product = self.env['product.template']
self.Wizard = self.env['stock.picking.operation.wizard']
self.warehouse = self.env['stock.warehouse'].create({
'name': 'warehouse - test',
'code': 'WH-TEST',
})
self.Location = self.env["stock.location"]
self.PickingType = self.env["stock.picking.type"]
self.Picking = self.env["stock.picking"]
self.Product = self.env["product.template"]
self.Wizard = self.env["stock.picking.operation.wizard"]
self.warehouse = self.env["stock.warehouse"].create(
{"name": "warehouse - test", "code": "WH-TEST",}
)

# self.warehouse.lot_stock_id.id
self.product = self.Product.create({
'name': 'Product - Test',
'type': 'product',
'list_price': 100.00,
'standard_price': 100.00,
})
self.product = self.Product.create(
{
"name": "Product - Test",
"type": "product",
"list_price": 100.00,
"standard_price": 100.00,
}
)
self.qty_on_hand(self.product.product_variant_ids[:1])
self.product2 = self.Product.create({
'name': 'Product2 - Test',
'type': 'product',
'list_price': 100.00,
'standard_price': 100.00,
})
self.product2 = self.Product.create(
{
"name": "Product2 - Test",
"type": "product",
"list_price": 100.00,
"standard_price": 100.00,
}
)
self.qty_on_hand(self.product2.product_variant_ids[:1])
self.customer = self.env['res.partner'].create({
'name': 'Customer - test',
'customer': True,
})
self.picking_type = self.PickingType.search([
('warehouse_id', '=', self.warehouse.id),
('code', '=', 'outgoing'),
])
self.picking = self.Picking.create({
'name': 'picking - test 01',
'location_id': self.warehouse.lot_stock_id.id,
'location_dest_id': self.warehouse.wh_output_stock_loc_id.id,
'picking_type_id': self.picking_type.id,
'move_lines': [(0, 0, {
'name': self.product.name,
'product_id': self.product.product_variant_ids[:1].id,
'product_uom_qty': 20.0,
'product_uom': self.product.uom_id.id,
}), (0, 0, {
'name': self.product.name,
'product_id': self.product2.product_variant_ids[:1].id,
'product_uom_qty': 60.0,
'product_uom': self.product.uom_id.id,
})]
})
self.customer = self.env["res.partner"].create(
{"name": "Customer - test", "customer": True,}
)
self.picking_type = self.PickingType.search(
[("warehouse_id", "=", self.warehouse.id), ("code", "=", "outgoing"),]
)
self.picking = self.Picking.create(
{
"name": "picking - test 01",
"location_id": self.warehouse.lot_stock_id.id,
"location_dest_id": self.warehouse.wh_output_stock_loc_id.id,
"picking_type_id": self.picking_type.id,
"move_lines": [
(
0,
0,
{
"name": self.product.name,
"product_id": self.product.product_variant_ids[:1].id,
"product_uom_qty": 20.0,
"product_uom": self.product.uom_id.id,
},
),
(
0,
0,
{
"name": self.product.name,
"product_id": self.product2.product_variant_ids[:1].id,
"product_uom_qty": 60.0,
"product_uom": self.product.uom_id.id,
},
),
],
}
)

def qty_on_hand(self, product):
stock_change_obj = self.env['stock.change.product.qty']
stock_change_obj = self.env["stock.change.product.qty"]
vals = {
'product_id': product.id,
'new_quantity': 200.0,
'location_id': self.warehouse.lot_stock_id.id,
"product_id": product.id,
"new_quantity": 200.0,
"location_id": self.warehouse.lot_stock_id.id,
}
wiz = stock_change_obj.create(vals)
wiz.change_product_qty()

def test_picking_operation_change_location_dest_all(self):
self.picking.action_assign()
new_location_dest_id = self.Location.create({
'name': 'New Test Customer Location',
'location_id': self.picking.location_dest_id.location_id.id
})
new_location_dest_id = self.Location.create(
{
"name": "New Test Customer Location",
"location_id": self.picking.location_dest_id.location_id.id,
}
)
wiz = self.Wizard.with_context(
active_model=self.picking._name,
active_ids=self.picking.ids,
).create({
'new_location_dest_id': new_location_dest_id.id,
'change_all': True,
})
move_lines = self.picking.mapped('move_line_ids')
active_model=self.picking._name, active_ids=self.picking.ids,
).create({"new_location_dest_id": new_location_dest_id.id, "change_all": True,})
move_lines = self.picking.mapped("move_line_ids")
self.assertEqual(wiz.location_dest_id, self.picking.location_dest_id)
self.assertEqual(wiz.old_location_dest_id,
move_lines[:1].location_dest_id)
self.assertEqual(wiz.old_location_dest_id, move_lines[:1].location_dest_id)
wiz.action_apply()
move_lines = self.picking.mapped(
'move_line_ids.location_dest_id')
move_lines = self.picking.mapped("move_line_ids.location_dest_id")
self.assertEqual(len(move_lines), 1)

def test_picking_operation_change_location_dest(self):
new_location_dest_id = self.Location.create({
'name': 'New Test Customer Location',
'location_id': self.picking.location_dest_id.location_id.id
})
other_location_dest_id = self.Location.create({
'name': 'New Test Customer Location',
'location_id': self.picking.location_dest_id.location_id.id
})
new_location_dest_id = self.Location.create(
{
"name": "New Test Customer Location",
"location_id": self.picking.location_dest_id.location_id.id,
}
)
other_location_dest_id = self.Location.create(
{
"name": "New Test Customer Location",
"location_id": self.picking.location_dest_id.location_id.id,
}
)
self.picking.action_assign()
move_lines = self.picking.mapped('move_line_ids')
move_lines[:1].write({'location_dest_id': other_location_dest_id.id})
move_lines = self.picking.mapped("move_line_ids")
move_lines[:1].write({"location_dest_id": other_location_dest_id.id})
wiz = self.Wizard.with_context(
active_model=self.picking._name,
active_ids=self.picking.ids,
).create({
'old_location_dest_id': self.picking.location_dest_id.id,
'new_location_dest_id': new_location_dest_id.id,
})
active_model=self.picking._name, active_ids=self.picking.ids,
).create(
{
"old_location_dest_id": self.picking.location_dest_id.id,
"new_location_dest_id": new_location_dest_id.id,
}
)
wiz.action_apply()
move_lines = self.picking.mapped(
'move_line_ids.location_dest_id')
move_lines = self.picking.mapped("move_line_ids.location_dest_id")
self.assertEqual(len(move_lines), 2)

def test_picking_operation_change_location_dest_failed(self):
self.picking.action_assign()
for move in self.picking.move_lines:
move.quantity_done = 1
self.picking.action_done()
new_location_dest_id = self.Location.create({
'name': 'New Test Customer Location',
'location_id': self.picking.location_dest_id.location_id.id
})
new_location_dest_id = self.Location.create(
{
"name": "New Test Customer Location",
"location_id": self.picking.location_dest_id.location_id.id,
}
)
wiz = self.Wizard.with_context(
active_model=self.picking._name,
active_ids=self.picking.ids,
).create({
'new_location_dest_id': new_location_dest_id.id,
'change_all': True,
})
active_model=self.picking._name, active_ids=self.picking.ids,
).create({"new_location_dest_id": new_location_dest_id.id, "change_all": True,})
with self.assertRaises(UserError):
wiz.action_apply()
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2017 Sergio Teruel <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record id="view_picking_form" model="ir.ui.view">
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="inherit_id" ref="stock.view_picking_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='move_ids_without_package']" position="before">
<button name="%(action_stock_picking_operation_change_location)d"
type="action"
string="Change Location"
groups="stock.group_stock_user">
<button
name="%(action_stock_picking_operation_change_location)d"
type="action"
string="Change Location"
groups="stock.group_stock_user"
>
</button>
</xpath>
</field>
</record>

</odoo>
Loading

0 comments on commit 7d9a32b

Please sign in to comment.