configure product works with serial number, restriction quantity of stock move must be equal to 1, add tests and docs
This commit is contained in:
parent
6534e51e82
commit
7511ac6145
|
@ -7,6 +7,7 @@ from .stock import *
|
|||
|
||||
def register():
|
||||
Pool.register(
|
||||
Template,
|
||||
Move,
|
||||
SplitMoveStart,
|
||||
module='stock_serial_number', type_='model')
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#:before:product/product:paragraph:required_lot#
|
||||
|
||||
En el campo |serial_number| podemos marcar si el producto require un número de
|
||||
serie. En ese caso indicaremos el |serial_number| a travès del lote, i sólo se
|
||||
permitirá realizar movimientos con cantidad 1.0
|
||||
|
||||
.. |serial_number| field:: product.template/serial_number
|
|
@ -0,0 +1,13 @@
|
|||
#:inside:stock/stock:section:split_moves#
|
||||
|
||||
Si introducimos un número en el campo |start_lot| se crearan un lote para cada
|
||||
uno de las divisiones comenzando a partir del número introducido. Además,
|
||||
podemos utilizar el campo |end_lot| para límitar el último lote que se va
|
||||
a crear.
|
||||
|
||||
En el campo |lots| podemos especificar lotes ya existentes en el sistema y
|
||||
utilizar esos lotes para las divisiones.
|
||||
|
||||
.. |lots| field:: stock.move.split.start/lots
|
||||
.. |start_lot| field:: stock.move.split.start/start_lot
|
||||
.. |end_lot| field:: stock.move.split.start/end_lot
|
|
@ -2,6 +2,23 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "error:stock.move:"
|
||||
msgid ""
|
||||
"Move \"%(move)s\" can not be done as its product \"%(product)s\" is marked "
|
||||
"as serial number and its quantity is different than 1."
|
||||
msgstr ""
|
||||
"No es pot realitzar el moviment \"%(move)s\" perquè el seu producte "
|
||||
"\"%(product)s\" està marcat com a número de serie però la seva quantitat es "
|
||||
"diferent de 1."
|
||||
|
||||
msgctxt "error:stock.move:"
|
||||
msgid "No numbers found in string \"%s\"."
|
||||
msgstr "No s'ha trobat números al text \"%s\"."
|
||||
|
||||
msgctxt "field:product.template,serial_number:"
|
||||
msgid "Serial Number"
|
||||
msgstr "Número de série"
|
||||
|
||||
msgctxt "field:stock.move.split.start,end_lot:"
|
||||
msgid "End Lot"
|
||||
msgstr "Lot final"
|
||||
|
@ -17,3 +34,11 @@ msgstr "Producte"
|
|||
msgctxt "field:stock.move.split.start,start_lot:"
|
||||
msgid "Start Lot"
|
||||
msgstr "Lot inicial"
|
||||
|
||||
msgctxt "help:product.template,serial_number:"
|
||||
msgid ""
|
||||
"If marked it won't be allowed to move this product in quantities diferent "
|
||||
"than 1."
|
||||
msgstr ""
|
||||
"Si es marca no es podrà realitzar moviments d'aquest producte en quantitats "
|
||||
"diferents de 1."
|
||||
|
|
|
@ -2,6 +2,23 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "error:stock.move:"
|
||||
msgid ""
|
||||
"Move \"%(move)s\" can not be done as its product \"%(product)s\" is marked "
|
||||
"as serial number and its quantity is different than 1."
|
||||
msgstr ""
|
||||
"No se puede realizar el movimiento \"%(move)s\" porqué su producto "
|
||||
"\"%(product)s\" esta marcado cómo numero de serie pero su cantidad es "
|
||||
"distinta de 1."
|
||||
|
||||
msgctxt "error:stock.move:"
|
||||
msgid "No numbers found in string \"%s\"."
|
||||
msgstr "No se han encontrado números en el texto \"%s\"."
|
||||
|
||||
msgctxt "field:product.template,serial_number:"
|
||||
msgid "Serial Number"
|
||||
msgstr "Número de serie"
|
||||
|
||||
msgctxt "field:stock.move.split.start,end_lot:"
|
||||
msgid "End Lot"
|
||||
msgstr "Lote final"
|
||||
|
@ -17,3 +34,11 @@ msgstr "Producto"
|
|||
msgctxt "field:stock.move.split.start,start_lot:"
|
||||
msgid "Start Lot"
|
||||
msgstr "Lote inicial"
|
||||
|
||||
msgctxt "help:product.template,serial_number:"
|
||||
msgid ""
|
||||
"If marked it won't be allowed to move this product in quantities diferent "
|
||||
"than 1."
|
||||
msgstr ""
|
||||
"Si se marca no se podrá realizar movimientos de este producto en cantidades "
|
||||
"distintas de 1."
|
||||
|
|
26
stock.py
26
stock.py
|
@ -7,12 +7,23 @@ from trytond.pool import Pool, PoolMeta
|
|||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['Move', 'SplitMoveStart', 'SplitMove']
|
||||
__all__ = ['Template', 'Move', 'SplitMoveStart', 'SplitMove']
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
NUMBER_REGEXP = re.compile("(\d+)")
|
||||
|
||||
|
||||
class Template:
|
||||
__name__ = 'product.template'
|
||||
|
||||
serial_number = fields.Boolean('Serial Number',
|
||||
states={
|
||||
'invisible': ~Eval('type').in_(['goods', 'assets']),
|
||||
},
|
||||
depends=['type'], help='If marked it won\'t be allowed to move this '
|
||||
'product in quantities diferent than 1.')
|
||||
|
||||
|
||||
class Move:
|
||||
__name__ = 'stock.move'
|
||||
|
||||
|
@ -21,8 +32,21 @@ class Move:
|
|||
super(Move, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'no_numbers': ('No numbers found in string "%s".'),
|
||||
'serial_number': ('Move "%(move)s" can not be done as its product '
|
||||
'"%(product)s" is marked as serial number and its quantity'
|
||||
' is different than 1.'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def do(cls, moves):
|
||||
for move in moves:
|
||||
if move.product.serial_number and move.quantity != 1.0:
|
||||
cls.raise_user_error('serial_number', {
|
||||
'move': move.rec_name,
|
||||
'product': move.product.rec_name,
|
||||
})
|
||||
super(Move, cls).do(moves)
|
||||
|
||||
def get_lot_range(self, start_lot, end_lot):
|
||||
" Return a lot range from start_lot to end_lot"
|
||||
def search_number(string):
|
||||
|
|
|
@ -9,5 +9,10 @@
|
|||
<field name="name">split_start_form</field>
|
||||
<field name="inherit" ref="stock_split.split_start_view_form"/>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="template_view_form">
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit" ref="product.template_view_form"/>
|
||||
<field name="name">template_form</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -83,6 +83,7 @@ Create product::
|
|||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> template.cost_price = Decimal('8')
|
||||
>>> template.serial_number = True
|
||||
>>> template.save()
|
||||
>>> product.template = template
|
||||
>>> product.save()
|
||||
|
@ -143,3 +144,21 @@ Split the line into lots from 1 to 10::
|
|||
>>> len(lots)
|
||||
10
|
||||
|
||||
|
||||
We are not allowed to make a move of more than ::
|
||||
|
||||
>>> move = StockMove()
|
||||
>>> move.product = product
|
||||
>>> move.uom = unit
|
||||
>>> move.quantity = 10
|
||||
>>> move.from_location = output_loc
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.company = company
|
||||
>>> move.unit_price = Decimal('1')
|
||||
>>> move.currency = currency
|
||||
>>> move.click('do')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
UserError: ('UserError', (u'Move "10.0u Product" can not be done as its product "Product" is marked as serial number and its quantity is different than 1.', ''))
|
||||
>>> move.quantity = 1
|
||||
>>> move.click('do')
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='lots']/label[@name='lot_required']"
|
||||
position="before">
|
||||
<label name="serial_number"/>
|
||||
<field name="serial_number"/>
|
||||
<newline/>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in New Issue