2013-04-29 16:07:21 +02:00
|
|
|
# This file is part of product_special_price module for Tryton.
|
|
|
|
# The COPYRIGHT file at the top level of this repository contains the full
|
|
|
|
# copyright notices and license terms.
|
|
|
|
from trytond.pool import Pool, PoolMeta
|
|
|
|
from trytond.model import fields
|
|
|
|
from trytond.pyson import Eval
|
|
|
|
from trytond.transaction import Transaction
|
2014-11-07 14:32:43 +01:00
|
|
|
from trytond.config import config
|
2014-11-26 13:20:39 +01:00
|
|
|
DIGITS = int(config.get('digits', 'unit_price_digits', 4))
|
2013-04-29 16:07:21 +02:00
|
|
|
|
|
|
|
__all__ = ['Template', 'Product']
|
|
|
|
__metaclass__ = PoolMeta
|
|
|
|
|
|
|
|
STATES = {
|
|
|
|
'readonly': ~Eval('active', True),
|
|
|
|
}
|
|
|
|
DEPENDS = ['active']
|
|
|
|
|
|
|
|
|
|
|
|
class Template:
|
|
|
|
__name__ = 'product.template'
|
|
|
|
special_price = fields.Property(fields.Numeric('Special Price',
|
2014-10-28 13:10:13 +01:00
|
|
|
states=STATES, digits=(16, DIGITS), depends=DEPENDS))
|
2014-05-06 18:52:46 +02:00
|
|
|
special_price_from = fields.Date('Special Price From')
|
|
|
|
special_price_to = fields.Date('Special Price To')
|
2013-04-29 16:07:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Product:
|
|
|
|
__name__ = 'product.product'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_sale_price(cls, products, quantity=0):
|
2014-06-08 16:37:25 +02:00
|
|
|
pool = Pool()
|
|
|
|
Date = pool.get('ir.date')
|
|
|
|
User = pool.get('res.user')
|
|
|
|
Uom = pool.get('product.uom')
|
2014-05-06 18:52:46 +02:00
|
|
|
|
2013-04-29 16:07:21 +02:00
|
|
|
prices = super(Product, cls).get_sale_price(products, quantity)
|
2014-05-15 11:32:42 +02:00
|
|
|
|
|
|
|
if Transaction().context.get('without_special_price'):
|
|
|
|
return prices
|
2013-08-28 17:37:33 +02:00
|
|
|
|
2014-11-06 00:23:05 +01:00
|
|
|
today = Date.today()
|
|
|
|
user = User(Transaction().user)
|
|
|
|
if user.shop and user.shop.special_price:
|
|
|
|
for product in products:
|
|
|
|
if product.special_price_from and product.special_price_to:
|
|
|
|
if not (product.special_price_from <= today <= product.special_price_to):
|
|
|
|
continue
|
|
|
|
special_price = 0.0
|
|
|
|
if user.shop.type_special_price == 'pricelist':
|
2015-07-06 14:07:07 +02:00
|
|
|
customer = Transaction().context.get('customer')
|
|
|
|
if customer:
|
|
|
|
price_list = user.shop.special_pricelist
|
|
|
|
uom_id = Transaction().context.get('uom', None)
|
|
|
|
if uom_id:
|
|
|
|
uom = Uom(uom_id)
|
|
|
|
else:
|
|
|
|
uom = product.default_uom
|
|
|
|
special_price = price_list.compute(customer, product,
|
|
|
|
prices[product.id], quantity, uom)
|
2014-11-06 00:23:05 +01:00
|
|
|
else:
|
|
|
|
special_price = product.special_price
|
2013-08-28 17:37:33 +02:00
|
|
|
|
2014-11-06 00:23:05 +01:00
|
|
|
if special_price != 0.0 and special_price != None and \
|
|
|
|
special_price < prices[product.id]:
|
|
|
|
prices[product.id] = special_price
|
2013-04-29 16:07:21 +02:00
|
|
|
return prices
|