Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0] Several improvements on stock_quant_packages_moving_wizard #1345

Open
wants to merge 3 commits into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stock_quant_packages_moving_wizard/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"wizard/quant_move_wizard_view.xml",
"wizard/quants_move_wizard_view.xml",
"wizard/quant_packages_move_wizard_view.xml",
"views/stock_view.xml",
],
"installable": True,
}
43 changes: 28 additions & 15 deletions stock_quant_packages_moving_wizard/models/stock.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
# -*- coding: utf-8 -*-
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, fields, models
from openerp import api, fields, models, _
from openerp.tools.float_utils import float_compare


class StockQuant(models.Model):
_inherit = 'stock.quant'

@api.one
def move_to(self, dest_location):
move_obj = self.with_context(quant_moving=True).env['stock.move']
new_move = move_obj.create({
'name': 'Move %s to %s' % (self.product_id.name,
dest_location.name),
@api.multi
def _prepare_move_to(self, dest_location):
self.ensure_one()
vals = {
'name': '%s: Move to %s' % (
self.product_id.name_get()[0][1],
dest_location.complete_name),
'product_id': self.product_id.id,
'location_id': self.location_id.id,
'location_dest_id': dest_location.id,
'product_uom_qty': self.qty,
'product_uom': self.product_id.uom_id.id,
'date_expected': fields.Datetime.now(),
'date': fields.Datetime.now(),
'quant_ids': [(4, self.id)],
'restrict_lot_id': self.lot_id.id
})
new_move.action_done()
'restrict_lot_id': self.lot_id.id,
'origin': _('Quant Move'),
}
return vals

@api.one
def move_to(self, dest_location):
# if the quant is reserved for another move,
# we should cleanly un-reserve it first, so that
# the picking that booked this quant comes back from
# available to waiting availability
if self.reservation_id:
self.reservation_id.do_unreserve()
vals = self._prepare_move_to(dest_location)
new_move = self.env['stock.move'].create(vals)
# No group has write access on stock.quant -> we need sudo()
self.sudo().reservation_id = new_move
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will do almost the same thing that is done in #1358

new_move.with_context(quant_moving=True).action_done()

@api.model
def quants_get_prefered_domain(
self, location, product, qty, domain=None,
prefered_domain_list=None, restrict_lot_id=False,
prefered_domain_list=[], restrict_lot_id=False,
Copy link
Contributor

@oihane oihane Feb 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexis-via I think this change is not allowed by pylint check
https://travis-ci.org/odoomrp/odoomrp-wip/jobs/198061670#L511

I don't remember but I think I did it that way because of that.

restrict_partner_id=False):
if prefered_domain_list is None:
prefered_domain_list = []
quants = super(StockQuant, self).quants_get_prefered_domain(
location, product, qty, domain=domain,
prefered_domain_list=prefered_domain_list,
restrict_lot_id=restrict_lot_id,
restrict_partner_id=restrict_partner_id)
if location.usage not in ['inventory', 'production', 'supplier']:
return quants
if self.env.context.get('quant_moving', False):
if self.env.context.get('quant_moving'):
if domain is None:
domain = []
res_qty = qty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def setUp(self):
'parent_id': self.package1.id,
'quant_ids': [(6, 0, self.quant2.ids)],
})
self.assertEquals(self.quant2.package_id, self.package2)
self.assertEquals(self.quant1.location_id.id, self.location_from_id)
self.assertEquals(self.quant2.location_id.id, self.location_from_id)
self.assertEquals(self.package1.location_id.id, self.location_from_id)
Expand All @@ -51,11 +52,9 @@ def test_move_quant(self):
move_wiz = self.quant_move_model.create({
'pack_move_items': [(0, 0,
{'quant': self.quant1.id,
'source_loc': self.quant1.location_id.id,
'dest_loc': self.location_to_id})],
})
move_wiz.do_transfer()
self.assertNotEquals(self.quant1.location_id.id, self.location_from_id)
self.assertEquals(self.quant1.location_id.id, self.location_to_id)

