Changed the way the sale of a ShipmentOut is computed: The sale of the first stock move with a sale line found

This commit is contained in:
Jordi Esteve 2013-11-30 17:46:10 +01:00
parent b3c2adada6
commit 955357b153
14 changed files with 13 additions and 31 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

0
MANIFEST.in Executable file → Normal file
View file

0
README Executable file → Normal file
View file

0
TODO Executable file → Normal file
View file

1
__init__.py Executable file → Normal file
View file

@ -8,6 +8,5 @@ from .sale import *
def register():
Pool.register(
Sale,
ShipmentOut,
module='stock_origin_sale', type_='model')

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

29
sale.py
View file

@ -1,29 +0,0 @@
#This file is part stock_origin_purchase module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.pool import Pool, PoolMeta
__all__ = ['Sale']
__metaclass__ = PoolMeta
class Sale:
__name__ = 'sale.sale'
def create_shipment(self, shipment_type):
shipments = super(Sale, self).create_shipment(shipment_type)
if shipment_type == 'out':
Shipment = Pool().get('stock.shipment.out')
elif shipment_type == 'return':
Shipment = Pool().get('stock.shipment.out.return')
else:
return None
if shipments:
for shipment in shipments:
values = {
'origin': 'sale.sale,%s' % (self.id),
}
Shipment.write([shipment], values)
return shipments

0
setup.py Executable file → Normal file
View file

14
shipment.py Executable file → Normal file
View file

@ -1,7 +1,8 @@
#This file is part stock_origin_sale module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.pool import PoolMeta
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
__all__ = ['ShipmentOut']
__metaclass__ = PoolMeta
@ -10,6 +11,17 @@ __metaclass__ = PoolMeta
class ShipmentOut:
__name__ = 'stock.shipment.out'
@classmethod
def get_origin_value(cls, shipments, name):
SaleLine = Pool().get('sale.line')
origin = super(ShipmentOut, cls).get_origin_value(shipments, name)
for shipment in shipments:
for m in shipment.outgoing_moves:
if m.origin and isinstance(m.origin, SaleLine):
origin[shipment.id] = 'sale.sale,%s' % (m.origin.sale.id)
break
return origin
@classmethod
def _get_origin(cls):
return super(ShipmentOut, cls)._get_origin() + ['sale.sale']

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

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