<s> from __future__ import unicode_literals <EOL> from django . db . models import Sum <EOL> from django . utils . functional import cached_property <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django_fsm import transition <EOL> from shop . models . delivery import DeliveryModel <EOL> class PartialDeliveryWorkflowMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> TRANSITION_TARGETS = { <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" ) , <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" ) , <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" ) , <EOL> } <EOL> @ cached_property <EOL> def unfulfilled_items ( self ) : <EOL> unfulfilled_items = <NUM_LIT:0> <EOL> for order_item in self . items . all ( ) : <EOL> if not order_item . canceled : <EOL> aggr = order_item . deliveryitem_set . aggregate ( delivered = Sum ( '<STR_LIT>' ) ) <EOL> unfulfilled_items += order_item . quantity - ( aggr [ '<STR_LIT>' ] or <NUM_LIT:0> ) <EOL> return unfulfilled_items <EOL> def ready_for_delivery ( self ) : <EOL> return self . is_fully_paid ( ) and self . unfulfilled_items > <NUM_LIT:0> <EOL> @ transition ( field = '<STR_LIT:status>' , source = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> target = '<STR_LIT>' , conditions = [ ready_for_delivery ] , <EOL> custom = dict ( admin = True , button_name = _ ( "<STR_LIT>" ) ) ) <EOL> def pick_goods ( self , by = None ) : <EOL> """<STR_LIT>""" <EOL> shipping_method = self . extra . get ( '<STR_LIT>' ) <EOL> if shipping_method : <EOL> DeliveryModel . objects . get_or_create ( order = self , shipping_method = shipping_method , fulfilled_at = None ) <EOL> @ transition ( field = '<STR_LIT:status>' , source = [ '<STR_LIT>' ] , target = '<STR_LIT>' , <EOL> custom = dict ( admin = True , button_name = _ ( "<STR_LIT>" ) ) ) <EOL> def pack_goods ( self , by = None ) : <EOL> """<STR_LIT>""" <EOL> self . _transition_to_pack_goods = True <EOL> @ transition ( field = '<STR_LIT:status>' , source = [ '<STR_LIT>' ] , target = '<STR_LIT>' , <EOL> custom = dict ( admin = True , button_name = _ ( "<STR_LIT>" ) ) ) <EOL> def ship_goods ( self , by = None ) : <EOL> """<STR_LIT>""" </s>
