changeset 11a985b94085 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=11a985b94085
description:
        Don't set default unit price on stock move

        issue8119
        review255251002
diffstat:

 CHANGELOG                                                 |   1 +
 move.py                                                   |  55 +++------------
 tests/scenario_stock_average_cost_price.rst               |   4 +
 tests/scenario_stock_shipment_in_same_storage_input.rst   |   1 +
 tests/scenario_stock_shipment_out_same_storage_output.rst |   1 +
 5 files changed, 18 insertions(+), 44 deletions(-)

diffs (148 lines):

diff -r 43ae98c5fc93 -r 11a985b94085 CHANGELOG
--- a/CHANGELOG Sun Apr 14 16:36:00 2019 +0200
+++ b/CHANGELOG Tue Apr 23 09:10:22 2019 +0200
@@ -1,3 +1,4 @@
+* Don't set default unit price on stock move
 * Prefer to pick product from the source location
 * Change move attribute of ShipmentReport for a method
 * Rename inventory count quantity_resulting to total_quantity
diff -r 43ae98c5fc93 -r 11a985b94085 move.py
--- a/move.py   Sun Apr 14 16:36:00 2019 +0200
+++ b/move.py   Tue Apr 23 09:10:22 2019 +0200
@@ -170,11 +170,15 @@
     product_uom_category = fields.Function(
         fields.Many2One('product.uom.category', 'Product Uom Category'),
         'on_change_with_product_uom_category')
-    uom = fields.Many2One("product.uom", "Uom", required=True, states=STATES,
+    uom = fields.Many2One("product.uom", "Uom", required=True,
+        states={
+            'readonly': (Eval('state').in_(['cancel', 'assigned', 'done'])
+                | Eval('unit_price')),
+            },
         domain=[
             ('category', '=', Eval('product_uom_category')),
             ],
-        depends=['state', 'product_uom_category'],
+        depends=['state', 'unit_price', 'product_uom_category'],
         help="The unit in which the quantity is specified.")
     unit_digits = fields.Function(fields.Integer('Unit Digits'),
         'on_change_with_unit_digits')
@@ -358,56 +362,19 @@
             return self.uom.digits
         return 2
 
-    @fields.depends('product', 'currency', 'uom', 'company', 'from_location',
-        'to_location')
+    @fields.depends('product', 'uom')
     def on_change_product(self):
-        pool = Pool()
-        Uom = pool.get('product.uom')
-        Currency = pool.get('currency.currency')
-
-        self.unit_price = Decimal('0.0')
         if self.product:
-            self.uom = self.product.default_uom
-            self.unit_digits = self.product.default_uom.digits
-            unit_price = None
-            if self.from_location and self.from_location.type in ('supplier',
-                    'production'):
-                unit_price = self.product.cost_price
-            elif self.to_location and self.to_location.type == 'customer':
-                unit_price = self.product.list_price
-            if unit_price:
-                if self.uom != self.product.default_uom:
-                    unit_price = Uom.compute_price(self.product.default_uom,
-                        unit_price, self.uom)
-                if self.currency and self.company:
-                    unit_price = Currency.compute(self.company.currency,
-                        unit_price, self.currency, round=False)
-                self.unit_price = unit_price
+            if (not self.uom
+                    or self.uom.category != self.product.default_uom.category):
+                self.uom = self.product.default_uom
+                self.unit_digits = self.product.default_uom.digits
 
     @fields.depends('product')
     def on_change_with_product_uom_category(self, name=None):
         if self.product:
             return self.product.default_uom_category.id
 
-    @fields.depends('product', 'currency', 'uom', 'company', 'from_location',
-        'to_location')
-    def on_change_uom(self):
-        pool = Pool()
-        Uom = pool.get('product.uom')
-        Currency = pool.get('currency.currency')
-
-        self.unit_price = Decimal('0.0')
-        if self.product:
-            if self.to_location and self.to_location.type == 'storage':
-                unit_price = self.product.cost_price
-                if self.uom and self.uom != self.product.default_uom:
-                    unit_price = Uom.compute_price(self.product.default_uom,
-                        unit_price, self.uom)
-                if self.currency and self.company:
-                    unit_price = Currency.compute(self.company.currency,
-                        unit_price, self.currency, round=False)
-                self.unit_price = unit_price
-
     @fields.depends('from_location', 'to_location')
     def on_change_with_unit_price_required(self, name=None):
         from_type = self.from_location.type if self.from_location else None
diff -r 43ae98c5fc93 -r 11a985b94085 tests/scenario_stock_average_cost_price.rst
--- a/tests/scenario_stock_average_cost_price.rst       Sun Apr 14 16:36:00 
2019 +0200
+++ b/tests/scenario_stock_average_cost_price.rst       Tue Apr 23 09:10:22 
2019 +0200
@@ -162,6 +162,7 @@
     >>> outgoing_move.product = negative_product
     >>> outgoing_move.uom = unit
     >>> outgoing_move.quantity = 1
+    >>> outgoing_move.unit_price = Decimal('28')
     >>> outgoing_move.from_location = storage_loc
     >>> outgoing_move.to_location = customer_loc
     >>> outgoing_move.planned_date = today
@@ -181,6 +182,7 @@
     >>> outgoing_move.product = negative_product
     >>> outgoing_move.uom = unit
     >>> outgoing_move.quantity = 1
+    >>> outgoing_move.unit_price = Decimal('28')
     >>> outgoing_move.from_location = storage_loc
     >>> outgoing_move.to_location = supplier_loc
     >>> outgoing_move.planned_date = today
@@ -200,6 +202,7 @@
     >>> incoming_move.product = negative_product
     >>> incoming_move.uom = unit
     >>> incoming_move.quantity = 1
+    >>> outgoing_move.unit_price = Decimal('28')
     >>> incoming_move.from_location = supplier_loc
     >>> incoming_move.to_location = storage_loc
     >>> incoming_move.planned_date = today
@@ -221,6 +224,7 @@
     >>> incoming_move.product = negative_product
     >>> incoming_move.uom = unit
     >>> incoming_move.quantity = 2
+    >>> outgoing_move.unit_price = Decimal('28')
     >>> incoming_move.from_location = supplier_loc
     >>> incoming_move.to_location = storage_loc
     >>> incoming_move.planned_date = today
diff -r 43ae98c5fc93 -r 11a985b94085 
tests/scenario_stock_shipment_in_same_storage_input.rst
--- a/tests/scenario_stock_shipment_in_same_storage_input.rst   Sun Apr 14 
16:36:00 2019 +0200
+++ b/tests/scenario_stock_shipment_in_same_storage_input.rst   Tue Apr 23 
09:10:22 2019 +0200
@@ -63,6 +63,7 @@
     >>> move.product = product
     >>> move.uom = unit
     >>> move.quantity = 1
+    >>> move.unit_price = Decimal('5')
     >>> move.from_location = supplier_loc
     >>> move.to_location = storage1
     >>> shipment_in.save()
diff -r 43ae98c5fc93 -r 11a985b94085 
tests/scenario_stock_shipment_out_same_storage_output.rst
--- a/tests/scenario_stock_shipment_out_same_storage_output.rst Sun Apr 14 
16:36:00 2019 +0200
+++ b/tests/scenario_stock_shipment_out_same_storage_output.rst Tue Apr 23 
09:10:22 2019 +0200
@@ -59,6 +59,7 @@
     >>> move.product = product
     >>> move.uom = unit
     >>> move.quantity = 1
+    >>> move.unit_price = Decimal('5')
     >>> move.from_location = storage_loc
     >>> move.to_location = customer_loc
     >>> shipment_out.save()

Reply via email to