mirror of
https://github.com/NaN-tic/trytond-product_sale_line_relation.git
synced 2023-12-14 03:42:57 +01:00
153 lines
4.4 KiB
ReStructuredText
153 lines
4.4 KiB
ReStructuredText
===================================
|
|
Product Sale Line Relation Scenario
|
|
===================================
|
|
|
|
Imports::
|
|
|
|
>>> import datetime
|
|
>>> from dateutil.relativedelta import relativedelta
|
|
>>> from decimal import Decimal
|
|
>>> from operator import attrgetter
|
|
>>> from proteus import config, 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 product_sale_line_relation::
|
|
|
|
>>> config = activate_modules('product_sale_line_relation')
|
|
|
|
Create company::
|
|
|
|
>>> _ = create_company()
|
|
>>> company = get_company()
|
|
|
|
Reload the context::
|
|
|
|
>>> User = Model.get('res.user')
|
|
>>> Group = Model.get('res.group')
|
|
>>> config._context = User.get_preferences(True, config.context)
|
|
|
|
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')
|
|
>>> cash_journal, = Journal.find([('type', '=', 'cash')])
|
|
>>> cash_journal.credit_account = cash
|
|
>>> cash_journal.debit_account = cash
|
|
>>> cash_journal.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 category::
|
|
|
|
>>> 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.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')
|
|
>>> product = Product()
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'product'
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'goods'
|
|
>>> template.purchasable = True
|
|
>>> template.salable = True
|
|
>>> template.list_price = Decimal('10')
|
|
>>> template.cost_price_method = 'fixed'
|
|
>>> template.account_category = account_category
|
|
>>> template.save()
|
|
>>> product, = template.products
|
|
>>> product.save()
|
|
|
|
Create payment term::
|
|
|
|
>>> payment_term = create_payment_term()
|
|
>>> payment_term.save()
|
|
|
|
Sale customer::
|
|
|
|
>>> Sale = Model.get('sale.sale')
|
|
>>> SaleLine = Model.get('sale.line')
|
|
>>> sale = Sale()
|
|
>>> sale.party = customer
|
|
>>> sale.payment_term = payment_term
|
|
>>> sale.invoice_method = 'order'
|
|
>>> sale_line = SaleLine()
|
|
>>> sale.lines.append(sale_line)
|
|
>>> sale_line.product = product
|
|
>>> sale_line.quantity = 2.0
|
|
>>> sale_line = SaleLine()
|
|
>>> sale.lines.append(sale_line)
|
|
>>> sale_line.type = 'comment'
|
|
>>> sale_line.description = 'Comment'
|
|
>>> sale_line = SaleLine()
|
|
>>> sale.lines.append(sale_line)
|
|
>>> sale_line.product = product
|
|
>>> sale_line.quantity = 3.0
|
|
>>> sale.click('quote')
|
|
|
|
Sale supplier::
|
|
|
|
>>> sale = Sale()
|
|
>>> sale.party = supplier
|
|
>>> sale.payment_term = payment_term
|
|
>>> sale.invoice_method = 'order'
|
|
>>> sale_line = SaleLine()
|
|
>>> sale.lines.append(sale_line)
|
|
>>> sale_line.product = product
|
|
>>> sale_line.quantity = 2.0
|
|
>>> sale.click('quote')
|
|
|
|
Search Sale Lines::
|
|
|
|
>>> lines = SaleLine.find([('sale_party', '=', customer.id)])
|
|
>>> len(lines)
|
|
3
|
|
>>> line1, line2, line3 = lines
|
|
>>> line1.sale_state
|
|
'quotation'
|
|
>>> sale = line1.sale
|
|
>>> sale.click('confirm')
|
|
>>> line1.reload()
|
|
>>> line1.sale_state
|
|
'processing'
|
|
>>> line1.sale_date == today
|
|
True
|