mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[mod] added qty control
This commit is contained in:
20
stock_quant_manual_assign/__init__.py
Normal file
20
stock_quant_manual_assign/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from . import wizard
|
||||
35
stock_quant_manual_assign/__openerp__.py
Normal file
35
stock_quant_manual_assign/__openerp__.py
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
{
|
||||
"name": "Manual assignment of quants",
|
||||
"version": "1.0",
|
||||
"depends": ["base", "stock"],
|
||||
"author": "OdooMRP team",
|
||||
"contributors": ["Mikel Arregi <mikelarregi@avanzosc.es>"],
|
||||
"category": "quant",
|
||||
"description": """
|
||||
This module provide :
|
||||
With this module, user can change manualy the automatic selection of quants
|
||||
""",
|
||||
'data': ['wizard/assign_manual_quants_view.xml',
|
||||
'views/stock_move_view.xml'],
|
||||
"installable": True,
|
||||
"auto_install": False,
|
||||
}
|
||||
16
stock_quant_manual_assign/views/stock_move_view.xml
Normal file
16
stock_quant_manual_assign/views/stock_move_view.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="stock_move_manual_quants_form_view">
|
||||
<field name="name">stock.move.form</field>
|
||||
<field name="model">stock.move</field>
|
||||
<field name="inherit_id" ref="stock.view_move_form" />
|
||||
<field name="arch" type="xml">
|
||||
<button name="force_assign" position="after">
|
||||
<button name="%(assign_manual_quants_action)d" states="assigned" string="Manual Quants" type="action" class="oe_highlight"/>
|
||||
</button>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
20
stock_quant_manual_assign/wizard/__init__.py
Normal file
20
stock_quant_manual_assign/wizard/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from . import assign_manual_quants
|
||||
86
stock_quant_manual_assign/wizard/assign_manual_quants.py
Normal file
86
stock_quant_manual_assign/wizard/assign_manual_quants.py
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import fields, models, api, exceptions, _
|
||||
|
||||
|
||||
class AssignManualQuants(models.TransientModel):
|
||||
_name = 'assign.manual.quants'
|
||||
_rec_name = 'quants_lines'
|
||||
|
||||
@api.one
|
||||
@api.constrains('quants_lines')
|
||||
def check_qty(self):
|
||||
total_qty = 0
|
||||
for line in self.quants_lines:
|
||||
if line.selected:
|
||||
total_qty += line.qty
|
||||
move = self.env['stock.move'].browse(self.env.context['active_id'])
|
||||
if total_qty > move.product_uom_qty:
|
||||
raise exceptions.Warning(_('Error'), _('Quantity is excessive'))
|
||||
|
||||
quants_lines = fields.One2many('assign.manual.quants.lines',
|
||||
'assign_wizard', string='Quants')
|
||||
|
||||
@api.multi
|
||||
@api.model
|
||||
def assign_quants(self):
|
||||
move = self.env['stock.move'].browse(self.env.context['active_id'])
|
||||
quants = []
|
||||
for quant_id in move.reserved_quant_ids.ids:
|
||||
move.write({'reserved_quant_ids': [[3, quant_id]]})
|
||||
for line in self.quants_lines:
|
||||
if line.selected:
|
||||
quants.append([line.quant, line.qty])
|
||||
self.pool['stock.quant'].quants_reserve(
|
||||
self.env.cr, self.env.uid, quants, move, context=self.env.context)
|
||||
return {}
|
||||
|
||||
def default_get(self, cr, uid, var_fields, context=None):
|
||||
move = self.pool['stock.move'].browse(
|
||||
cr, uid, context['active_id'], context=context)
|
||||
available_quants_ids = self.pool['stock.quant'].search(
|
||||
cr, uid, [
|
||||
'|', ('location_id', '=', move.location_id.id),
|
||||
('location_id', 'in', move.location_id.child_ids.ids),
|
||||
('product_id', '=', move.product_id.id),
|
||||
('qty', '>', 0),
|
||||
('reservation_id', '=', False)], context=context)
|
||||
available_quants = [{'quant': x} for x in available_quants_ids]
|
||||
available_quants.extend(
|
||||
{'quant': x.id,
|
||||
'selected': True,
|
||||
'qty': x.qty
|
||||
} for x in move.reserved_quant_ids)
|
||||
return {'quants_lines': available_quants}
|
||||
|
||||
|
||||
class AssignManualQuantsLines(models.TransientModel):
|
||||
_name = 'assign.manual.quants.lines'
|
||||
_rec_name = 'quant'
|
||||
|
||||
@api.onchange('selected')
|
||||
def onchange_selected(self):
|
||||
if not self.selected:
|
||||
self.qty = False
|
||||
|
||||
assign_wizard = fields.Many2one('assign.manual.quants', string='Move')
|
||||
quant = fields.Many2one('stock.quant', string="Quant")
|
||||
qty = fields.Float(string='QTY')
|
||||
selected = fields.Boolean(string="Select")
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="assign_manual_quants_form_view">
|
||||
<field name="name">assign.manual.quants.form</field>
|
||||
<field name="model">assign.manual.quants</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Manual Quants">
|
||||
<group col='4' colspan="4">
|
||||
<field name='quants_lines' colspan="4">
|
||||
<tree editable="top" delete="0" create="0">
|
||||
<field name="quant" />
|
||||
<field name="selected" />
|
||||
<field name="qty"/>
|
||||
</tree>
|
||||
<form>
|
||||
<field name="quant" />
|
||||
<field name="selected" />
|
||||
<field name="qty"/>
|
||||
</form>
|
||||
</field>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="assign_quants" type="object"
|
||||
string="Confirm" class="oe_highlight" />
|
||||
or
|
||||
<button string="Cancel" class="oe_link"
|
||||
special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<act_window name="Manual quants" res_model="assign.manual.quants"
|
||||
src_model="stock.move" view_mode="form" target="new"
|
||||
key2="client_action_multi" id="assign_manual_quants_action" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
Reference in New Issue
Block a user