/usr/lib/python3/dist-packages/trytond/modules/purchase_shipment_cost/tests/scenario_purchase_shipment_cost_with_account_stock.rst is in tryton-modules-purchase-shipment-cost 4.6.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | ==================================================
Purchase Shipment Cost with Account Stock Scenario
==================================================
Imports::
>>> import datetime
>>> from dateutil.relativedelta import relativedelta
>>> 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_fiscalyear, \
... create_chart, get_accounts
>>> from trytond.modules.account_invoice.tests.tools import \
... set_fiscalyear_invoice_sequences
>>> from trytond.modules.account_stock_continental.tests.tools import \
... add_stock_accounts
>>> today = datetime.date.today()
Install purchase_shipment_cost and account_stock_continental::
>>> config = activate_modules([
... 'purchase_shipment_cost',
... 'account_stock_continental',
... ])
Create company::
>>> _ = create_company()
>>> company = get_company()
Create fiscal year::
>>> fiscalyear = create_fiscalyear(company)
>>> fiscalyear.account_stock_method = 'continental'
>>> fiscalyear.click('create_period')
Create chart of accounts::
>>> _ = create_chart(company)
>>> accounts = add_stock_accounts(get_accounts(company), company)
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> stock = accounts['stock']
>>> stock_customer = accounts['stock_customer']
>>> stock_lost_found = accounts['stock_lost_found']
>>> stock_production = accounts['stock_production']
>>> stock_supplier = accounts['stock_supplier']
>>> AccountJournal = Model.get('account.journal')
>>> stock_journal, = AccountJournal.find([('code', '=', 'STO')])
Create supplier::
>>> Party = Model.get('party.party')
>>> supplier = Party(name='Supplier')
>>> supplier.save()
Create products::
>>> ProductUom = Model.get('product.uom')
>>> ProductTemplate = Model.get('product.template')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('20')
>>> template.account_expense = expense
>>> template.account_revenue = revenue
>>> template.account_stock = stock
>>> template.account_stock_supplier = stock_supplier
>>> template.account_stock_customer = stock_customer
>>> template.account_stock_production = stock_production
>>> template.account_stock_lost_found = stock_lost_found
>>> template.account_journal_stock_supplier = stock_journal
>>> template.account_journal_stock_customer = stock_journal
>>> template.account_journal_stock_lost_found = stock_journal
>>> product, = template.products
>>> product.cost_price = Decimal('8')
>>> template.save()
>>> product, = template.products
>>> template_average, = template.duplicate({
... 'cost_price_method': 'average',
... })
>>> product_average, = template_average.products
>>> carrier_template = ProductTemplate()
>>> carrier_template.name = 'Carrier Product'
>>> carrier_template.default_uom = unit
>>> carrier_template.type = 'service'
>>> carrier_template.list_price = Decimal('5')
>>> carrier_template.account_expense = expense
>>> carrier_template.account_revenue = revenue
>>> carrier_product, = carrier_template.products
>>> carrier_product.cost_price = Decimal('3')
>>> carrier_template.save()
>>> carrier_product, = carrier_template.products
Create carrier::
>>> Carrier = Model.get('carrier')
>>> carrier = Carrier()
>>> party = Party(name='Carrier')
>>> party.save()
>>> carrier.party = party
>>> carrier.carrier_product = carrier_product
>>> carrier.save()
Receive a single product line::
>>> ShipmentIn = Model.get('stock.shipment.in')
>>> Move = Model.get('stock.move')
>>> Location = Model.get('stock.location')
>>> supplier_location, = Location.find([
... ('code', '=', 'SUP'),
... ])
>>> shipment = ShipmentIn()
>>> shipment.supplier = supplier
>>> move = Move()
>>> shipment.incoming_moves.append(move)
>>> move.from_location = supplier_location
>>> move.to_location = shipment.warehouse.input_location
>>> move.product = product
>>> move.quantity = 30
>>> move.unit_price
Decimal('8')
>>> move = Move()
>>> shipment.incoming_moves.append(move)
>>> move.from_location = supplier_location
>>> move.to_location = shipment.warehouse.input_location
>>> move.product = product_average
>>> move.quantity = 20
>>> move.unit_price
Decimal('8')
>>> shipment.carrier = carrier
>>> shipment.cost
Decimal('3')
>>> shipment.cost_currency == company.currency
True
>>> shipment.click('receive')
>>> shipment.state
u'received'
>>> move, move_average = shipment.incoming_moves
>>> move.unit_price
Decimal('8.0600')
>>> move_average.unit_price
Decimal('8.0600')
>>> stock_supplier.reload()
>>> (stock_supplier.debit, stock_supplier.credit) == \
... (Decimal('0.00'), Decimal('398.20'))
True
>>> expense.reload()
>>> (expense.debit, expense.credit) == \
... (Decimal('0.00'), Decimal('3.00'))
True
>>> stock.reload()
>>> (stock.debit, stock.credit) == \
... (Decimal('401.20'), Decimal('0.00'))
True
Receive many product lines::
>>> shipment = ShipmentIn()
>>> shipment.supplier = supplier
>>> for quantity in (1, 3, 5):
... move = Move()
... shipment.incoming_moves.append(move)
... move.from_location = supplier_location
... move.to_location = shipment.warehouse.input_location
... move.product = product
... move.quantity = quantity
>>> shipment.carrier = carrier
>>> shipment.cost
Decimal('3')
>>> shipment.click('receive')
>>> shipment.state
u'received'
>>> [move.unit_price for move in shipment.incoming_moves] == \
... [Decimal('8.3333'), Decimal('8.3333'), Decimal('8.3334')]
True
>>> stock_supplier.reload()
>>> (stock_supplier.debit, stock_supplier.credit) == \
... (Decimal('0.00'), Decimal('467.20'))
True
>>> expense.reload()
>>> (expense.debit, expense.credit) == \
... (Decimal('0.00'), Decimal('6.00'))
True
>>> stock.reload()
>>> (stock.debit, stock.credit) == \
... (Decimal('473.20'), Decimal('0.00'))
True
|