def test_move_quant_default(self):
Expand All @@ -64,23 +63,22 @@ def test_move_quant_default(self):
self.assertEquals(
move_wiz_vals['pack_move_items'][0]['quant'], self.quant1.id)

def test_move_quant_item_onchange_quant(self):
item = self.quant_move_item_model.new({'quant': self.quant1.id})
item.onchange_quant()
self.assertEquals(item.source_loc, self.quant1.location_id)

def test_move_package_default(self):
move_wiz_vals = self.package_move_model.with_context(
active_ids=self.package1.ids).default_get([])
self.assertEquals(
move_wiz_vals['pack_move_items'][0]['package'], self.package1.id)

def test_move_package_item_onchange_quant(self):
item = self.package_move_item_model.new({'package': self.package1.id})
item.onchange_quant()
self.assertEquals(item.source_loc, self.package1.location_id)

def test_move_quants_item_onchange_quant(self):
item = self.quants_move_item_model.new({'quant': self.quant1.id})
item.onchange_quant()
self.assertEquals(item.source_loc, self.quant1.location_id)
def test_move_quant_package(self):
move_wiz = self.package_move_model.create({
'pack_move_items': [(0, 0,
{'package': self.package1.id,
'dest_loc': self.location_to_id})],
})
move_wiz.do_detailed_transfer()
self.assertEquals(self.quant2.location_id.id, self.location_to_id)
# It fails here because of a bug in the module
# quant2 is not inside the package2
self.assertEquals(self.quant2.package_id, self.package2)
self.assertEquals(self.package1.location_id.id, self.location_to_id)
self.assertEquals(self.package2.location_id.id, self.location_to_id)
28 changes: 28 additions & 0 deletions stock_quant_packages_moving_wizard/views/stock_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>

<record id="view_stock_quant_form" model="ir.ui.view">
<field name="name">move_wizard.stock.quant.form</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_form"/>
<field name="arch" type="xml">
<button name="action_view_quant_history" position="before">
<button name="%(action_move_quants)d" type="action" string="Move to Another Location"/>
</button>
</field>
</record>

<record id="view_quant_package_form" model="ir.ui.view">
<field name="name">move_wizard.stock.quant.package.form</field>
<field name="model">stock.quant.package</field>
<field name="inherit_id" ref="stock.view_quant_package_form"/>
<field name="arch" type="xml">
<button name="unpack" position="before">
<button name="%(action_move_packages)d" type="action" string="Move to Another Location"/>
</button>
</field>
</record>

</data>
</openerp>
20 changes: 8 additions & 12 deletions stock_quant_packages_moving_wizard/wizard/quant_move_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
class StockQuantMove(models.TransientModel):
_name = 'stock.quant.move'

# TODO port v9: rename this field to remove 'pack_', which is confusing
pack_move_items = fields.One2many(
comodel_name='stock.quant.move_items', inverse_name='move_id',
string='Packs')

@api.model
def default_get(self, fields):
res = super(StockQuantMove, self).default_get(fields)
def default_get(self, fields_list):
res = super(StockQuantMove, self).default_get(fields_list)
quants_ids = self.env.context.get('active_ids', [])
if not quants_ids:
return res
Expand All @@ -22,11 +23,11 @@ def default_get(self, fields):
items = []
for quant in quants:
if not quant.package_id:
item = {
items.append({
'quant': quant.id,
# source_loc is needed even if it's a related field...
'source_loc': quant.location_id.id,
}
items.append(item)
})
res.update(pack_move_items=items)
return res

Expand All @@ -44,15 +45,10 @@ class StockQuantMoveItems(models.TransientModel):
move_id = fields.Many2one(
comodel_name='stock.quant.move', string='Quant move')
quant = fields.Many2one(
comodel_name='stock.quant', string='Quant',
comodel_name='stock.quant', string='Quant', required=True,
domain=[('package_id', '=', False)])
source_loc = fields.Many2one(
comodel_name='stock.location', string='Source Location', required=True)
string='Current Location', related='quant.location_id', readonly=True)
dest_loc = fields.Many2one(
comodel_name='stock.location', string='Destination Location',
required=True)

