Skip to content

Commit

Permalink
[IMP][product_unique_serial] deprecated module stock_serial_wizard an…
Browse files Browse the repository at this point in the history
…d added fields to handle create/exsiting lots from pickgin type
  • Loading branch information
JulioSerna committed Nov 23, 2015
1 parent 1730285 commit 211268d
Show file tree
Hide file tree
Showing 22 changed files with 261 additions and 395 deletions.
11 changes: 10 additions & 1 deletion product_unique_serial/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ Features
- Add a field to product to activate check if is a product unique serial number.
- Add a constraint to deny stock quants with quantity different to 1 if product as unique serial number as True.
- Add a constraint to deny stock quants with quantity different to 1 when serial number that exists in another location
- Add a field to lot to set domain to show only serial number that exists in source location
- Add a field to lot to set domain to show only serial number that exists in source location
- Add a wizard in lines of picking to capture faster the serial number

You can find the wizard here

.. image:: product_unique_serial/static/src/img/wizard.png
:width: 300pt

.. image:: product_unique_serial/static/src/img/wizard_move.png
:width: 300pt
1 change: 1 addition & 0 deletions product_unique_serial/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'data': [
"views/product_view.xml",
"views/stock_view.xml",
"views/stock_serial_view.xml"
],
'demo': [
"demo/test_demo.xml",
Expand Down
28 changes: 20 additions & 8 deletions product_unique_serial/demo/test_demo.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">

<!-- Products -->

<record id="product_demo_1" model="product.product">
<field name="name">Huawei Ascend</field>
<field name="track_all" eval="True"/>
Expand All @@ -13,7 +13,7 @@
<field name="standard_price">75.50</field>
<field name="list_price">82.25</field>
</record>

<record id="product_demo_2" model="product.product">
<field name="name">Nokia 2630</field>
<field name="track_all" eval="True"/>
Expand All @@ -23,27 +23,39 @@
<field name="standard_price">35.50</field>
<field name="list_price">42.28</field>
</record>

<!-- Sales Orders -->

<record id="serial_number_demo_1" model="stock.production.lot">
<field name="name">86137801852514</field>
<field name="product_id" ref="product_demo_1"/>
</record>

<record id="serial_number_demo_2" model="stock.production.lot">
<field name="name">86137801852515</field>
<field name="product_id" ref="product_demo_1"/>
</record>

<record id="serial_number_demo_3" model="stock.production.lot">
<field name="name">86137801852516</field>
<field name="product_id" ref="product_demo_1"/>
</record>

<record id="serial_number_demo_4" model="stock.production.lot">
<field name="name">86137801852517</field>
<field name="product_id" ref="product_demo_1"/>
</record>

<!-- Stock Picking Type -->
<record id="stock.picking_type_in" model="stock.picking.type">
<field name="use_create_lots" eval="True"/>
</record>
<record id="stock.picking_type_out" model="stock.picking.type">
<field name="use_existing_lots" eval="True"/>
</record>
<record id="stock.picking_type_internal" model="stock.picking.type">
<field name="use_existing_lots" eval="True"/>
</record>

</data>
</openerp>
132 changes: 132 additions & 0 deletions product_unique_serial/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,135 @@ msgstr "No se puede activar 'Trazabilidad completa de lotes' o 'Lote unico' en e
msgid "You should only receive by the piece with the same serial number"
msgstr "Solo se puede recibir una pieza con el mismo número de serie"

#. module: product_unique_serial
#: view:stock.serial:product_unique_serial.view_stock_serial
msgid "Add Serial"
msgstr "Agrega Serial"

#. module: product_unique_serial
#: view:stock.serial:product_unique_serial.view_stock_serial
msgid "Cancel"
msgstr "Cancelar"

#. module: product_unique_serial
#: field:stock.serial,create_uid:0
#: field:stock.serial.line,create_uid:0
msgid "Created by"
msgstr ""

#. module: product_unique_serial
#: field:stock.serial,create_date:0
#: field:stock.serial.line,create_date:0
msgid "Created on"
msgstr ""

#. module: product_unique_serial
#: field:stock.serial,id:0
#: field:stock.serial.line,id:0
msgid "ID"
msgstr ""

#. module: product_unique_serial
#: field:stock.serial,write_uid:0
#: field:stock.serial.line,write_uid:0
msgid "Last Updated by"
msgstr ""

#. module: product_unique_serial
#: field:stock.serial,write_date:0
#: field:stock.serial.line,write_date:0
msgid "Last Updated on"
msgstr ""

#. module: product_unique_serial
#: field:stock.serial.line,lot_id:0
msgid "Lot/Serial Number"
msgstr "Numero Serial"

#. module: product_unique_serial
#: field:stock.serial,move_id:0
msgid "Move"
msgstr "Movimiento"

#. module: product_unique_serial
#: field:stock.serial,product_id:0
msgid "Product"
msgstr "Producto"

#. module: product_unique_serial
#: field:stock.serial,product_qty:0
msgid "Qty"
msgstr "Cantidad"

#. module: product_unique_serial
#: view:stock.serial:product_unique_serial.view_stock_serial
#: field:stock.serial.line,serial:0
#: field:stock.serial.line,serial_id:0
msgid "Serial"
msgstr "Serial"

#. module: product_unique_serial
#: view:stock.move:product_unique_serial.view_move_serial
#: view:stock.serial:product_unique_serial.view_stock_serial
msgid "Serial Products"
msgstr "Serial de Productos"

#. module: product_unique_serial
#: code:addons/product_unique_serial/wizard/stock_serial.py:193
#, python-format
msgid "Serial {} not found"
msgstr "Numero de Serial {} No Encontrado"

#. module: product_unique_serial
#: field:stock.serial,serial_ids:0
msgid "Serials"
msgstr "Seriales"

#. module: product_unique_serial
#: model:ir.actions.act_window,name:product_unique_serial.move_serial
msgid "Stock Serial"
msgstr "Stock Serial"

#. module: product_unique_serial
#: view:stock.serial:product_unique_serial.view_stock_serial
msgid "of"
msgstr "De"

#. module: product_unique_serial
#: view:stock.serial:product_unique_serial.view_stock_serial
msgid "or"
msgstr ""

#. module: product_unique_serial
#: code:addons/product_unique_serial/wizard/stock_serial.py:91
#, python-format
msgid "The Serial number {} already captured"
msgstr "El numero serial {} ya fue capturado"

#. module: product_unique_serial
#: help:stock.picking.type,use_create_lots:0
msgid "If this is checked only, it will suppose you want to create new Serial Numbers / Lots, so you can provide them in a text field. "
msgstr "SI este campo es seleccionado, supondrá que quieres crear nuevos números de serie, entonces tu puedes proporcionarlos en un campo de texto"

#. module: product_unique_serial
#: help:stock.picking.type,use_existing_lots:0
msgid "If this is checked, you will be able to choose the Serial Number / Lots. "
msgstr "SI este campo esta seleccionado, tu podrás seleccionar el numero de serie"

#. module: product_unique_serial
#: field:stock.picking.type,use_create_lots:0
msgid "Create New Lots"
msgstr "Crear nuevo serial"

#. module: product_unique_serial
#: field:stock.picking.type,use_existing_lots:0
msgid "Use Existing Lots"
msgstr "Usar serial existente"

#. module: product_unique_serial
#: code:addons/product_unique_serial/wizard/stock_serial.py:185
#, python-format
msgid "The serial number {} is already in stock"
msgstr "El numero serial {} ya esta en almacén"


31 changes: 31 additions & 0 deletions product_unique_serial/model/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,34 @@ def _ckeck_qty_line(self):
'The product %s has active "Full Lots Traceability", you '
'must assign the serial number to update the quantity.'
% line.product_id.name))


