Simplify stock accounting for fixed cost price from supplier

review244001
This commit is contained in:
Cédric Krier
2012-02-24 10:52:42 +01:00
parent eee9d89888
commit 2b9148a3a4
2 changed files with 23 additions and 29 deletions
+20 -27
View File
@@ -28,41 +28,34 @@ class Move(ModelSQL, ModelView):
lines = super(Move, self)._get_account_stock_move_lines(move, type_)
if (type_.endswith('supplier')
and move.product.cost_price_method == 'fixed'):
move_line = {
'name': move.rec_name,
}
cost_price = uom_obj.compute_price(move.product.default_uom,
move.cost_price, move.uom)
amount = currency_obj.round(move.company.currency,
Decimal(str(move.quantity)) * (move.unit_price - cost_price))
if currency_obj.is_zero(move.company.currency, amount):
return lines
account_id = move.product.account_stock_supplier_used.id
for move_line in lines:
if move_line['account'] == account_id:
break
else:
return lines
if type_.startswith('in_'):
if amount > Decimal(0):
move_line['debit'] = Decimal(0)
move_line['credit'] = amount
else:
move_line['debit'] = -amount
move_line['credit'] = Decimal(0)
account_type = type_[3:]
move_line['credit'] += amount
debit = amount
credit = Decimal(0)
else:
if amount > Decimal(0):
move_line['debit'] = amount
move_line['credit'] = Decimal(0)
else:
move_line['debit'] = Decimal(0)
move_line['credit'] = -amount
account_type = type_[4:]
move_line['account'] = getattr(move.product,
'account_stock_%s_used' % account_type).id
lines.append(move_line)
move_line = move_line.copy()
move_line['debit'], move_line['credit'] = \
move_line['credit'], move_line['debit']
if account_type == 'supplier':
move_line['account'] = move.product.account_expense_used.id
else:
move_line['account'] = move.product.account_revenue_used.id
move_line['debit'] += amount
debit = Decimal(0)
credit = amount
if amount < Decimal(0):
debit, credit = -credit, -debit
move_line = {
'name': move.rec_name,
'debit': debit,
'credit': credit,
'account': move.product.account_expense_used.id,
}
lines.append(move_line)
return lines
+3 -2
View File
@@ -223,8 +223,9 @@ Receive 9 products::
>>> shipment.state
u'done'
>>> stock_supplier.reload()
>>> stock.reload()
>>> (stock_supplier.debit, stock_supplier.credit) == \
... (Decimal('4.00'), Decimal('50.00'))
... (Decimal('0.00'), Decimal('46.00'))
True
>>> stock.reload()
>>> (stock.debit, stock.credit) == \
@@ -258,7 +259,7 @@ Open supplier invoice::
True
>>> stock_supplier.reload()
>>> (stock_supplier.debit, stock_supplier.credit) == \
... (Decimal('50.00'), Decimal('50.00'))
... (Decimal('46.00'), Decimal('46.00'))
True
Sale 5 products::