Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. class CreatePurchaseRequestQuotation(Wizard):
  2.     'Create Purchase Request Quotation'
  3.     __name__ = 'purchase.request.quotation.create'
  4.  
  5.     start_state = 'start'
  6.     start = StateTransition()
  7.     ask_suppliers = StateView(
  8.         'purchase.request.quotation.create.ask_suppliers',
  9.         'purchase_requeste_quotation_create_ask_suppliers', [
  10.             Button('Cancel', 'end', 'tryton-cancel'),
  11.             Button('Process', 'create_quotations', 'tryton-ok', default=True),
  12.             ])
  13.     create_quotations = StateTransition()
  14.  
  15.     @classmethod
  16.     def __setup__(cls):
  17.         super(CreatePurchaseRequestQuotation, cls).__setup__()
  18.         cls._error_messages.update({
  19.                 'previous_quotation': ('A quotation was already made with '
  20.                     'this request: "%(request)s".'),
  21.                 'no_request': ('No request selected or wrong state to '
  22.                     'proceed'),
  23.                 })
  24.  
  25.     def transition_start(self):
  26.         pool = Pool()
  27.         Request = pool.get('purchase.request')
  28.         suppliers = []
  29.         requests = []
  30.  
  31.         request_ids = Transaction().context['active_ids']
  32.         for request_id in request_ids:
  33.             request = Request(request_id)
  34.             if request.state in ('draft', 'quotation'):
  35.                 if request.state == 'quotation':
  36.                     self.raise_user_warning(str(request),
  37.                                 'previous_quotation',
  38.                                 {'request': request.rec_name, })
  39.                 requests.append(request.id)
  40.                 if request.party:
  41.                     suppliers.append(request.party.id)
  42.         if requests:
  43.             self.ask_suppliers.requests = requests
  44.             self.ask_suppliers.suppliers = suppliers
  45.             return 'ask_suppliers'
  46.         self.raise_user_error('no_request')
  47.         return 'end'
  48.  
  49.     def default_ask_suppliers(self, fields):
  50.         defaults = {}
  51.         defaults['requests'] = [r.id for r in self.ask_suppliers.requests]
  52.         defaults['suppliers'] = [s.id for s in self.ask_suppliers.suppliers]
  53.         return defaults
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement