165 lines
5.4 KiB
ReStructuredText
165 lines
5.4 KiB
ReStructuredText
===========================================
|
|
Account Invoice Line Purchase Info Scenario
|
|
===========================================
|
|
|
|
Imports::
|
|
|
|
>>> from datetime import date
|
|
>>> import datetime
|
|
>>> from dateutil.relativedelta import relativedelta
|
|
>>> from decimal import Decimal
|
|
>>> from operator import attrgetter
|
|
>>> from proteus import Model, Wizard, Report
|
|
>>> 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_fiscalyear, \
|
|
... create_chart, get_accounts, create_tax
|
|
>>> from trytond.modules.account_invoice.tests.tools import \
|
|
... set_fiscalyear_invoice_sequences, create_payment_term
|
|
>>> today = datetime.date.today()
|
|
|
|
Install account_invoice_line_purchase_info::
|
|
|
|
>>> config = activate_modules('account_invoice_line_purchase_info')
|
|
|
|
|
|
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']
|
|
|
|
>>> Journal = Model.get('account.journal')
|
|
>>> PaymentMethod = Model.get('account.invoice.payment.method')
|
|
>>> cash_journal, = Journal.find([('type', '=', 'cash')])
|
|
>>> cash_journal.save()
|
|
>>> payment_method = PaymentMethod()
|
|
>>> payment_method.name = 'Cash'
|
|
>>> payment_method.journal = cash_journal
|
|
>>> payment_method.credit_account = cash
|
|
>>> payment_method.debit_account = cash
|
|
>>> payment_method.save()
|
|
|
|
Create tax::
|
|
|
|
>>> tax = create_tax(Decimal('.10'))
|
|
>>> tax.save()
|
|
|
|
Create parties::
|
|
|
|
>>> Party = Model.get('party.party')
|
|
>>> supplier = Party(name='Supplier')
|
|
>>> supplier.save()
|
|
>>> customer = Party(name='Customer')
|
|
>>> customer.save()
|
|
|
|
|
|
Create account categories::
|
|
|
|
>>> ProductCategory = Model.get('product.category')
|
|
>>> account_category = ProductCategory(name="Account Category")
|
|
>>> account_category.accounting = True
|
|
>>> account_category.account_expense = expense
|
|
>>> account_category.account_revenue = revenue
|
|
>>> account_category.save()
|
|
>>> account_category_tax, = account_category.duplicate()
|
|
>>> account_category_tax.customer_taxes.append(tax)
|
|
>>> account_category_tax.save()
|
|
|
|
Create product::
|
|
|
|
>>> ProductUom = Model.get('product.uom')
|
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
|
>>> ProductTemplate = Model.get('product.template')
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'product'
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'goods'
|
|
>>> template.purchasable = True
|
|
>>> template.list_price = Decimal('10')
|
|
>>> template.cost_price_method = 'fixed'
|
|
>>> template.account_category = account_category_tax
|
|
>>> product, = template.products
|
|
>>> product.cost_price = Decimal('5')
|
|
>>> template.save()
|
|
>>> product, = template.products
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'service'
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'service'
|
|
>>> template.purchasable = True
|
|
>>> template.list_price = Decimal('10')
|
|
>>> template.cost_price_method = 'fixed'
|
|
>>> template.account_category = account_category_tax
|
|
>>> service, = template.products
|
|
>>> service.cost_price = Decimal('10')
|
|
>>> template.save()
|
|
>>> service, = template.products
|
|
|
|
Create payment term::
|
|
|
|
>>> payment_term = create_payment_term()
|
|
>>> payment_term.save()
|
|
|
|
Create an Inventory::
|
|
|
|
>>> Inventory = Model.get('stock.inventory')
|
|
>>> Location = Model.get('stock.location')
|
|
>>> storage, = Location.find([
|
|
... ('code', '=', 'STO'),
|
|
... ])
|
|
>>> inventory = Inventory()
|
|
>>> inventory.location = storage
|
|
>>> inventory_line = inventory.lines.new(product=product)
|
|
>>> inventory_line.quantity = 100.0
|
|
>>> inventory_line.expected_quantity = 0.0
|
|
>>> inventory.click('confirm')
|
|
|
|
Purchase 5 products::
|
|
|
|
>>> Purchase = Model.get('purchase.purchase')
|
|
>>> PurchaseLine = Model.get('purchase.line')
|
|
>>> purchase = Purchase()
|
|
>>> purchase.party = supplier
|
|
>>> purchase.payment_term = payment_term
|
|
>>> purchase.invoice_method = 'order'
|
|
>>> 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.type = 'comment'
|
|
>>> purchase.reference = 'P1'
|
|
>>> purchase.purchase_date = date(day=31, month=12, year=2016)
|
|
>>> purchase_line.description = 'Comment'
|
|
>>> purchase_line = PurchaseLine()
|
|
>>> purchase.lines.append(purchase_line)
|
|
>>> purchase_line.product = product
|
|
>>> purchase_line.quantity = 3.0
|
|
>>> purchase.click('quote')
|
|
>>> purchase.click('confirm')
|
|
>>> purchase.click('process')
|
|
>>> invoice, = purchase.invoices
|
|
|
|
Invoice line must have purchase values::
|
|
|
|
>>> invoice_line1 = invoice.lines[0]
|
|
>>> invoice_line1.purchase_reference
|
|
'P1'
|
|
>>> invoice_line1.purchase_date
|
|
datetime.date(2016, 12, 31) |