Added origin for ShipmentOutReturn. Changed origin field to function field for ShipmentOut

This commit is contained in:
Jordi Esteve 2013-11-30 17:43:42 +01:00
parent 8546170b65
commit d3f400c2f7
20 changed files with 126 additions and 14 deletions

0
CHANGELOG Executable file → Normal file
View file

0
COPYRIGHT Executable file → Normal file
View file

0
INSTALL Executable file → Normal file
View file

0
LICENSE Executable file → Normal file
View file

1
MANIFEST.in Executable file → Normal file
View file

@ -8,3 +8,4 @@ include tryton.cfg
include *.xml
include locale/*.po
include doc/*
include view/*

0
README Executable file → Normal file
View file

0
TODO Executable file → Normal file
View file

4
__init__.py Executable file → Normal file
View file

@ -7,4 +7,8 @@ from .shipment import *
def register():
Pool.register(
ShipmentOut,
ShipmentOutReturn,
module='stock_origin', type_='model')
Pool.register(
CreateShipmentOutReturn,
module='stock', type_='wizard')

0
doc/index.rst Executable file → Normal file
View file

4
locale/ca_ES.po Executable file → Normal file
View file

@ -5,3 +5,7 @@ msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:stock.shipment.out,origin:"
msgid "Origin"
msgstr "Origen"
msgctxt "field:stock.shipment.out.return,origin:"
msgid "Origin"
msgstr "Origen"

4
locale/es_ES.po Executable file → Normal file
View file

@ -5,3 +5,7 @@ msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:stock.shipment.out,origin:"
msgid "Origin"
msgstr "Origen"
msgctxt "field:stock.shipment.out.return,origin:"
msgid "Origin"
msgstr "Origen"

0
setup.py Executable file → Normal file
View file

60
shipment.py Executable file → Normal file
View file

@ -4,14 +4,24 @@
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
from trytond.rpc import RPC
__all__ = ['ShipmentOut']
__all__ = ['ShipmentOut', 'ShipmentOutReturn', 'CreateShipmentOutReturn']
__metaclass__ = PoolMeta
class ShipmentOut:
__name__ = 'stock.shipment.out'
origin = fields.Reference('Origin', selection='get_origin')
origin = fields.Function(fields.Reference('Origin', selection='get_origin'),
'get_origin_value')
@classmethod
def __setup__(cls):
super(ShipmentOut, cls).__setup__()
cls.__rpc__.update({
'get_origin': RPC(),
})
@classmethod
def _get_origin(cls):
@ -26,3 +36,49 @@ class ShipmentOut:
('model', 'in', models),
])
return [('', '')] + [(m.model, m.name) for m in models]
@classmethod
def get_origin_value(cls, shipments, name):
origin = {}
for shipment in shipments:
origin[shipment.id] = None
return origin
class ShipmentOutReturn:
__name__ = 'stock.shipment.out.return'
origin = fields.Reference('Origin', selection='get_origin')
@classmethod
def _get_origin(cls):
'Return list of Model names for origin Reference'
return ['stock.shipment.out']
@classmethod
def get_origin(cls):
Model = Pool().get('ir.model')
models = cls._get_origin()
models = Model.search([
('model', 'in', models),
])
return [('', '')] + [(m.model, m.name) for m in models]
class CreateShipmentOutReturn:
__name__ = 'stock.shipment.out.return.create'
def do_start(self, action):
pool = Pool()
ShipmentOut = pool.get('stock.shipment.out')
ShipmentOutReturn = pool.get('stock.shipment.out.return')
action, data = super(CreateShipmentOutReturn, self).do_start(action)
shipment_ids = Transaction().context['active_ids']
shipment_outs = ShipmentOut.browse(shipment_ids)
shipment_out_returns = ShipmentOutReturn.browse(data['res_id'])
for shipment_out, shipment_out_return in \
zip(shipment_outs, shipment_out_returns):
shipment_out_return.origin = shipment_out
shipment_out_return.save()
return action, data

29
shipment.xml Executable file → Normal file
View file

@ -6,18 +6,23 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<record model="ir.ui.view" id="shipment_out_view_form">
<field name="model">stock.shipment.out</field>
<field name="inherit" ref="stock.shipment_out_view_form"/>
<field name="arch" type="xml">
<![CDATA[
<data>
<xpath
expr="/form/field[@name=&quot;warehouse&quot;]"
position="after">
<label name="origin"/>
<field name="origin"/>
</xpath>
</data>
]]>
</field>
<field name="name">shipment_out_form</field>
</record>
<record model="ir.ui.view" id="shipment_out_view_tree">
<field name="model">stock.shipment.out</field>
<field name="inherit" ref="stock.shipment_out_view_tree"/>
<field name="name">shipment_out_tree</field>
</record>
<record model="ir.ui.view" id="shipment_out_return_view_form">
<field name="model">stock.shipment.out.return</field>
<field name="inherit" ref="stock.shipment_out_return_view_form"/>
<field name="name">shipment_out_return_form</field>
</record>
<record model="ir.ui.view" id="shipment_out_return_view_tree">
<field name="model">stock.shipment.out.return</field>
<field name="inherit" ref="stock.shipment_out_return_view_tree"/>
<field name="name">shipment_out_return_tree</field>
</record>
</data>
</tryton>

0
tests/__init__.py Executable file → Normal file
View file

0
tests/test_stock_origin.py Executable file → Normal file
View file

View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath
expr="/form/field[@name=&quot;warehouse&quot;]" position="after">
<label name="origin"/>
<field name="origin"/>
</xpath>
</data>

View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath
expr="/form/field[@name=&quot;warehouse&quot;]" position="after">
<label name="origin"/>
<field name="origin"/>
</xpath>
</data>

View file

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath
expr="/tree/field[@name=&quot;delivery_address&quot;]" position="after">
<field name="origin"/>
</xpath>
</data>

View file

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath
expr="/tree/field[@name=&quot;state&quot;]" position="after">
<field name="origin"/>
</xpath>
</data>