<s> from __future__ import unicode_literals <EOL> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> from djangobmf . conf import settings <EOL> from djangobmf . models import BMFModel <EOL> from djangobmf . fields import CurrencyField <EOL> from djangobmf . fields import MoneyField <EOL> from . serializers import PositionSerializer <EOL> RATE_CHOICES = ( <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:4> , '<STR_LIT>' ) , <EOL> ) <EOL> class PositionManager ( models . Manager ) : <EOL> def get_queryset ( self , * args , ** kwargs ) : <EOL> return super ( PositionManager , self ) . get_queryset ( * args , ** kwargs ) . select_related ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ python_2_unicode_compatible <EOL> class AbstractPosition ( BMFModel ) : <EOL> """<STR_LIT:U+0020>""" <EOL> project = models . ForeignKey ( <EOL> settings . CONTRIB_PROJECT , null = True , blank = False , <EOL> related_name = "<STR_LIT:+>" , on_delete = models . SET_NULL , <EOL> ) <EOL> employee = models . ForeignKey ( <EOL> settings . CONTRIB_EMPLOYEE , null = True , blank = False , on_delete = models . SET_NULL , <EOL> ) <EOL> date = models . DateField ( _ ( "<STR_LIT>" ) , null = True , blank = False ) <EOL> name = models . CharField ( _ ( "<STR_LIT:Name>" ) , max_length = <NUM_LIT:255> , null = True , blank = False ) <EOL> invoice = models . ForeignKey ( <EOL> settings . CONTRIB_INVOICE , null = True , blank = True , related_name = "<STR_LIT:+>" , <EOL> editable = False , on_delete = models . PROTECT , <EOL> ) <EOL> product = models . ForeignKey ( <EOL> settings . CONTRIB_PRODUCT , null = True , blank = False , on_delete = models . PROTECT , <EOL> ) <EOL> invoiceable = models . PositiveSmallIntegerField ( <EOL> _ ( "<STR_LIT>" ) , null = True , blank = False , default = <NUM_LIT:1> , choices = RATE_CHOICES , editable = False , <EOL> ) <EOL> price_currency = CurrencyField ( ) <EOL> price_precision = models . PositiveSmallIntegerField ( default = <NUM_LIT:0> , blank = True , null = True , editable = False ) <EOL> price = MoneyField ( _ ( "<STR_LIT>" ) , blank = False ) <EOL> amount = models . FloatField ( _ ( "<STR_LIT>" ) , null = True , blank = False , default = <NUM_LIT:1.0> ) <EOL> description = models . TextField ( _ ( "<STR_LIT>" ) , null = True , blank = True ) <EOL> objects = PositionManager ( ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT:%s>' % ( self . name ) <EOL> def has_invoice ( self ) : <EOL> return bool ( self . invoice ) <EOL> def bmfget_customer ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return self . project . customer <EOL> else : <EOL> return None <EOL> def bmfget_project ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return self . project <EOL> else : <EOL> return None <EOL> def clean ( self ) : <EOL> if self . product and not self . name : <EOL> self . name = self . product . name <EOL> if self . product and not self . price : <EOL> self . price = self . product . price <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> abstract = True <EOL> swappable = "<STR_LIT>" <EOL> class BMFMeta : <EOL> has_logging = False <EOL> serializer = PositionSerializer <EOL> class Position ( AbstractPosition ) : <EOL> pass </s>
