Allow to decide if we create serial numbers or not

This commit is contained in:
Sergi Almacellas Abellana 2016-03-03 12:49:36 +01:00
parent f6ad9d3481
commit 98c9a77115
9 changed files with 120 additions and 1 deletions

View File

@ -7,6 +7,7 @@ from .production import *
def register():
Pool.register(
Production,
SplitProductionStart,
module='production_split_serial_number', type_='model')
Pool.register(
SplitProduction,

11
locale/ca_ES.po Normal file
View File

@ -0,0 +1,11 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.split.start,create_serial_numbers:"
msgid "Create Serial Numbers?"
msgstr "Crear números de sèrie?"
msgctxt "field:production.split.start,serial_number_product:"
msgid "Serial Numbers Product"
msgstr "Producte amb números de sèrie"

11
locale/es_ES.po Normal file
View File

@ -0,0 +1,11 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:production.split.start,create_serial_numbers:"
msgid "Create Serial Numbers?"
msgstr "Crear números de serie?"
msgctxt "field:production.split.start,serial_number_product:"
msgid "Serial Numbers Product"
msgstr "Producto con número de serie"

View File

@ -1,9 +1,11 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
from trytond.transaction import Transaction
__all__ = ['Production', 'SplitProduction']
__all__ = ['Production', 'SplitProductionStart', 'SplitProduction']
__metaclass__ = PoolMeta
@ -17,6 +19,8 @@ class Production:
for output in self.outputs:
if not output.product.serial_number:
continue
if not Transaction().context.get('create_serial_numbers', True):
continue
if output.quantity != 1.0 or output.lot:
continue
if hasattr(output, 'get_production_output_lot'):
@ -30,6 +34,25 @@ class Production:
output.save()
class SplitProductionStart:
__name__ = 'production.split.start'
serial_number_product = fields.Boolean('Serial Numbers Product')
create_serial_numbers = fields.Boolean('Create Serial Numbers?',
states={
'invisible': ~Eval('serial_number_product', False),
},
depends=['serial_number_product'])
@staticmethod
def default_serial_number_product():
return False
@staticmethod
def default_create_serial_numbers():
return False
class SplitProduction:
'Split Production'
__name__ = 'production.split'
@ -41,4 +64,11 @@ class SplitProduction:
production = Production(Transaction().context['active_id'])
if production.product and production.product.serial_number:
default['quantity'] = 1.0
default['serial_number_product'] = True
default['create_serial_numbers'] = True
return default
def transition_split(self):
with Transaction().set_context(
create_serial_numbers=self.start.create_serial_numbers):
return super(SplitProduction, self).transition_split()

14
production.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="split_start_view_form">
<field name="model">production.split.start</field>
<field name="name">split_start_form</field>
<field name="inherit"
ref="production_split.split_start_view_form"/>
</record>
</data>
</tryton>

View File

@ -176,3 +176,23 @@ Make a production::
>>> product_sequence.reload()
>>> product_sequence.number_next
3
Split a production without creating serial numbers::
>>> Production = Model.get('production')
>>> production = Production()
>>> production.product = product
>>> production.bom = bom
>>> production.quantity = 4
>>> production.save()
>>> split_production = Wizard('production.split', [production])
>>> split_production.form.quantity
1.0
>>> split_production.form.count = 2
>>> split_production.form.create_serial_numbers = False
>>> split_production.execute('split')
>>> productions = Production.find([('code', 'like', '2-%')])
>>> len(productions)
3
>>> [o.lot for p in productions for o in p.outputs]
[None, None, None]

View File

@ -172,6 +172,8 @@ Make a production::
>>> split_production.form.quantity
1.0
>>> split_production.form.count = 2
>>> split_production.form.create_serial_numbers
True
>>> split_production.execute('split')
>>> productions = Production.find([])
>>> len(productions)
@ -185,3 +187,23 @@ Make a production::
>>> output_sequence.reload()
>>> output_sequence.number_next
3
Split a production without creating serial numbers::
>>> Production = Model.get('production')
>>> production = Production()
>>> production.product = product
>>> production.bom = bom
>>> production.quantity = 4
>>> production.save()
>>> split_production = Wizard('production.split', [production])
>>> split_production.form.quantity
1.0
>>> split_production.form.count = 2
>>> split_production.form.create_serial_numbers = False
>>> split_production.execute('split')
>>> productions = Production.find([('code', 'like', '2-%')])
>>> len(productions)
3
>>> [o.lot for p in productions for o in p.outputs]
[None, None, None]

View File

@ -7,3 +7,4 @@ depends:
extras_depend:
production_output_lot
xml:
production.xml

View File

@ -0,0 +1,9 @@
<?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" position="inside">
<label name="create_serial_numbers"/>
<field name="create_serial_numbers" colspan="5"/>
</xpath>
</data>