@api.one
@api.onchange('quant')
def onchange_quant(self):
self.source_loc = self.quant.location_id
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<openerp>
<data>
<record id="stock_quant_move_wizard" model="ir.ui.view">
<field name="name">Enter transfer details</field>
<field name="name">stock.quant.move.wizard.form</field>
<field name="model">stock.quant.move</field>
<field name="arch" type="xml">
<form string="Transfer details" version="7">
<group groups="stock.group_tracking_lot">
<field name="pack_move_items"
nolabel="1">
<form string="Transfer details">
<group name="main">
<field name="pack_move_items" nolabel="1">
<tree editable="bottom">
<field name="quant" />
<field name="source_loc" />
<field name="dest_loc" />
<field name="dest_loc"
domain="[('id', '!=', source_loc)]"/>
</tree>
</field>
</group>
Expand All @@ -27,8 +27,9 @@
</field>
</record>

<act_window name="Move Stock Quant" groups="stock.group_tracking_lot"
<act_window name="Move Quant"
res_model="stock.quant.move" src_model="stock.quant"
view_mode="form" target="new" key2="client_action_multi" id="action_move_quants" />

</data>
</openerp>
</openerp>
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class StockQuantPackageMove(models.TransientModel):
string='Packs')

@api.model
def default_get(self, fields):
res = super(StockQuantPackageMove, self).default_get(fields)
def default_get(self, fields_list):
res = super(StockQuantPackageMove, self).default_get(fields_list)
packages_ids = self.env.context.get('active_ids', [])
if not packages_ids:
return res
Expand All @@ -22,16 +22,17 @@ def default_get(self, fields):
items = []
for package in packages:
if not package.parent_id and package.location_id:
item = {
items.append({
'package': package.id,
# source_loc is needed even if it's a related field...
'source_loc': package.location_id.id,
}
items.append(item)
})
res.update(pack_move_items=items)
return res

@api.one
@api.multi
def do_detailed_transfer(self):
self.ensure_one()
for item in self.pack_move_items:
if item.dest_loc is not item.source_loc:
for quant in item.package.quant_ids:
Expand All @@ -50,14 +51,11 @@ class StockQuantPackageMoveItems(models.TransientModel):
comodel_name='stock.quant.package.move', string='Package move')
package = fields.Many2one(
comodel_name='stock.quant.package', string='Quant package',
required=True,
domain=[('parent_id', '=', False), ('location_id', '!=', False)])
source_loc = fields.Many2one(
comodel_name='stock.location', string='Source Location', required=True)
string='Current Location', related='package.location_id',
readonly=True)
dest_loc = fields.Many2one(
comodel_name='stock.location', string='Destination Location',
required=True)

@api.one
@api.onchange('package')
def onchange_quant(self):
self.source_loc = self.package.location_id
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<openerp>
<data>
<record id="stock_quant_package_move_wizard" model="ir.ui.view">
<field name="name">Enter transfer details</field>
<field name="name">stock.quant.package.move.wizard.form</field>
<field name="model">stock.quant.package.move</field>
<field name="arch" type="xml">
<form string="Transfer details" version="7">
<group groups="stock.group_tracking_lot">
<field name="pack_move_items"
nolabel="1">
<form string="Package Transfer details">
<group name="main">
<field name="pack_move_items" nolabel="1">
<tree editable="bottom">
<field name="package" />
<field name="source_loc" />
<field name="dest_loc" />
<field name="dest_loc"
domain="[('id', '!=', source_loc)]" />
</tree>
</field>
</group>
Expand All @@ -27,7 +27,7 @@
</field>
</record>

<act_window name="Move Stock Quant Packages" groups="stock.group_tracking_lot"
<act_window name="Move Packages" groups="stock.group_tracking_lot"
res_model="stock.quant.package.move" src_model="stock.quant.package"
view_mode="form" target="new" key2="client_action_multi" id="action_move_packages" />
</data>
Expand Down
Loading