class StockMove(models.Model):

_inherit = 'stock.move'

@api.multi
def move_lot_unique(self):
for move in self:
pick_type = move.picking_id.picking_type_id
if move.product_id.lot_unique_ok and move.state in (
'draft', 'waiting', 'confirmed', 'assigned') and\
(pick_type.use_create_lots or pick_type.use_existing_lots):
move.lot_unique = True

lot_unique = fields.Boolean('Is lot unique?', compute='move_lot_unique')


class StockPickingType(models.Model):

_inherit = 'stock.picking.type'

use_existing_lots = fields.Boolean(
'Use Existing Lots',
help='If this is checked, '
'you will be able to choose the Serial Number / Lots. ')
use_create_lots = fields.Boolean(
'Create New Lots',
help='If this is checked only, '
'it will suppose you want to create new Serial Numbers / Lots, '
'so you can provide them in a text field. ')
1 change: 1 addition & 0 deletions product_unique_serial/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_for_unicity
from . import test_serial_wizard
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def setUp(self):
'product_unique_serial.product_demo_1')

def test_serial_wizard_incoming_outgoing(self):
'This test validate the capture of number serial for move'\
'of type incoming and to use number serial in'\
'This test validate the capture of number serial for move '\
'of type incoming and to use number serial in '\
'picking type of outgoing'

