Create move also from supplier to customer

issue2428
review237005
This commit is contained in:
Cédric Krier committed 2012-02-27 10:46:12 +01:00
1 parent 3cdc86cc8a
commit dd2fe5dbb5
3 files changed
+63 -3

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Create move also from supplier to customer
* Define "Stock Journal" on "Account Configuration"
* Use cost price instead of unit price when cost method is "fixed"
+21 -3
View File
@@ -53,6 +53,8 @@ class Move(ModelSQL, ModelView):
'name': move.rec_name,
'account': move.product.account_stock_used.id,
}
if not amount:
return
if amount >= Decimal('0.0'):
move_line['debit'] = Decimal('0.0')
move_line['credit'] = amount
@@ -97,6 +99,10 @@ class Move(ModelSQL, ModelView):
return 'out_lost_found'
elif type_ == ('lost_found', 'storage'):
return 'in_lost_found'
elif type_ == ('supplier', 'customer'):
return 'supplier_customer'
elif type_ == ('customer', 'supplier'):
return 'customer_supplier'
def _create_account_stock_move(self, move):
'''
@@ -107,13 +113,25 @@ class Move(ModelSQL, ModelView):
if not type_:
return
assert not move.account_move, 'account move field not empty'
account_move_lines = self._get_account_stock_move_lines(move, type_)
if type_ == 'supplier_customer':
account_move_lines = self._get_account_stock_move_lines(move,
'in_supplier')
account_move_lines.extend(self._get_account_stock_move_lines(move,
'out_customer'))
elif type_ == 'customer_supplier':
account_move_lines = self._get_account_stock_move_lines(move,
'in_customer')
account_move_lines.extend(self._get_account_stock_move_lines(move,
'out_supplier'))
else:
account_move_lines = self._get_account_stock_move_lines(move, type_)
amount = Decimal('0.0')
for line in account_move_lines:
amount += line['debit'] - line['credit']
account_move_lines.append(
self._get_account_stock_move_line(move, amount))
move_line = self._get_account_stock_move_line(move, amount)
if move_line:
account_move_lines.append(move_line)
account_move_id = account_move_obj.create(
self._get_account_stock_move(move, account_move_lines))
@@ -335,3 +335,44 @@ Create an Inventory::
>>> (stock.debit, stock.credit) == \
... (Decimal('50.00'), Decimal('39.00'))
True
Create Move from Supplier to Customer::
>>> supplier_location, = Location.find([('code', '=', 'SUP')])
>>> customer_location, = Location.find([('code', '=', 'CUS')])
>>> move = Move()
>>> move.product = product
>>> move.quantity = 3
>>> move.from_location = supplier_location
>>> move.to_location = customer_location
>>> move.unit_price = Decimal(6)
>>> move.cost_price = move.unit_price
>>> move.currency = currency
>>> move.state = 'done'
>>> move.save()
>>> stock_supplier.reload()
>>> (stock_supplier.debit, stock_supplier.credit) == \
... (Decimal(0), Decimal(68))
True
>>> stock_customer.reload()
>>> (stock_customer.debit, stock_customer.credit) == \
... (Decimal(46), Decimal(0))
True
>>> move = Move()
>>> move.product = product_average
>>> move.quantity = 4
>>> move.from_location = supplier_location
>>> move.to_location = customer_location
>>> move.unit_price = Decimal(5)
>>> move.cost_price = move.unit_price
>>> move.currency = currency
>>> move.state = 'done'
>>> move.save()
>>> stock_supplier.reload()
>>> (stock_supplier.debit, stock_supplier.credit) == \
... (Decimal(0), Decimal(88))
True
>>> stock_customer.reload()
>>> (stock_customer.debit, stock_customer.credit) == \
... (Decimal('66'), Decimal(0))
True