/usr/lib/python3/dist-packages/trytond/modules/stock/tests/scenario_stock_average_cost_price.rst is in tryton-modules-stock 4.6.2-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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | ========================
Stock Average Cost Price
========================
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
>>> today = datetime.date.today()
Install stock Module::
>>> config = activate_modules('stock')
Create company::
>>> _ = create_company()
>>> company = get_company()
Create product::
>>> ProductUom = Model.get('product.uom')
>>> ProductTemplate = Model.get('product.template')
>>> Product = Model.get('product.product')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('300')
>>> template.cost_price_method = 'average'
>>> product, = template.products
>>> product.cost_price = Decimal('80')
>>> template.save()
>>> product, = template.products
>>> template = ProductTemplate()
>>> template.name = 'Negative Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('28')
>>> template.cost_price_method = 'average'
>>> negative_product, = template.products
>>> negative_product.cost_price = Decimal('5.0000')
>>> template.save()
>>> negative_product, = template.products
Get stock locations::
>>> Location = Model.get('stock.location')
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
>>> storage_loc, = Location.find([('code', '=', 'STO')])
>>> storage_sub_loc = Location(
... name="Storage Sub", type='storage', parent=storage_loc)
>>> storage_sub_loc.save()
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
Make 1 unit of the product available @ 100 ::
>>> StockMove = Model.get('stock.move')
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.uom = unit
>>> incoming_move.quantity = 1
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_sub_loc
>>> incoming_move.planned_date = today
>>> incoming_move.effective_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('100')
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Check Cost Price is 100::
>>> product.reload()
>>> product.cost_price
Decimal('100.0000')
Add 1 more unit @ 200::
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.uom = unit
>>> incoming_move.quantity = 1
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.effective_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('200')
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Check Cost Price Average is 150::
>>> product.reload()
>>> product.cost_price
Decimal('150.0000')
Add twice 1 more unit @ 200::
>>> incoming_moves = []
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.uom = unit
>>> incoming_move.quantity = 1
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.effective_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('200')
>>> incoming_move.currency = company.currency
>>> incoming_move.save()
>>> incoming_moves.append(incoming_move)
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.uom = unit
>>> incoming_move.quantity = 1
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.effective_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('200')
>>> incoming_move.currency = company.currency
>>> incoming_move.save()
>>> incoming_moves.append(incoming_move)
>>> StockMove.click(incoming_moves, 'do')
Check Cost Price Average is 175::
>>> product.reload()
>>> product.cost_price
Decimal('175.0000')
Change Cost Price to 125, to force to write recomputed price later::
>>> product.cost_price = Decimal('125.0000')
>>> product.save()
>>> product.cost_price
Decimal('125.0000')
Recompute Cost Price::
>>> recompute = Wizard('product.recompute_cost_price', [product])
>>> product.cost_price
Decimal('175.0000')
Send one product we don't have in stock::
>>> outgoing_move = StockMove()
>>> outgoing_move.product = negative_product
>>> outgoing_move.uom = unit
>>> outgoing_move.quantity = 1
>>> outgoing_move.from_location = storage_loc
>>> outgoing_move.to_location = customer_loc
>>> outgoing_move.planned_date = today
>>> outgoing_move.effective_date = today
>>> outgoing_move.company = company
>>> outgoing_move.currency = company.currency
>>> outgoing_move.click('do')
Cost price should stay 5::
>>> negative_product.cost_price
Decimal('5.0000')
Return one product to the supplier::
>>> outgoing_move = StockMove()
>>> outgoing_move.product = negative_product
>>> outgoing_move.uom = unit
>>> outgoing_move.quantity = 1
>>> outgoing_move.from_location = storage_loc
>>> outgoing_move.to_location = supplier_loc
>>> outgoing_move.planned_date = today
>>> outgoing_move.effective_date = today
>>> outgoing_move.company = company
>>> outgoing_move.currency = company.currency
>>> outgoing_move.click('do')
Cost price should stay 5::
>>> negative_product.cost_price
Decimal('5.0000')
Receive one unit of the product with negative stock so the stock stays negative::
>>> incoming_move = StockMove()
>>> incoming_move.product = negative_product
>>> incoming_move.uom = unit
>>> incoming_move.quantity = 1
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.effective_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('3')
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Cost price should be set to last unit price::
>>> negative_product.reload()
>>> negative_product.cost_price
Decimal('3.0000')
Receive two units of the product so the stock becomes positive::
>>> incoming_move = StockMove()
>>> incoming_move.product = negative_product
>>> incoming_move.uom = unit
>>> incoming_move.quantity = 2
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.effective_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('2')
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Cost price should be set to last unit price::
>>> negative_product.reload()
>>> negative_product.cost_price
Decimal('2.0000')
Change Cost Price to 5, to force to write recomputed price later::
>>> negative_product.cost_price = Decimal('5.0000')
>>> negative_product.save()
>>> negative_product.cost_price
Decimal('5.0000')
Recompute Cost Price::
>>> recompute = Wizard('product.recompute_cost_price', [negative_product])
>>> negative_product.cost_price
Decimal('2.0000')
|