<s> from __future__ import unicode_literals <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from djangobmf . workflow import Workflow , State , Transition <EOL> import datetime <EOL> class QuotationWorkflow ( Workflow ) : <EOL> class States : <EOL> draft = State ( _ ( u"<STR_LIT>" ) , True , delete = False ) <EOL> send = State ( _ ( u"<STR_LIT>" ) , update = False , delete = False ) <EOL> accepted = State ( _ ( u"<STR_LIT>" ) , update = False , delete = False ) <EOL> invoiced = State ( _ ( u"<STR_LIT>" ) , update = False , delete = False ) <EOL> cancelled = State ( _ ( u"<STR_LIT>" ) , update = False , delete = True ) <EOL> class Transitions : <EOL> send = Transition ( _ ( "<STR_LIT>" ) , [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> accept = Transition ( _ ( "<STR_LIT>" ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> reopen = Transition ( _ ( "<STR_LIT>" ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> invoice = Transition ( _ ( "<STR_LIT>" ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> revise = Transition ( _ ( "<STR_LIT>" ) , ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> cancel = Transition ( _ ( "<STR_LIT>" ) , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' , validate = False ) <EOL> def invoice ( self ) : <EOL> if not self . instance . invoice : <EOL> invoice_mdl = self . instance . _meta . model . invoice . field . related_field . model <EOL> products = invoice_mdl . products . through <EOL> invoice = invoice_mdl ( <EOL> customer = self . instance . customer , <EOL> project = self . instance . project , <EOL> employee = self . instance . employee , <EOL> shipping_address = self . instance . shipping_address , <EOL> invoice_address = self . instance . invoice_address , <EOL> notes = self . instance . notes , <EOL> net = self . instance . net , <EOL> term_of_payment = self . instance . term_of_payment , <EOL> date = datetime . datetime . now ( ) . date ( ) , <EOL> created_by = self . user , <EOL> modified_by = self . user , <EOL> ) <EOL> invoice . save ( ) <EOL> for item in self . instance . quotation_products . select_related ( '<STR_LIT>' ) : <EOL> invoice_item = products ( <EOL> invoice = invoice , <EOL> product = item . product , <EOL> amount = item . amount , <EOL> price = item . price , <EOL> name = item . name , <EOL> description = item . description , <EOL> ) <EOL> invoice_item . save ( ) <EOL> self . instance . invoice = invoice </s>
