Implement carrier's purchase document creation.

This commit refs #526, #447
This commit is contained in:
Sergio Morillo 2015-11-03 17:15:48 +01:00
parent a5dd681902
commit a7a9b97cb8
4 changed files with 60 additions and 2 deletions

View File

@ -2,7 +2,7 @@
# copyright notices and license terms.
from trytond.pool import Pool
from .load import (LoadOrder, LoadOrderLine,
from .load import (Load, LoadOrder, LoadOrderLine,
LoadUnitLoad, LoadUnitLoadOrder,
LoadUnitLoadData, Configuration)
from .unit_load import UnitLoad
@ -12,6 +12,7 @@ def register():
Pool.register(
UnitLoad,
Configuration,
Load,
LoadOrder,
LoadOrderLine,
LoadUnitLoadOrder,

25
load.py
View File

@ -8,7 +8,7 @@ from trytond.wizard import Wizard, StateTransition, StateView, Button
__metaclass__ = PoolMeta
__all__ = ['Configuration', 'LoadOrder', 'LoadOrderLine',
__all__ = ['Configuration', 'Load', 'LoadOrder', 'LoadOrderLine',
'LoadUnitLoad', 'LoadUnitLoadOrder', 'LoadUnitLoadData']
@ -23,6 +23,23 @@ class Configuration:
return True
class Load:
__name__ = 'carrier.load'
unit_loads = fields.Function(
fields.One2Many('stock.unit_load', None, 'Unit loads'),
'get_unit_loads', searcher='search_unit_loads')
def get_unit_loads(self, name=None):
if not self.orders:
return []
return [ul.id for l in self.orders for ul in l.unit_loads if l.unit_loads]
@classmethod
def search_unit_loads(cls, name, clause):
return [('orders.unit_loads', ) + tuple(clause[1:])]
class LoadOrder:
__name__ = 'carrier.load.order'
@ -73,6 +90,12 @@ class LoadOrder:
def search_unit_loads(cls, name, clause):
return [('lines.unit_loads', ) + tuple(clause[1:])]
def get_carrier_amount(self, name=None):
if not self.load.unit_price:
return 0
return self.load.currency.round(
(len(self.unit_loads) / len(self.load.unit_loads)) * self.load.unit_price)
@classmethod
def cancel(cls, records):
if any(r.unit_loads for r in records):

View File

@ -64,6 +64,10 @@ msgctxt "help:carrier.configuration,ul_origin_restrict:"
msgid "Restricts origin of UL when loading in a Load order."
msgstr "Restringe el origen de la UdC al cargarse en una Orden de carga."
msgctxt "field:carrier.load,unit_loads:"
msgid "Unit loads"
msgstr "Unidades de carga"
msgctxt "field:carrier.load.order,unit_loads:"
msgid "Unit loads"
msgstr "Unidades de carga"

View File

@ -110,6 +110,11 @@ Create payment term::
Create carrier::
>>> carrier = create_carrier(config)
>>> carrier_product = carrier.carrier_product.template
>>> carrier_product.purchasable = True
>>> carrier_product.purchase_uom = carrier_product.default_uom
>>> carrier_product.account_expense = expense
>>> carrier_product.save()
Get warehouse and dock::
@ -358,3 +363,28 @@ Check sale::
u'Plastic Case 30x30'
>>> order.outgoing_moves[0].quantity
2.0
Close load::
>>> load.click('do')
>>> load.reload()
>>> load.state
u'done'
Create purchase::
>>> load.currency != None
True
>>> load.unit_price = Decimal(300.0)
>>> load.save()
>>> not load.purchase_state
True
>>> load.click('create_purchase')
>>> load.reload()
>>> load.purchase != None
True
>>> load.purchase_state
u'draft'
>>> order.reload()
>>> order.carrier_amount
Decimal('300.00')