Reviewers: ,


Please review this at http://codereview.tryton.org/237005/

Affected files:
  M stock.py
  M tests/scenario_account_stock_continental.rst


Index: stock.py
===================================================================

--- a/stock.py
+++ b/stock.py
@@ -53,6 +53,8 @@
             '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 @@
             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 @@
         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))

Index: tests/scenario_account_stock_continental.rst
===================================================================

--- a/tests/scenario_account_stock_continental.rst
+++ b/tests/scenario_account_stock_continental.rst
@@ -335,3 +335,42 @@
     >>> (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.currency = currency
+    >>> move.state = 'done'
+    >>> move.save()
+    >>> stock_supplier.reload()
+    >>> (stock_supplier.debit, stock_supplier.credit) == \
+    ... (Decimal(0), Decimal(65))
+    True
+    >>> stock_customer.reload()
+    >>> (stock_customer.debit, stock_customer.credit) == \
+    ... (Decimal(43), 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.currency = currency
+    >>> move.state = 'done'
+    >>> move.save()
+    >>> stock_supplier.reload()
+    >>> (stock_supplier.debit, stock_supplier.credit) == \
+    ... (Decimal(0), Decimal(85))
+    True
+    >>> stock_customer.reload()
+    >>> (stock_customer.debit, stock_customer.credit) == \
+    ... (Decimal('63.80'), Decimal(0))
+    True



--
[email protected] mailing list

Reply via email to