150 lines
4.4 KiB
ReStructuredText
150 lines
4.4 KiB
ReStructuredText
==================
|
|
Purchase Shop Scenario
|
|
==================
|
|
|
|
Imports::
|
|
|
|
>>> import datetime
|
|
>>> from decimal import Decimal
|
|
>>> from proteus import Model
|
|
>>> from trytond.tests.tools import activate_modules, set_user
|
|
>>> from trytond.modules.company.tests.tools import create_company, \
|
|
... get_company
|
|
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
|
|
... create_chart, get_accounts, create_tax
|
|
>>> from trytond.modules.account_invoice.tests.tools import \
|
|
... set_fiscalyear_invoice_sequences, create_payment_term
|
|
>>> from trytond.modules.purchase_shop.tests.tools import create_shop
|
|
>>> today = datetime.date.today()
|
|
|
|
Install purchase::
|
|
|
|
>>> config = activate_modules('purchase_shop')
|
|
|
|
Create company::
|
|
|
|
>>> _ = create_company()
|
|
>>> company = get_company()
|
|
|
|
Create fiscal year::
|
|
|
|
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
|
... create_fiscalyear(company))
|
|
>>> fiscalyear.click('create_period')
|
|
|
|
Create chart of accounts::
|
|
|
|
>>> _ = create_chart(company)
|
|
>>> accounts = get_accounts(company)
|
|
>>> revenue = accounts['revenue']
|
|
>>> expense = accounts['expense']
|
|
>>> cash = accounts['cash']
|
|
|
|
Create tax::
|
|
|
|
>>> tax = create_tax(Decimal('.10'))
|
|
>>> tax.save()
|
|
|
|
Create payment term::
|
|
|
|
>>> payment_term = create_payment_term()
|
|
>>> payment_term.save()
|
|
|
|
Create product price list::
|
|
|
|
>>> ProductPriceList = Model.get('product.price_list')
|
|
>>> product_price_list = ProductPriceList()
|
|
>>> product_price_list.name = 'Price List'
|
|
>>> product_price_list.company = company
|
|
>>> product_price_list.save()
|
|
|
|
Create parties::
|
|
|
|
>>> Party = Model.get('party.party')
|
|
>>> supplier = Party(name='Supplier')
|
|
>>> supplier.save()
|
|
>>> customer = Party(name='Customer')
|
|
>>> customer.save()
|
|
|
|
Create category::
|
|
|
|
>>> ProductCategory = Model.get('product.category')
|
|
>>> account_category = ProductCategory(name='Category')
|
|
>>> account_category.accounting = True
|
|
>>> account_category.account_expense = expense
|
|
>>> account_category.account_revenue = revenue
|
|
>>> account_category.customer_taxes.append(tax)
|
|
>>> account_category.save()
|
|
|
|
Create product::
|
|
|
|
>>> ProductUom = Model.get('product.uom')
|
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
|
>>> ProductTemplate = Model.get('product.template')
|
|
>>> Product = Model.get('product.product')
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'product'
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'goods'
|
|
>>> template.list_price = Decimal('40')
|
|
>>> template.account_category = account_category
|
|
>>> template.salable = True
|
|
>>> template.save()
|
|
>>> product, = template.products
|
|
>>> product.cost_price = Decimal('25')
|
|
>>> product.save()
|
|
|
|
Create an Inventory::
|
|
|
|
>>> Inventory = Model.get('stock.inventory')
|
|
>>> InventoryLine = Model.get('stock.inventory.line')
|
|
>>> Location = Model.get('stock.location')
|
|
>>> storage, = Location.find([
|
|
... ('code', '=', 'STO'),
|
|
... ])
|
|
>>> inventory = Inventory()
|
|
>>> inventory.location = storage
|
|
>>> inventory.save()
|
|
>>> inventory_line = InventoryLine(product=product, inventory=inventory)
|
|
>>> inventory_line.quantity = 100.0
|
|
>>> inventory_line.expected_quantity = 0.0
|
|
>>> inventory.save()
|
|
>>> inventory_line.save()
|
|
>>> Inventory.confirm([inventory.id], config.context)
|
|
>>> inventory.state == 'done'
|
|
True
|
|
|
|
Create Purchase Shop::
|
|
|
|
>>> shop = create_shop(payment_term, product_price_list)
|
|
>>> shop.save()
|
|
|
|
Save Purchase Shop User::
|
|
|
|
>>> User = Model.get('res.user')
|
|
>>> user, = User.find([])
|
|
>>> user.shops.append(shop)
|
|
>>> user.shop = shop
|
|
>>> user.save()
|
|
>>> set_user(user)
|
|
|
|
Purchase 5 products::
|
|
|
|
>>> Purchase = Model.get('purchase.purchase')
|
|
>>> PurchaseLine = Model.get('purchase.line')
|
|
>>> purchase = Purchase()
|
|
>>> purchase.party = customer
|
|
>>> purchase.payment_term = payment_term
|
|
>>> purchase.invoice_method = 'shipment'
|
|
>>> purchase_line = PurchaseLine()
|
|
>>> purchase.lines.append(purchase_line)
|
|
>>> purchase_line.product = product
|
|
>>> purchase_line.quantity = 2.0
|
|
>>> purchase_line = PurchaseLine()
|
|
>>> purchase.lines.append(purchase_line)
|
|
>>> purchase_line.product = product
|
|
>>> purchase_line.quantity = 3.0
|
|
>>> purchase.save()
|
|
>>> purchase.state == 'draft'
|
|
True
|