Move cost price to product level instead of template

issue6515
review41321002
This commit is contained in:
Cédric Krier committed 2017-07-05 14:51:50 +02:00
1 parent a81448cf9a
commit f132407fc0
9 files changed
+32 -79

No files matched your search

+4 -15
View File
@@ -548,7 +548,6 @@ class Move(Workflow, ModelSQL, ModelView):
pool = Pool()
Uom = pool.get('product.uom')
Product = pool.get('product.product')
ProductTemplate = pool.get('product.template')
Location = pool.get('stock.location')
Currency = pool.get('currency.currency')
Date = pool.get('ir.date')
@@ -568,11 +567,7 @@ class Move(Workflow, ModelSQL, ModelView):
qty = Uom.compute_qty(self.uom, quantity, product.default_uom)
qty = Decimal(str(qty))
if not isinstance(Product.cost_price, TemplateFunction):
product_qty = product.quantity
else:
product_qty = product.template.quantity
product_qty = Decimal(str(max(product_qty, 0)))
product_qty = Decimal(str(max(product.quantity, 0)))
# convert wrt currency
with Transaction().set_context(date=self.effective_date):
unit_price = Currency.compute(self.currency, self.unit_price,
@@ -587,18 +582,12 @@ class Move(Workflow, ModelSQL, ModelView):
else:
new_cost_price = product.cost_price
if not isinstance(Product.cost_price, TemplateFunction):
digits = Product.cost_price.digits
write = partial(Product.write, [product])
else:
digits = ProductTemplate.cost_price.digits
write = partial(ProductTemplate.write, [product.template])
digits = Product.cost_price.digits
new_cost_price = new_cost_price.quantize(
Decimal(str(10.0 ** -digits[1])))
write({
'cost_price': new_cost_price,
})
product.set_multivalue(
'cost_price', new_cost_price, company=self.company.id)
@staticmethod
def _get_internal_quantity(quantity, uom, product):
+3 -14
View File
@@ -185,18 +185,7 @@ class Product(StockMixin, object):
@classmethod
def recompute_cost_price(cls, products):
pool = Pool()
Template = pool.get('product.template')
if not isinstance(cls.cost_price, TemplateFunction):
digits = cls.cost_price.digits
write = cls.write
record = lambda p: p
else:
digits = Template.cost_price.digits
write = Template.write
record = lambda p: p.template
digits = cls.cost_price.digits
costs = defaultdict(list)
for product in products:
if product.type == 'service':
@@ -204,7 +193,7 @@ class Product(StockMixin, object):
cost = getattr(product,
'recompute_cost_price_%s' % product.cost_price_method)()
cost = cost.quantize(Decimal(str(10.0 ** -digits[1])))
costs[cost].append(record(product))
costs[cost].append(product)
if not costs:
return
@@ -216,7 +205,7 @@ class Product(StockMixin, object):
# Enforce check access for account_stock*
with Transaction().set_context(_check_access=True):
write(*to_write)
cls.write(*to_write)
def recompute_cost_price_fixed(self):
return self.cost_price
+16 -16
View File
@@ -28,28 +28,28 @@ Create product::
>>> ProductTemplate = Model.get('product.template')
>>> Product = Model.get('product.product')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> product = Product()
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('300')
>>> template.cost_price = Decimal('80')
>>> template.cost_price_method = 'average'
>>> product, = template.products
>>> product.cost_price = Decimal('80')
>>> template.save()
>>> product.template = template
>>> product.save()
>>> negative_product = Product()
>>> product, = template.products
>>> template = ProductTemplate()
>>> template.name = 'Negative Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('28')
>>> template.cost_price = Decimal('5')
>>> template.cost_price_method = 'average'
>>> negative_product, = template.products
>>> negative_product.cost_price = Decimal('5')
>>> template.save()
>>> negative_product.template = template
>>> negative_product.save()
>>> negative_product, = template.products
Get stock locations::
@@ -77,7 +77,7 @@ Make 1 unit of the product available @ 100 ::
Check Cost Price is 100::
>>> product.reload()
>>> product.template.cost_price
>>> product.cost_price
Decimal('100.0000')
Add 1 more unit @ 200::
@@ -98,7 +98,7 @@ Add 1 more unit @ 200::
Check Cost Price Average is 150::
>>> product.reload()
>>> product.template.cost_price
>>> product.cost_price
Decimal('150.0000')
Add twice 1 more unit @ 200::
@@ -137,20 +137,20 @@ Add twice 1 more unit @ 200::
Check Cost Price Average is 175::
>>> product.reload()
>>> product.template.cost_price
>>> product.cost_price
Decimal('175.0000')
Change Cost Price to 125, to force to write recomputed price later::
>>> product.template.cost_price = Decimal('125.0000')
>>> product.template.save()
>>> product.template.cost_price
>>> product.cost_price = Decimal('125.0000')
>>> product.save()
>>> product.cost_price
Decimal('125.0000')
Recompute Cost Price::
>>> recompute = Wizard('product.recompute_cost_price', [product])
>>> product.template.cost_price
>>> product.cost_price
Decimal('175.0000')
Send one product we dont have in stock::
@@ -184,5 +184,5 @@ Recieve two units of the product with negative stock::
Cost price should be set to 2::
>>> negative_product.template.cost_price
>>> negative_product.cost_price
Decimal('2.0000')
+5 -2
View File
@@ -33,14 +33,16 @@ Create products::
>>> ProductUom = Model.get('product.uom')
>>> ProductTemplate = Model.get('product.template')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('300')
>>> template.cost_price = Decimal('80')
>>> template.cost_price_method = 'average'
>>> product, = template.products
>>> product.cost_price = Decimal('80')
>>> template.save()
>>> product, = template.products
@@ -50,8 +52,9 @@ Create products::
>>> template2.default_uom = kg
>>> template2.type = 'goods'
>>> template2.list_price = Decimal('140')
>>> template2.cost_price = Decimal('60')
>>> template2.cost_price_method = 'average'
>>> product2, = template2.products
>>> product2.cost_price = Decimal('60')
>>> template2.save()
>>> product2, = template2.products
+1 -4
View File
@@ -37,16 +37,13 @@ Create product::
>>> ProductTemplate = Model.get('product.template')
>>> Product = Model.get('product.product')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> product = Product()
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('20')
>>> template.cost_price = Decimal('8')
>>> template.save()
>>> product.template = template
>>> product.save()
>>> product, = template.products
Get stock locations::
+1 -4
View File
@@ -30,16 +30,13 @@ Create product::
>>> ProductTemplate = Model.get('product.template')
>>> Product = Model.get('product.product')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> product = Product()
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('20')
>>> template.cost_price = Decimal('8')
>>> template.save()
>>> product.template = template
>>> product.save()
>>> product, = template.products
Get stock locations::
+1 -4
View File
@@ -35,16 +35,13 @@ Create product::
>>> ProductTemplate = Model.get('product.template')
>>> Product = Model.get('product.product')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> product = Product()
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('20')
>>> template.cost_price = Decimal('8')
>>> template.save()
>>> product.template = template
>>> product.save()
>>> product, = template.products
Create stock user::
@@ -31,16 +31,13 @@ Create product::
>>> ProductTemplate = Model.get('product.template')
>>> Product = Model.get('product.product')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> product = Product()
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('20')
>>> template.cost_price = Decimal('8')
>>> template.save()
>>> product.template = template
>>> product.save()
>>> product, = template.products
Get stock locations::
-16
View File
@@ -40,8 +40,6 @@ class StockTestCase(ModuleTestCase):
'name': 'Test Move.internal_quantity',
'type': 'goods',
'list_price': Decimal(1),
'cost_price': Decimal(0),
'cost_price_method': 'fixed',
'default_uom': kg.id,
}])
product, = Product.create([{
@@ -98,8 +96,6 @@ class StockTestCase(ModuleTestCase):
'name': 'Test products_by_location',
'type': 'goods',
'list_price': Decimal(0),
'cost_price': Decimal(0),
'cost_price_method': 'fixed',
'default_uom': kg.id,
}])
product, = Product.create([{
@@ -364,8 +360,6 @@ class StockTestCase(ModuleTestCase):
'name': 'Test products_by_location',
'type': 'goods',
'list_price': Decimal(0),
'cost_price': Decimal(0),
'cost_price_method': 'fixed',
'default_uom': unit.id,
}])
product, = Product.create([{
@@ -452,10 +446,8 @@ class StockTestCase(ModuleTestCase):
template, = Template.create([{
'name': 'Test period',
'type': 'goods',
'cost_price_method': 'fixed',
'default_uom': unit.id,
'list_price': Decimal(0),
'cost_price': Decimal(0),
}])
product, = Product.create([{
'template': template.id,
@@ -624,8 +616,6 @@ class StockTestCase(ModuleTestCase):
'name': 'Test Move.check_origin',
'type': 'goods',
'list_price': Decimal(1),
'cost_price': Decimal(0),
'cost_price_method': 'fixed',
'default_uom': uom.id,
}])
product, = Product.create([{
@@ -676,8 +666,6 @@ class StockTestCase(ModuleTestCase):
name='Test Move.assign_try',
type='goods',
list_price=Decimal(1),
cost_price=Decimal(0),
cost_price_method='fixed',
default_uom=uom,
)
template.save()
@@ -743,8 +731,6 @@ class StockTestCase(ModuleTestCase):
name='Test Move.assign_try',
type='goods',
list_price=Decimal(1),
cost_price=Decimal(0),
cost_price_method='fixed',
default_uom=uom,
)
template.save()
@@ -810,8 +796,6 @@ class StockTestCase(ModuleTestCase):
name="Product",
type='goods',
list_price=Decimal(1),
cost_price=Decimal(1),
cost_price_method='fixed',
default_uom=unit,
)
template.save()