Don't set default unit price on stock move

issue8119
review255251002
This commit is contained in:
Cédric Krier
2019-04-23 09:10:22 +02:00
parent 2d82ff8abb
commit 08e5893595
5 changed files with 18 additions and 44 deletions
+1
View File
@@ -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
+11 -44
View File
@@ -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
@@ -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
@@ -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()
@@ -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()