picking_val = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@
<field name="context">{'form_view_ref': False}</field>
</record>

<record id="view_picking_type_serial" model="ir.ui.view">
<field name="name">view.picking.type.serial</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.view_picking_type_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='default_location_dest_id']" position="after">
<group string="Lots">
<field name="use_existing_lots" groups="stock.group_production_lot"/>
<field name="use_create_lots" groups="stock.group_production_lot"/>
</group>
</xpath>
</field>
</record>

<record id="view_move_serial" model="ir.ui.view">
<field name="name">view.move.serial</field>
<field name="model">stock.move</field>
Expand Down
1 change: 1 addition & 0 deletions product_unique_serial/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from . import stock_transfer_details
from . import stock_change_product_qty
from . import stock_serial
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ def default_get(self, field_list):
product_qty_done = fields.Float(
'Qty Done', compute='_qty_done', store=False)

@api.onchange('serial_ids')
def onchange_serial(self):
serial = []

for serial_name in self.serial_ids:
if serial_name.serial in serial:
return {
'warning': {
'title': _('Warning'),
'message': _(
'The Serial number {} already captured'.format(
serial_name.serial.encode('utf-8')))
}}
else:
serial.append(serial_name.serial)

@api.multi
def move_serial(self):
quant_obj = self.env['stock.quant']
Expand All @@ -88,12 +104,17 @@ def move_serial(self):
move_id.picking_id.pack_operation_ids.filtered(
lambda dat: dat.product_id.id == product_id).unlink()

if move_id.picking_type_id.code != 'incoming':
if move_id.picking_type_id.use_existing_lots:
move_id.do_unreserve()

for move_serial in move.serial_ids:

if move_id.picking_type_id.code == 'incoming':
# This validation by picking type code and
# picking type create/existing lots is necessary because
# the lot can be used again if are not present in someone
# location of type internal and not need to be created
if move_id.picking_type_id.use_create_lots or (
move_id.picking_type_id.use_existing_lots and
move_id.picking_id.picking_type_id.code == 'incoming'):
self._get_pack_ops_lot(move, move_serial)
else:
quants = quant_obj.quants_get_prefered_domain(
Expand Down Expand Up @@ -144,18 +165,38 @@ def onchange_lot_id(self):
move_obj = self.env['stock.move']
move = self._context.get('move_id', [])
move_id = move_obj.browse(move)
prod_lot_obj = self.env['stock.production.lot']
quant_obj = self.env['stock.quant']

if move_id.picking_type_id.code == 'incoming':
if move_id.picking_type_id.use_create_lots:
return {}
if self.serial:
lot_id = self.env['stock.production.lot'].search(
serial_number = self.serial.encode('utf-8')
lot_id = prod_lot_obj.search(
[('name', '=', self.serial),
('product_id', '=', move_id.product_id.id)], limit=1)

if lot_id and\
move_id.picking_id.picking_type_id.code == 'incoming':
other_quants = quant_obj.search(
[('product_id', '=', move_id.product_id.id),
('lot_id', '=', lot_id.id),
('qty', '>', 0.0),
('location_id.usage', '=', 'internal')])
if other_quants:
message = _(
'The serial number {} is already in stock'.format(
serial_number))
return {
'warning': {
'title': _('Warning'),
'message': message
}}
if not lot_id:
message = _('Serial {} not found'.format(serial_number))
return {
'warning': {
'title': _('Warning'),
'message': _('Serial {} not found'.format(
self.serial.encode('utf-8')))}
}
'message': message
}}
self.lot_id = lot_id
Loading

0 comments on commit 211268d

Please sign in to comment.