diff --git a/CHANGELOG b/CHANGELOG index 6930506437..fdebd408f1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 --git a/move.py b/move.py index b4792908ef..5bc753497f 100644 --- a/move.py +++ b/move.py @@ -170,11 +170,15 @@ class Move(Workflow, ModelSQL, ModelView): 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 @@ class Move(Workflow, ModelSQL, ModelView): 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 --git a/tests/scenario_stock_average_cost_price.rst b/tests/scenario_stock_average_cost_price.rst index ac695a3825..8223c5cd66 100644 --- a/tests/scenario_stock_average_cost_price.rst +++ b/tests/scenario_stock_average_cost_price.rst @@ -162,6 +162,7 @@ Send one product we don't have in stock:: >>> 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 @@ Return one product to the supplier:: >>> 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 @@ Receive one unit of the product with negative stock so the stock stays negative: >>> 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 @@ Receive two units of the product so the stock becomes positive:: >>> 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 --git a/tests/scenario_stock_shipment_in_same_storage_input.rst b/tests/scenario_stock_shipment_in_same_storage_input.rst index 3d17bcdf97..7b684250ef 100644 --- a/tests/scenario_stock_shipment_in_same_storage_input.rst +++ b/tests/scenario_stock_shipment_in_same_storage_input.rst @@ -63,6 +63,7 @@ Create Shipment In:: >>> 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 --git a/tests/scenario_stock_shipment_out_same_storage_output.rst b/tests/scenario_stock_shipment_out_same_storage_output.rst index e6fa77d0ac..a4e4f5bd85 100644 --- a/tests/scenario_stock_shipment_out_same_storage_output.rst +++ b/tests/scenario_stock_shipment_out_same_storage_output.rst @@ -59,6 +59,7 @@ Create Shipment Out:: >>> 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()