diff --git a/CHANGELOG b/CHANGELOG index 98cb01726c..78b42521f3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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" diff --git a/stock.py b/stock.py index aa7bbb9cad..5b06ebf78e 100644 --- a/stock.py +++ b/stock.py @@ -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)) diff --git a/tests/scenario_account_stock_continental.rst b/tests/scenario_account_stock_continental.rst index 6af7fee3e4..af1fe7978d 100644 --- a/tests/scenario_account_stock_continental.rst +++ b/tests/scenario_account_stock_continental.rst @@ -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