Use original cost price for returned move
and factorize the cost price of move for cost computation issue9440 review327491003
This commit is contained in:
1 parent
9d08ff5d2e
commit
c3e8df02e3
2 files changed
+31
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Use original cost price for returned move
|
||||
* Add shipping date
|
||||
* Rename sale state from cancel to cancelled
|
||||
* Add window tab for exception states
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# 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 decimal import Decimal
|
||||
from functools import wraps
|
||||
|
||||
from trytond.i18n import gettext
|
||||
@@ -8,6 +9,8 @@ from trytond.model.exceptions import AccessError
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
|
||||
from trytond.modules.product import round_price
|
||||
|
||||
|
||||
def process_sale(moves_field):
|
||||
def _process_sale(func):
|
||||
@@ -153,6 +156,33 @@ class Move(metaclass=PoolMeta):
|
||||
category = self.origin.unit.category.id
|
||||
return category
|
||||
|
||||
def get_cost_price(self, product_cost_price=None):
|
||||
pool = Pool()
|
||||
SaleLine = pool.get('sale.line')
|
||||
Sale = pool.get('sale.sale')
|
||||
# For return sale's move use the cost price of the original sale
|
||||
if (isinstance(self.origin, SaleLine)
|
||||
and self.origin.quantity < 0
|
||||
and self.from_location.type != 'storage'
|
||||
and self.to_location.type == 'storage'
|
||||
and isinstance(self.origin.origin, Sale)):
|
||||
sale = self.origin.origin
|
||||
cost = Decimal(0)
|
||||
qty = Decimal(0)
|
||||
for move in sale.moves:
|
||||
if (move.state == 'done'
|
||||
and move.from_location.type == 'storage'
|
||||
and move.to_location.type == 'customer'
|
||||
and move.product == self.product):
|
||||
move_quantity = Decimal(str(move.internal_quantity))
|
||||
cost_price = move.get_cost_price(
|
||||
product_cost_price=move.cost_price)
|
||||
qty += move_quantity
|
||||
cost += cost_price * move_quantity
|
||||
if qty:
|
||||
product_cost_price = round_price(cost / qty)
|
||||
return super().get_cost_price(product_cost_price=product_cost_price)
|
||||
|
||||
@property
|
||||
def origin_name(self):
|
||||
pool = Pool()
|
||||
|
||||
Reference in new issue
Block a user