Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =======================================
- Purchase Request For Quotation Scenario
- =======================================
- Imports::
- >>> import datetime
- >>> from decimal import Decimal
- >>> from proteus import Model, Wizard
- >>> from trytond.tests.tools import activate_modules
- >>> from trytond.modules.company.tests.tools import (create_company,
- ... get_company)
- >>> from trytond.modules.account.tests.tools import (create_chart,
- ... get_accounts)
- >>> today = datetime.date.today()
- Activate purchase_request_quotation Module::
- >>> config = activate_modules('purchase_request_quotation')
- Create company::
- >>> _ = create_company()
- >>> company = get_company()
- Create chart of accounts::
- >>> _ = create_chart(company)
- >>> accounts = get_accounts(company)
- >>> expense = accounts['expense']
- Create purchase user which is also in requisition approval group::
- >>> User = Model.get('res.user')
- >>> Group = Model.get('res.group')
- >>> Party = Model.get('party.party')
- >>> Employee = Model.get('company.employee')
- >>> purchase_user = User()
- >>> purchase_user.name = 'Purchase'
- >>> purchase_user.login = 'purchase'
- >>> purchase_user.main_company = company
- >>> purchase_group, = Group.find([('name', '=', 'Purchase')])
- >>> purchase_user.groups.append(purchase_group)
- >>> purchase_request_group, = Group.find(
- ... [('name', '=', 'Purchase Request')])
- >>> purchase_user.groups.append(purchase_request_group)
- >>> requisition_group, = Group.find([
- ... ('name', '=', 'Purchase Requisition')])
- >>> purchase_user.groups.append(requisition_group)
- >>> requisition_approval_group, = Group.find([
- ... ('name', '=', 'Purchase Requisition Approval')])
- >>> purchase_user.groups.append(requisition_approval_group)
- >>> employee_party = Party(name='Employee')
- >>> employee_party.save()
- >>> employee = Employee(party=employee_party)
- >>> employee.save()
- >>> purchase_user.employees.append(employee)
- >>> purchase_user.employee = employee
- >>> purchase_user.save()
- Create supplier::
- >>> supplier = Party(name='Supplier')
- >>> supplier.save()
- >>> supplier2 = Party(name='Supplier2')
- >>> supplier2.save()
- >>> supplier3 = Party(name='Supplier3')
- >>> supplier3.save()
- Create 2 products::
- >>> ProductUom = Model.get('product.uom')
- >>> ProductTemplate = Model.get('product.template')
- >>> Product = Model.get('product.product')
- >>> unit, = ProductUom.find([('name', '=', 'Unit')])
- >>> product = Product()
- >>> template = ProductTemplate()
- >>> template.name = 'Product'
- >>> template.default_uom = unit
- >>> template.type = 'goods'
- >>> template.list_price = Decimal('20')
- >>> template.cost_price = Decimal('8')
- >>> template.purchasable = True
- >>> template.account_expense = expense
- >>> template.save()
- >>> product.template = template
- >>> product.save()
- >>> product2 = Product()
- >>> template = ProductTemplate()
- >>> template.name = 'Product2'
- >>> template.default_uom = unit
- >>> template.type = 'goods'
- >>> template.list_price = Decimal('10')
- >>> template.cost_price = Decimal('4')
- >>> template.purchasable = True
- >>> template.account_expense = expense
- >>> template.save()
- >>> product2.template = template
- >>> product2.save()
- Create 2 purchase requisition with differents products and
- different suppliers::
- >>> config.user = purchase_user.id
- >>> Location = Model.get('stock.location')
- >>> PurchaseRequisition = Model.get('purchase.requisition')
- >>> requisition = PurchaseRequisition()
- >>> requisition.description = 'Description'
- >>> requisition.employee = purchase_user.employee
- >>> requisition.supply_date = today
- >>> requisition_line = requisition.lines.new()
- >>> requisition_line.product = product
- >>> requisition_line.description = 'Description'
- >>> requisition_line.quantity = 2.0
- >>> requisition_line.supplier = supplier
- >>> requisition_line.price = 10.0
- >>> warehouse_loc, = Location.find([('code', '=', 'WH')])
- >>> requisition.warehouse = warehouse_loc
- >>> requisition.click('wait')
- >>> requisition.click('approve')
- >>> requisition.state
- u'processing'
- >>> requisition = PurchaseRequisition()
- >>> requisition.description = 'Description'
- >>> requisition.employee = purchase_user.employee
- >>> requisition.supply_date = today
- >>> requisition_line = requisition.lines.new()
- >>> requisition_line.product = product2
- >>> requisition_line.description = 'Description2'
- >>> requisition_line.quantity = 3.0
- >>> requisition_line.supplier = supplier2
- >>> requisition_line.price = 7.0
- >>> warehouse_loc, = Location.find([('code', '=', 'WH')])
- >>> requisition.warehouse = warehouse_loc
- >>> requisition.click('wait')
- >>> requisition.click('approve')
- >>> requisition.state
- u'processing'
- Create Purchase Request Quotation from 2 Requests and
- add another supplier::
- >>> PurchaseRequest = Model.get('purchase.request')
- >>> pr = PurchaseRequest.find([('state', '=', 'draft')])
- >>> len(pr)
- 2
- >>> pr[0].state
- 'draft'
- >>> create_quotation = Wizard('purchase.request.create_quotation', pr)
- >>> create_quotation.form.suppliers.append(supplier3)
- >>> create_quotation.execute('process')
- >>> pr[0].state
- 'quotation'
- Check Quotations (2 Requests with 3 Suppliers = 6 Quotations)::
- >>> Quotation = Model.get('purchase.request.quotation')
- >>> q = Quotation.find([('group_state', '=', 'draft')])
- >>> len(q)
- 6
- Send Quotations::
- >>> QuotationGroup = Model.get('purchase.request.quotation.group')
- >>> qg = QuotationGroup.find([('state', '=', 'draft')])
- >>> len(qg)
- 3
- >>> for quotation_group in qg:
- ... quotation_group.click('send')
- >>> qg = QuotationGroup.find([('state', '=', 'sent')])
- >>> len(qg)
- 3
- Only supplier and supplier3 will answer to quotation::
- >>> qg, = QuotationGroup.find([('state', '=', 'sent'),
- ... ('supplier', '=', supplier.id)])
- >>> qg.request_quotations[0].unit_price = Decimal('11')
- >>> qg.request_quotations[1].unit_price = Decimal('6')
- >>> qg.click('answer')
- >>> qg, = QuotationGroup.find([('state', '=', 'sent'),
- ... ('supplier', '=', supplier3.id)])
- >>> qg.request_quotations[0].unit_price = Decimal('8')
- >>> qg.request_quotations[1].unit_price = Decimal('9')
- >>> qg.click('answer')
- For each Purchase Request we will order Quotations (the first quotation
- with state 'answered' will be used to create the Purchase Order)::
- >>> for request in pr:
- ... q_ids = [q.id for q in request.quotations]
- ... quotations = Quotation.find([('id', 'in', q_ids)],
- ... order=[('unit_price', 'ASC')])
- ... i = 1
- ... for q in quotations:
- ... q.sequence = i
- ... q.save()
- ... i = i + 1
- >>> PurchaseRequest = Model.get('purchase.request')
- >>> prequest = PurchaseRequest.find([('state', '=', 'draft')])
- >>> for r in prequest:
- ... r.id, r.state,r.quotations
- Create Purchase Order from Purchase Request::
- >>> create_purchase = Wizard('purchase.request.create_purchase', prequest)
- >>> prequest[0].state
- 'purchased'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement