Remove not used patch, becasue is merged in the new product cost fifo patch issues_321471002_317771007_327491003_325801002_321611002.diff
This commit is contained in:
parent
7870c63ff7
commit
8b93bac7d3
327
issue9274.diff
327
issue9274.diff
|
@ -1,327 +0,0 @@
|
|||
diff --git a/__init__.py b/__init__.py
|
||||
index 06b209f..48f9eb6 100644
|
||||
--- a/trytond/trytond/modules/product_cost_fifo/__init__.py
|
||||
+++ b/trytond/trytond/modules/product_cost_fifo/__init__.py
|
||||
@@ -1,13 +1,16 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.pool import Pool
|
||||
-from .product import *
|
||||
-from .move import *
|
||||
+from . import product
|
||||
+from . import move
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
- Template,
|
||||
- Product,
|
||||
- Move,
|
||||
+ product.Template,
|
||||
+ product.Product,
|
||||
+ move.Move,
|
||||
module='product_cost_fifo', type_='model')
|
||||
diff --git a/move.py b/move.py
|
||||
index 1d4bd63..b169ac9 100644
|
||||
--- a/trytond/trytond/modules/product_cost_fifo/move.py
|
||||
+++ b/trytond/trytond/modules/product_cost_fifo/move.py
|
||||
@@ -60,6 +60,23 @@ class Move(metaclass=PoolMeta):
|
||||
column, operator, value, expression)
|
||||
return expression
|
||||
|
||||
+ def _compute_product_cost_price(self, direction):
|
||||
+ pool = Pool()
|
||||
+ Location = pool.get('stock.location')
|
||||
+ Config = pool.get('stock.configuration')
|
||||
+
|
||||
+ configuration = Config(1)
|
||||
+ location_ids = []
|
||||
+
|
||||
+ if configuration.warehouse:
|
||||
+ locations = Location.search([
|
||||
+ ('parent', 'child_of', [configuration.warehouse]),
|
||||
+ ])
|
||||
+ location_ids = list(set(x.id for x in locations))
|
||||
+ with Transaction().set_context(locations=location_ids):
|
||||
+ self = self.__class__(self.id)
|
||||
+ return super()._compute_product_cost_price(direction)
|
||||
+
|
||||
def _update_fifo_out_product_cost_price(self):
|
||||
'''
|
||||
Update the product cost price of the given product on the move. Update
|
||||
@@ -121,6 +138,19 @@ class Move(metaclass=PoolMeta):
|
||||
cost_price = average_cost_price
|
||||
return cost_price, average_cost_price
|
||||
|
||||
+ def _get_last_cost_price(self):
|
||||
+ pool = Pool()
|
||||
+ Move = pool.get('stock.move')
|
||||
+
|
||||
+ move = None
|
||||
+ domain = self.product._domain_fifo_moves()
|
||||
+ moves = Move.search(domain, limit=1,
|
||||
+ order=[('effective_date', 'DESC'), ('id', 'DESC')])
|
||||
+ if moves:
|
||||
+ move = moves[0]
|
||||
+
|
||||
+ return move.cost_price if move else 0
|
||||
+
|
||||
def _do(self):
|
||||
cost_price = super(Move, self)._do()
|
||||
if (self.from_location.type in ('supplier', 'production')
|
||||
@@ -138,6 +168,10 @@ class Move(metaclass=PoolMeta):
|
||||
self._update_fifo_out_product_cost_price())
|
||||
if self.cost_price is None:
|
||||
self.cost_price = fifo_cost_price
|
||||
+ elif (self.from_location.type == 'customer'
|
||||
+ and self.to_location.type == 'storage'
|
||||
+ and self.product.cost_price_method == 'fifo'):
|
||||
+ cost_price = self._get_last_cost_price()
|
||||
return cost_price
|
||||
|
||||
@classmethod
|
||||
diff --git a/product.py b/product.py
|
||||
index 9eaceac..8b5aa0a 100644
|
||||
--- a/trytond/trytond/modules/product_cost_fifo/product.py
|
||||
+++ b/trytond/trytond/modules/product_cost_fifo/product.py
|
||||
@@ -24,20 +24,51 @@ class Template(metaclass=PoolMeta):
|
||||
class Product(metaclass=PoolMeta):
|
||||
__name__ = 'product.product'
|
||||
|
||||
- def _get_available_fifo_moves(self, date=None, offset=0, limit=None):
|
||||
+ def _domain_fifo_moves(self):
|
||||
pool = Pool()
|
||||
- Move = pool.get('stock.move')
|
||||
+ Location = pool.get('stock.location')
|
||||
+ Config = pool.get('stock.configuration')
|
||||
+
|
||||
+ configuration = Config(1)
|
||||
|
||||
domain = [
|
||||
('product', '=', self.id),
|
||||
self._domain_moves_cost(),
|
||||
- ('from_location.type', 'in', ['supplier', 'production']),
|
||||
- ('to_location.type', '=', 'storage'),
|
||||
+ ['OR',
|
||||
+ [
|
||||
+ ('to_location.type', '=', 'storage'),
|
||||
+ ('from_location.type', '!=', 'storage'),
|
||||
+ ],
|
||||
+ [
|
||||
+ ('from_location.type', '=', 'storage'),
|
||||
+ ('to_location.type', '!=', 'storage'),
|
||||
+ ],
|
||||
+ ],
|
||||
]
|
||||
+
|
||||
+ if configuration.warehouse:
|
||||
+ storage_locations = Location.search(['type', '=', 'storage'])
|
||||
+ locations = Location.search([
|
||||
+ ('parent', 'child_of', [configuration.warehouse]),
|
||||
+ ])
|
||||
+ location_ids = list(set(x.id for x in storage_locations) -
|
||||
+ set(x.id for x in locations))
|
||||
+ domain.extend([
|
||||
+ ('to_location.id', 'not in', location_ids),
|
||||
+ ('from_location.id', 'not in', location_ids),
|
||||
+ ])
|
||||
+ return domain
|
||||
+
|
||||
+ def _get_available_fifo_moves(self, date=None, offset=0, limit=None):
|
||||
+ pool = Pool()
|
||||
+ Move = pool.get('stock.move')
|
||||
+
|
||||
+ domain = self._domain_fifo_moves()
|
||||
if not date:
|
||||
domain.append(('fifo_quantity_available', '>', 0))
|
||||
else:
|
||||
domain.append(('effective_date', '<=', date))
|
||||
+
|
||||
return Move.search(
|
||||
domain,
|
||||
offset=offset, limit=limit,
|
||||
@@ -95,22 +126,9 @@ class Product(metaclass=PoolMeta):
|
||||
Move = pool.get('stock.move')
|
||||
Currency = pool.get('currency.currency')
|
||||
Uom = pool.get('product.uom')
|
||||
- digits = self.__class__.cost_price.digits
|
||||
|
||||
- domain = [
|
||||
- ('product', '=', self.id),
|
||||
- self._domain_moves_cost(),
|
||||
- ['OR',
|
||||
- [
|
||||
- ('to_location.type', '=', 'storage'),
|
||||
- ('from_location.type', '!=', 'storage'),
|
||||
- ],
|
||||
- [
|
||||
- ('from_location.type', '=', 'storage'),
|
||||
- ('to_location.type', '!=', 'storage'),
|
||||
- ],
|
||||
- ],
|
||||
- ]
|
||||
+ digits = self.__class__.cost_price.digits
|
||||
+ domain = self._domain_fifo_moves()
|
||||
if start:
|
||||
domain.append(('effective_date', '>=', start))
|
||||
moves = Move.search(
|
||||
@@ -135,11 +153,10 @@ class Product(metaclass=PoolMeta):
|
||||
quantity = Decimal(str(quantity))
|
||||
|
||||
def in_move(move):
|
||||
- return (move.from_location.type in ['supplier', 'production']
|
||||
- or move.to_location.type == 'supplier')
|
||||
+ return move.to_location.type == 'storage'
|
||||
|
||||
def out_move(move):
|
||||
- return not in_move(move)
|
||||
+ return move.from_location.type == 'storage'
|
||||
|
||||
def compute_fifo_cost_price(quantity, date):
|
||||
fifo_moves = self.get_fifo_move(
|
||||
@@ -150,12 +167,15 @@ class Product(metaclass=PoolMeta):
|
||||
consumed_qty = 0
|
||||
for move, move_qty in fifo_moves:
|
||||
consumed_qty += move_qty
|
||||
- with Transaction().set_context(date=move.effective_date):
|
||||
- unit_price = Currency.compute(
|
||||
- move.currency, move.unit_price,
|
||||
- move.company.currency, round=False)
|
||||
- unit_price = Uom.compute_price(
|
||||
- move.uom, unit_price, move.product.default_uom)
|
||||
+ if move.from_location.type in {'supplier', 'production'}:
|
||||
+ with Transaction().set_context(date=move.effective_date):
|
||||
+ unit_price = Currency.compute(
|
||||
+ move.currency, move.unit_price,
|
||||
+ move.company.currency, round=False)
|
||||
+ unit_price = Uom.compute_price(
|
||||
+ move.uom, unit_price, move.product.default_uom)
|
||||
+ else:
|
||||
+ unit_price = move.cost_price or 0
|
||||
cost_price += unit_price * Decimal(str(move_qty))
|
||||
if consumed_qty:
|
||||
return (cost_price / Decimal(str(consumed_qty))).quantize(
|
||||
@@ -163,7 +183,8 @@ class Product(metaclass=PoolMeta):
|
||||
|
||||
current_moves = []
|
||||
current_out_qty = 0
|
||||
- current_cost_price = cost_price
|
||||
+ current_cost_price = cost_price.quantize(
|
||||
+ Decimal(str(10.0 ** -digits[1])))
|
||||
for move in moves:
|
||||
if (current_moves
|
||||
and current_moves[-1].effective_date
|
||||
@@ -189,7 +210,7 @@ class Product(metaclass=PoolMeta):
|
||||
quantity + current_out_qty))
|
||||
- (fifo_cost_price * current_out_qty))
|
||||
/ quantity)
|
||||
- else:
|
||||
+ elif move.from_location.type != 'customer':
|
||||
cost_price = Decimal(0)
|
||||
current_cost_price = cost_price.quantize(
|
||||
Decimal(str(10.0 ** -digits[1])))
|
||||
@@ -202,12 +223,15 @@ class Product(metaclass=PoolMeta):
|
||||
if move.from_location.type == 'storage':
|
||||
qty *= -1
|
||||
if in_move(move):
|
||||
- with Transaction().set_context(date=move.effective_date):
|
||||
- unit_price = Currency.compute(
|
||||
- move.currency, move.unit_price,
|
||||
- move.company.currency, round=False)
|
||||
- unit_price = Uom.compute_price(
|
||||
- move.uom, unit_price, self.default_uom)
|
||||
+ if move.from_location.type in {'supplier', 'production'}:
|
||||
+ with Transaction().set_context(date=move.effective_date):
|
||||
+ unit_price = Currency.compute(
|
||||
+ move.currency, move.unit_price,
|
||||
+ move.company.currency, round=False)
|
||||
+ unit_price = Uom.compute_price(
|
||||
+ move.uom, unit_price, self.default_uom)
|
||||
+ else:
|
||||
+ unit_price = cost_price
|
||||
if quantity + qty > 0 and quantity >= 0:
|
||||
cost_price = (
|
||||
(cost_price * quantity) + (unit_price * qty)
|
||||
@@ -216,7 +240,7 @@ class Product(metaclass=PoolMeta):
|
||||
cost_price = unit_price
|
||||
current_cost_price = cost_price.quantize(
|
||||
Decimal(str(10.0 ** -digits[1])))
|
||||
- else:
|
||||
+ elif out_move(move):
|
||||
current_out_qty += -qty
|
||||
quantity += qty
|
||||
|
||||
diff --git a/tests/scenario_product_cost_fifo_recompute_cost_price.rst b/tests/scenario_product_cost_fifo_recompute_cost_price.rst
|
||||
index f8b952f..d4f906d 100644
|
||||
--- a/trytond/trytond/modules/product_cost_fifo/tests/scenario_product_cost_fifo_recompute_cost_price.rst
|
||||
+++ b/trytond/trytond/modules/product_cost_fifo/tests/scenario_product_cost_fifo_recompute_cost_price.rst
|
||||
@@ -45,6 +45,7 @@ Get stock locations::
|
||||
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
|
||||
>>> storage_loc, = Location.find([('code', '=', 'STO')])
|
||||
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
|
||||
+ >>> lost_found, = Location.find([('name', '=', "Lost and Found")])
|
||||
|
||||
Create some moves::
|
||||
|
||||
@@ -58,6 +59,12 @@ Create some moves::
|
||||
... effective_date=today - dt.timedelta(days=2)).click('do')
|
||||
>>> StockMove(
|
||||
... product=product,
|
||||
+ ... quantity=1,
|
||||
+ ... from_location=lost_found,
|
||||
+ ... to_location=storage_loc,
|
||||
+ ... effective_date=today - dt.timedelta(days=1)).click('do')
|
||||
+ >>> StockMove(
|
||||
+ ... product=product,
|
||||
... quantity=2,
|
||||
... from_location=supplier_loc,
|
||||
... to_location=storage_loc,
|
||||
@@ -67,8 +74,7 @@ Create some moves::
|
||||
... product=product,
|
||||
... quantity=2,
|
||||
... from_location=storage_loc,
|
||||
- ... to_location=customer_loc,
|
||||
- ... unit_price=Decimal('300'),
|
||||
+ ... to_location=lost_found,
|
||||
... effective_date=today - dt.timedelta(days=1)).click('do')
|
||||
>>> StockMove(
|
||||
... product=product,
|
||||
@@ -94,11 +100,11 @@ Create some moves::
|
||||
|
||||
|
||||
>>> [m.cost_price for m in StockMove.find([])]
|
||||
- [Decimal('100.0000'), Decimal('110.0000'), Decimal('105.0000'), Decimal('110.0000'), Decimal('113.3333'), Decimal('100.0000')]
|
||||
+ [Decimal('100.0000'), Decimal('116.6666'), Decimal('106.6666'), Decimal('110.0000'), Decimal('113.3333'), Decimal('113.3333'), Decimal('100.0000')]
|
||||
|
||||
>>> product.reload()
|
||||
>>> product.cost_price
|
||||
- Decimal('100.0000')
|
||||
+ Decimal('99.9998')
|
||||
|
||||
Recompute cost price::
|
||||
|
||||
@@ -106,11 +112,11 @@ Recompute cost price::
|
||||
>>> recompute.execute('recompute')
|
||||
|
||||
>>> [m.cost_price for m in StockMove.find([])]
|
||||
- [Decimal('106.6667'), Decimal('106.6667'), Decimal('105.0000'), Decimal('110.0000'), Decimal('113.3333'), Decimal('100.0000')]
|
||||
+ [Decimal('111.1111'), Decimal('111.1111'), Decimal('106.6666'), Decimal('110.0000'), Decimal('113.3333'), Decimal('113.3333'), Decimal('100.0000')]
|
||||
|
||||
>>> product.reload()
|
||||
>>> product.cost_price
|
||||
- Decimal('99.9999')
|
||||
+ Decimal('100.0000')
|
||||
|
||||
Recompute cost price from a date::
|
||||
|
||||
@@ -119,8 +125,8 @@ Recompute cost price from a date::
|
||||
>>> recompute.execute('recompute')
|
||||
|
||||
>>> [m.cost_price for m in StockMove.find([])]
|
||||
- [Decimal('106.6667'), Decimal('106.6667'), Decimal('105.0000'), Decimal('110.0000'), Decimal('113.3333'), Decimal('100.0000')]
|
||||
+ [Decimal('111.1111'), Decimal('111.1111'), Decimal('106.6666'), Decimal('110.0000'), Decimal('113.3333'), Decimal('113.3333'), Decimal('100.0000')]
|
||||
|
||||
>>> product.reload()
|
||||
>>> product.cost_price
|
||||
- Decimal('99.9999')
|
||||
+ Decimal('100.0000')
|
1
series
1
series
|
@ -76,6 +76,5 @@ issue9103.diff # [trytond] User-defined reports for custom template extensions
|
|||
lazy_loading.diff # [trytond] lazy loading of id, create_date, write_date on many2one
|
||||
cost_price_in_productions_without_inputs.diff # [production]
|
||||
#fifo_cost_price_formula.diff # [product_cost_fio] change formula to avoid minus zero cost_price
|
||||
#issue9274.diff # [product_cost_fifo] take care on inventory moves:
|
||||
issues_321471002_317771007_327491003_325801002_321611002.diff # [product_cost_fifo, sale, stock] take care on inventory moves
|
||||
issue7280.diff # [account_invoice_stock] + [account_stock_landed_cost] Update unit price of stock moves based on posted invoice lines
|
||||
|
|
Loading…
Reference in New Issue