mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[mod] new_api
This commit is contained in:
@@ -22,7 +22,10 @@
|
||||
"version": "1.0",
|
||||
"depends": ["base", "stock"],
|
||||
"author": "OdooMRP team",
|
||||
"contributors": ["Mikel Arregi <mikelarregi@avanzosc.es>"],
|
||||
"contributors": [
|
||||
"Ana Juaristi Olalde <ajuaristio@gmail.com>",
|
||||
"Pedro Manuel Baeza Romero <pedro.baeza@gmail.com>"
|
||||
"Mikel Arregi <mikelarregi@avanzosc.es>"],
|
||||
"category": "quant",
|
||||
'data': ['wizard/assign_manual_quants_view.xml',
|
||||
'views/stock_move_view.xml'],
|
||||
|
||||
@@ -6,11 +6,21 @@
|
||||
<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 name="action_done" position="after">
|
||||
<button name="%(assign_manual_quants_action)d" states="confirmed,assigned" string="Manual Quants" type="action" class="oe_highlight"/>
|
||||
</button>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="stock_move_manual_quants_picking_form_view">
|
||||
<field name="name">stock.move.form</field>
|
||||
<field name="model">stock.move</field>
|
||||
<field name="inherit_id" ref="stock.view_move_picking_form" />
|
||||
<field name="arch" type="xml">
|
||||
<button name="force_assign" position="after">
|
||||
<button name="%(assign_manual_quants_action)d" states="confirmed,assigned" string="Manual Quants" type="action" class="oe_highlight"/>
|
||||
</button>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -23,20 +23,30 @@ from openerp import fields, models, api, exceptions, _
|
||||
class AssignManualQuants(models.TransientModel):
|
||||
_name = 'assign.manual.quants'
|
||||
|
||||
@api.one
|
||||
@api.constrains('quants_lines')
|
||||
def check_qty(self):
|
||||
def lines_qty(self):
|
||||
total_qty = 0
|
||||
for line in self.quants_lines:
|
||||
if line.selected:
|
||||
total_qty += line.qty
|
||||
return total_qty
|
||||
|
||||
@api.one
|
||||
@api.constrains('quants_lines')
|
||||
def check_qty(self):
|
||||
total_qty = self.lines_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 higher'
|
||||
' than the needed one'))
|
||||
|
||||
@api.depends('quants_lines')
|
||||
def get_move_qty(self):
|
||||
move = self.env['stock.move'].browse(self.env.context['active_id'])
|
||||
self.move_qty = move.product_uom_qty - self.lines_qty()
|
||||
|
||||
name = fields.Char(string='Name')
|
||||
move_qty = fields.Float(string="Remaining qty", compute="get_move_qty")
|
||||
quants_lines = fields.One2many('assign.manual.quants.lines',
|
||||
'assign_wizard', string='Quants')
|
||||
|
||||
@@ -53,17 +63,16 @@ class AssignManualQuants(models.TransientModel):
|
||||
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]
|
||||
@api.model
|
||||
def default_get(self, var_fields):
|
||||
move = self.env['stock.move'].browse(self.env.context['active_id'])
|
||||
available_quants_ids = self.env['stock.quant'].search(
|
||||
['|', ('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)])
|
||||
available_quants = [{'quant': x.id} for x in available_quants_ids]
|
||||
available_quants.extend(
|
||||
{'quant': x.id,
|
||||
'selected': True,
|
||||
@@ -80,6 +89,8 @@ class AssignManualQuantsLines(models.TransientModel):
|
||||
def onchange_selected(self):
|
||||
if not self.selected:
|
||||
self.qty = False
|
||||
if self.selected and self.qty == 0:
|
||||
self.qty = self.quant.qty
|
||||
|
||||
assign_wizard = fields.Many2one('assign.manual.quants', string='Move',
|
||||
required=True)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<tree editable="top" delete="0" create="0">
|
||||
<field name="quant" />
|
||||
<field name="selected" />
|
||||
<field name="qty" attrs="{'readonly':[('selected', '=' ,False)]}"/>
|
||||
<field name="qty" attrs="{'readonly':[('selected', '=' ,False)]}" sum="qty"/>
|
||||
</tree>
|
||||
<form>
|
||||
<field name="quant" />
|
||||
@@ -19,6 +19,7 @@
|
||||
<field name="qty"/>
|
||||
</form>
|
||||
</field>
|
||||
<field name="move_qty" colspan="2" readonly="1"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="assign_quants" type="object"
|
||||
@@ -33,8 +34,6 @@
|
||||
|
||||
<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" />
|
||||
|
||||
id="assign_manual_quants_action" />
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user