Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.42 KB | None | 0 0
  1. =======================================
  2. Purchase Request For Quotation Scenario
  3. =======================================
  4.  
  5. Imports::
  6.  
  7. >>> import datetime
  8. >>> from decimal import Decimal
  9. >>> from proteus import Model, Wizard
  10. >>> from trytond.tests.tools import activate_modules
  11. >>> from trytond.modules.company.tests.tools import (create_company,
  12. ... get_company)
  13. >>> from trytond.modules.account.tests.tools import (create_chart,
  14. ... get_accounts)
  15. >>> today = datetime.date.today()
  16.  
  17. Activate purchase_request_quotation Module::
  18.  
  19. >>> config = activate_modules('purchase_request_quotation')
  20.  
  21. Create company::
  22.  
  23. >>> _ = create_company()
  24. >>> company = get_company()
  25.  
  26. Create chart of accounts::
  27.  
  28. >>> _ = create_chart(company)
  29. >>> accounts = get_accounts(company)
  30. >>> expense = accounts['expense']
  31.  
  32. Create purchase user which is also in requisition approval group::
  33.  
  34. >>> User = Model.get('res.user')
  35. >>> Group = Model.get('res.group')
  36. >>> Party = Model.get('party.party')
  37. >>> Employee = Model.get('company.employee')
  38. >>> purchase_user = User()
  39. >>> purchase_user.name = 'Purchase'
  40. >>> purchase_user.login = 'purchase'
  41. >>> purchase_user.main_company = company
  42. >>> purchase_group, = Group.find([('name', '=', 'Purchase')])
  43. >>> purchase_user.groups.append(purchase_group)
  44. >>> purchase_request_group, = Group.find(
  45. ... [('name', '=', 'Purchase Request')])
  46. >>> purchase_user.groups.append(purchase_request_group)
  47. >>> requisition_group, = Group.find([
  48. ... ('name', '=', 'Purchase Requisition')])
  49. >>> purchase_user.groups.append(requisition_group)
  50. >>> requisition_approval_group, = Group.find([
  51. ... ('name', '=', 'Purchase Requisition Approval')])
  52. >>> purchase_user.groups.append(requisition_approval_group)
  53. >>> employee_party = Party(name='Employee')
  54. >>> employee_party.save()
  55. >>> employee = Employee(party=employee_party)
  56. >>> employee.save()
  57. >>> purchase_user.employees.append(employee)
  58. >>> purchase_user.employee = employee
  59. >>> purchase_user.save()
  60.  
  61.  
  62. Create supplier::
  63.  
  64. >>> supplier = Party(name='Supplier')
  65. >>> supplier.save()
  66. >>> supplier2 = Party(name='Supplier2')
  67. >>> supplier2.save()
  68. >>> supplier3 = Party(name='Supplier3')
  69. >>> supplier3.save()
  70.  
  71. Create 2 products::
  72.  
  73. >>> ProductUom = Model.get('product.uom')
  74. >>> ProductTemplate = Model.get('product.template')
  75. >>> Product = Model.get('product.product')
  76. >>> unit, = ProductUom.find([('name', '=', 'Unit')])
  77. >>> product = Product()
  78. >>> template = ProductTemplate()
  79. >>> template.name = 'Product'
  80. >>> template.default_uom = unit
  81. >>> template.type = 'goods'
  82. >>> template.list_price = Decimal('20')
  83. >>> template.cost_price = Decimal('8')
  84. >>> template.purchasable = True
  85. >>> template.account_expense = expense
  86. >>> template.save()
  87. >>> product.template = template
  88. >>> product.save()
  89. >>> product2 = Product()
  90. >>> template = ProductTemplate()
  91. >>> template.name = 'Product2'
  92. >>> template.default_uom = unit
  93. >>> template.type = 'goods'
  94. >>> template.list_price = Decimal('10')
  95. >>> template.cost_price = Decimal('4')
  96. >>> template.purchasable = True
  97. >>> template.account_expense = expense
  98. >>> template.save()
  99. >>> product2.template = template
  100. >>> product2.save()
  101.  
  102. Create 2 purchase requisition with differents products and
  103. different suppliers::
  104.  
  105. >>> config.user = purchase_user.id
  106. >>> Location = Model.get('stock.location')
  107. >>> PurchaseRequisition = Model.get('purchase.requisition')
  108. >>> requisition = PurchaseRequisition()
  109. >>> requisition.description = 'Description'
  110. >>> requisition.employee = purchase_user.employee
  111. >>> requisition.supply_date = today
  112. >>> requisition_line = requisition.lines.new()
  113. >>> requisition_line.product = product
  114. >>> requisition_line.description = 'Description'
  115. >>> requisition_line.quantity = 2.0
  116. >>> requisition_line.supplier = supplier
  117. >>> requisition_line.price = 10.0
  118. >>> warehouse_loc, = Location.find([('code', '=', 'WH')])
  119. >>> requisition.warehouse = warehouse_loc
  120. >>> requisition.click('wait')
  121. >>> requisition.click('approve')
  122. >>> requisition.state
  123. u'processing'
  124. >>> requisition = PurchaseRequisition()
  125. >>> requisition.description = 'Description'
  126. >>> requisition.employee = purchase_user.employee
  127. >>> requisition.supply_date = today
  128. >>> requisition_line = requisition.lines.new()
  129. >>> requisition_line.product = product2
  130. >>> requisition_line.description = 'Description2'
  131. >>> requisition_line.quantity = 3.0
  132. >>> requisition_line.supplier = supplier2
  133. >>> requisition_line.price = 7.0
  134. >>> warehouse_loc, = Location.find([('code', '=', 'WH')])
  135. >>> requisition.warehouse = warehouse_loc
  136. >>> requisition.click('wait')
  137. >>> requisition.click('approve')
  138. >>> requisition.state
  139. u'processing'
  140.  
  141. Create Purchase Request Quotation from 2 Requests and
  142. add another supplier::
  143.  
  144. >>> PurchaseRequest = Model.get('purchase.request')
  145. >>> pr = PurchaseRequest.find([('state', '=', 'draft')])
  146. >>> len(pr)
  147. 2
  148. >>> pr[0].state
  149. 'draft'
  150. >>> create_quotation = Wizard('purchase.request.create_quotation', pr)
  151. >>> create_quotation.form.suppliers.append(supplier3)
  152. >>> create_quotation.execute('process')
  153. >>> pr[0].state
  154. 'quotation'
  155.  
  156. Check Quotations (2 Requests with 3 Suppliers = 6 Quotations)::
  157.  
  158. >>> Quotation = Model.get('purchase.request.quotation')
  159. >>> q = Quotation.find([('group_state', '=', 'draft')])
  160. >>> len(q)
  161. 6
  162.  
  163. Send Quotations::
  164.  
  165. >>> QuotationGroup = Model.get('purchase.request.quotation.group')
  166. >>> qg = QuotationGroup.find([('state', '=', 'draft')])
  167. >>> len(qg)
  168. 3
  169. >>> for quotation_group in qg:
  170. ... quotation_group.click('send')
  171. >>> qg = QuotationGroup.find([('state', '=', 'sent')])
  172. >>> len(qg)
  173. 3
  174.  
  175. Only supplier and supplier3 will answer to quotation::
  176.  
  177. >>> qg, = QuotationGroup.find([('state', '=', 'sent'),
  178. ... ('supplier', '=', supplier.id)])
  179. >>> qg.request_quotations[0].unit_price = Decimal('11')
  180. >>> qg.request_quotations[1].unit_price = Decimal('6')
  181. >>> qg.click('answer')
  182. >>> qg, = QuotationGroup.find([('state', '=', 'sent'),
  183. ... ('supplier', '=', supplier3.id)])
  184. >>> qg.request_quotations[0].unit_price = Decimal('8')
  185. >>> qg.request_quotations[1].unit_price = Decimal('9')
  186. >>> qg.click('answer')
  187.  
  188. For each Purchase Request we will order Quotations (the first quotation
  189. with state 'answered' will be used to create the Purchase Order)::
  190.  
  191. >>> for request in pr:
  192. ... q_ids = [q.id for q in request.quotations]
  193. ... quotations = Quotation.find([('id', 'in', q_ids)],
  194. ... order=[('unit_price', 'ASC')])
  195. ... i = 1
  196. ... for q in quotations:
  197. ... q.sequence = i
  198. ... q.save()
  199. ... i = i + 1
  200. >>> PurchaseRequest = Model.get('purchase.request')
  201. >>> prequest = PurchaseRequest.find([('state', '=', 'draft')])
  202. >>> for r in prequest:
  203. ... r.id, r.state,r.quotations
  204.  
  205. Create Purchase Order from Purchase Request::
  206.  
  207. >>> create_purchase = Wizard('purchase.request.create_purchase', prequest)
  208. >>> prequest[0].state
  209. 'purchased'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement