first commit
This commit is contained in:
2
modules/product_price_list_dates/__init__.py
Normal file
2
modules/product_price_list_dates/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19
modules/product_price_list_dates/locale/bg.po
Normal file
19
modules/product_price_list_dates/locale/bg.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
19
modules/product_price_list_dates/locale/ca.po
Normal file
19
modules/product_price_list_dates/locale/ca.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Data final"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Data inicial"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
19
modules/product_price_list_dates/locale/cs.po
Normal file
19
modules/product_price_list_dates/locale/cs.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
19
modules/product_price_list_dates/locale/de.po
Normal file
19
modules/product_price_list_dates/locale/de.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Enddatum"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Startdatum"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Datum"
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Datum"
|
||||
19
modules/product_price_list_dates/locale/es.po
Normal file
19
modules/product_price_list_dates/locale/es.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Fecha fin"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Fecha inicial"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Fecha"
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Fecha"
|
||||
19
modules/product_price_list_dates/locale/es_419.po
Normal file
19
modules/product_price_list_dates/locale/es_419.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
20
modules/product_price_list_dates/locale/et.po
Normal file
20
modules/product_price_list_dates/locale/et.po
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Lõppkuupäev"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Alguskuupäev"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Kuupäev"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Kuupäev"
|
||||
20
modules/product_price_list_dates/locale/fa.po
Normal file
20
modules/product_price_list_dates/locale/fa.po
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "تاریخ پایان"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "تاریخ شروع"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "تاریخ"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "تاریخ"
|
||||
19
modules/product_price_list_dates/locale/fi.po
Normal file
19
modules/product_price_list_dates/locale/fi.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
19
modules/product_price_list_dates/locale/fr.po
Normal file
19
modules/product_price_list_dates/locale/fr.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Date de fin"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Date de début"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Date"
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Date"
|
||||
19
modules/product_price_list_dates/locale/hu.po
Normal file
19
modules/product_price_list_dates/locale/hu.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
20
modules/product_price_list_dates/locale/id.po
Normal file
20
modules/product_price_list_dates/locale/id.po
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Tanggal Akhir"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Tanggal Awal"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Tanggal"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Tanggal"
|
||||
19
modules/product_price_list_dates/locale/it.po
Normal file
19
modules/product_price_list_dates/locale/it.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Data fine"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Data inizio"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
20
modules/product_price_list_dates/locale/lo.po
Normal file
20
modules/product_price_list_dates/locale/lo.po
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "ວັນທີສິ້ນສຸດ"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "ວັນທີເລີ່ມ"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "ວັນທີ"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "ວັນທີ"
|
||||
20
modules/product_price_list_dates/locale/lt.po
Normal file
20
modules/product_price_list_dates/locale/lt.po
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Pabaigos data"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Pradžios data"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Pabaigos data"
|
||||
19
modules/product_price_list_dates/locale/nl.po
Normal file
19
modules/product_price_list_dates/locale/nl.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Eind datum"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Start datum"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Datum"
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Datum"
|
||||
20
modules/product_price_list_dates/locale/pl.po
Normal file
20
modules/product_price_list_dates/locale/pl.po
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Data ukończenia"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Data rozpoczęcia"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
19
modules/product_price_list_dates/locale/pt.po
Normal file
19
modules/product_price_list_dates/locale/pt.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Data Final"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Data de Início"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
19
modules/product_price_list_dates/locale/ro.po
Normal file
19
modules/product_price_list_dates/locale/ro.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Data de încheiere"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Data de început"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
19
modules/product_price_list_dates/locale/ru.po
Normal file
19
modules/product_price_list_dates/locale/ru.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
20
modules/product_price_list_dates/locale/sl.po
Normal file
20
modules/product_price_list_dates/locale/sl.po
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Konec veljavnosti"
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Pričetek veljavnosti"
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Datum"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr "Datum"
|
||||
19
modules/product_price_list_dates/locale/tr.po
Normal file
19
modules/product_price_list_dates/locale/tr.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
19
modules/product_price_list_dates/locale/uk.po
Normal file
19
modules/product_price_list_dates/locale/uk.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
19
modules/product_price_list_dates/locale/zh_CN.po
Normal file
19
modules/product_price_list_dates/locale/zh_CN.po
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:product.price_list.line,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.price_list.line.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "field:product.sale.context,date:"
|
||||
msgid "Date"
|
||||
msgstr ""
|
||||
131
modules/product_price_list_dates/product.py
Normal file
131
modules/product_price_list_dates/product.py
Normal file
@@ -0,0 +1,131 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
import datetime as dt
|
||||
|
||||
import trytond.config as config
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Date, Eval, If, PYSONDecoder, PYSONEncoder
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class PriceList(metaclass=PoolMeta):
|
||||
__name__ = 'product.price_list'
|
||||
|
||||
@classmethod
|
||||
@ModelView.button_action(
|
||||
'product_price_list.act_price_list_line_form')
|
||||
def open_lines(cls, price_lists):
|
||||
encoder = PYSONEncoder()
|
||||
decoder = PYSONDecoder(noeval=True)
|
||||
action = super().open_lines(price_lists)
|
||||
context_domain = [
|
||||
['OR',
|
||||
('start_date', '=', None),
|
||||
('start_date', '<=', Eval('date', Date())),
|
||||
],
|
||||
['OR',
|
||||
('end_date', '=', None),
|
||||
('end_date', '>=', Eval('date', Date())),
|
||||
],
|
||||
]
|
||||
if isinstance(action, dict):
|
||||
if action.get('context_domain'):
|
||||
context_domain = [
|
||||
decoder.decode(action['context_domain']),
|
||||
context_domain]
|
||||
action['context_domain'] = encoder.encode(context_domain)
|
||||
else:
|
||||
action = {
|
||||
'context_domain': encoder.encode(context_domain),
|
||||
}
|
||||
return action
|
||||
|
||||
def compute(self, product, quantity, uom, pattern=None):
|
||||
context = Transaction().context
|
||||
pattern = pattern.copy() if pattern is not None else {}
|
||||
pattern.setdefault('date', context.get('date'))
|
||||
return super().compute(product, quantity, uom, pattern=pattern)
|
||||
|
||||
|
||||
class PriceListCache(metaclass=PoolMeta):
|
||||
__name__ = 'product.price_list.cache'
|
||||
|
||||
@classmethod
|
||||
def patterns(cls, price_list, product):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
today = Date.today()
|
||||
for pattern in super().patterns(price_list, product):
|
||||
if pattern is None:
|
||||
pattern = {}
|
||||
for days in range(config.getint(
|
||||
'product_price_list_dates', 'cache_days', default=2)):
|
||||
pattern['date'] = today + dt.timedelta(days=days)
|
||||
yield pattern
|
||||
|
||||
@classmethod
|
||||
def get(cls, price_list, product, pattern=None):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
context = Transaction().context
|
||||
today = Date.today()
|
||||
pattern = pattern.copy() if pattern else {}
|
||||
pattern['date'] = pattern.get('date', context.get('date')) or today
|
||||
return super().get(price_list, product, pattern=pattern)
|
||||
|
||||
|
||||
class PriceListLine(metaclass=PoolMeta):
|
||||
__name__ = 'product.price_list.line'
|
||||
|
||||
start_date = fields.Date(
|
||||
"Start Date",
|
||||
domain=[
|
||||
If(Eval('start_date') & Eval('end_date'),
|
||||
('start_date', '<=', Eval('end_date')),
|
||||
()),
|
||||
])
|
||||
end_date = fields.Date(
|
||||
"End Date",
|
||||
domain=[
|
||||
If(Eval('start_date') & Eval('end_date'),
|
||||
('end_date', '>=', Eval('start_date')),
|
||||
()),
|
||||
])
|
||||
|
||||
def match(self, pattern):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
pattern = pattern.copy()
|
||||
date = pattern.pop('date', None) or Date.today()
|
||||
if self.start_date and self.start_date > date:
|
||||
return False
|
||||
if self.end_date and self.end_date < date:
|
||||
return False
|
||||
return super().match(pattern)
|
||||
|
||||
|
||||
class PriceListLineContext(metaclass=PoolMeta):
|
||||
__name__ = 'product.price_list.line.context'
|
||||
|
||||
date = fields.Date("Date")
|
||||
|
||||
@classmethod
|
||||
def default_date(cls):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
return Date.today()
|
||||
|
||||
|
||||
class SaleContext(metaclass=PoolMeta):
|
||||
__name__ = 'product.sale.context'
|
||||
|
||||
date = fields.Function(
|
||||
fields.Date("Date"),
|
||||
'on_change_with_date')
|
||||
|
||||
@fields.depends('sale_date')
|
||||
def on_change_with_date(self, name=None):
|
||||
return self.sale_date
|
||||
43
modules/product_price_list_dates/product.xml
Normal file
43
modules/product_price_list_dates/product.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="price_list_line_view_form">
|
||||
<field name="model">product.price_list.line</field>
|
||||
<field name="inherit"
|
||||
ref="product_price_list.price_list_line_view_form"/>
|
||||
<field name="name">price_list_line_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="price_list_line_view_tree">
|
||||
<field name="model">product.price_list.line</field>
|
||||
<field name="inherit"
|
||||
ref="product_price_list.price_list_line_view_tree"/>
|
||||
<field name="name">price_list_line_tree</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="price_list_line_view_tree_sequence">
|
||||
<field name="model">product.price_list.line</field>
|
||||
<field name="inherit"
|
||||
ref="product_price_list.price_list_line_view_tree_sequence"/>
|
||||
<field name="name">price_list_line_tree_sequence</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="price_list_line_context_view_form">
|
||||
<field name="model">product.price_list.line.context</field>
|
||||
<!-- Migration from 7.2: Force empty type for inherit -->
|
||||
<field name="type" eval="None"/>
|
||||
<field name="inherit" ref="product_price_list.price_list_line_context_view_form"/>
|
||||
<field name="name">price_list_line_context_form</field>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
<data depends="sale_price_list">
|
||||
<record model="ir.ui.view" id="product_sale_context_view_form">
|
||||
<field name="model">product.sale.context</field>
|
||||
<field name="inherit" ref="sale.product_sale_context_view_form"/>
|
||||
<field name="name">product_sale_context_form</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
22
modules/product_price_list_dates/purchase.py
Normal file
22
modules/product_price_list_dates/purchase.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# 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.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
|
||||
|
||||
class Line(metaclass=PoolMeta):
|
||||
__name__ = 'purchase.line'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.product.search_context['date'] = Eval(
|
||||
'_parent_purchase', {}).get('purchase_date')
|
||||
|
||||
@fields.depends('purchase', '_parent_purchase.purchase_date')
|
||||
def _get_context_purchase_price(self):
|
||||
context = super()._get_context_purchase_price()
|
||||
if self.purchase:
|
||||
context.setdefault('date', self.purchase.purchase_date)
|
||||
return context
|
||||
22
modules/product_price_list_dates/sale.py
Normal file
22
modules/product_price_list_dates/sale.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# 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.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
|
||||
|
||||
class Line(metaclass=PoolMeta):
|
||||
__name__ = 'sale.line'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.product.search_context['date'] = Eval(
|
||||
'_parent_sale', {}).get('sale_date')
|
||||
|
||||
@fields.depends('sale', '_parent_sale.sale_date')
|
||||
def _get_context_sale_price(self):
|
||||
context = super()._get_context_sale_price()
|
||||
if self.sale:
|
||||
context.setdefault('date', self.sale.sale_date)
|
||||
return context
|
||||
2
modules/product_price_list_dates/tests/__init__.py
Normal file
2
modules/product_price_list_dates/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
153
modules/product_price_list_dates/tests/test_module.py
Normal file
153
modules/product_price_list_dates/tests/test_module.py
Normal file
@@ -0,0 +1,153 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from trytond.modules.company.tests import (
|
||||
CompanyTestMixin, create_company, set_company)
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class ProductPriceListDatesTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Product Price List Dates module'
|
||||
module = 'product_price_list_dates'
|
||||
extras = [
|
||||
'product_price_list_cache', 'sale_price_list', 'purchase_price_list']
|
||||
|
||||
def create_price_list(self, field, date):
|
||||
pool = Pool()
|
||||
PriceList = pool.get('product.price_list')
|
||||
|
||||
price_list, = PriceList.create([{
|
||||
'name': "Price List",
|
||||
'price': 'list_price',
|
||||
'lines': [('create', [{
|
||||
field: date,
|
||||
'formula': 'unit_price * 0.9',
|
||||
}, {
|
||||
'formula': 'unit_price',
|
||||
}])],
|
||||
}])
|
||||
return price_list
|
||||
|
||||
def create_product(self, list_price=Decimal(10)):
|
||||
pool = Pool()
|
||||
Product = pool.get('product.product')
|
||||
Template = pool.get('product.template')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
unit, = Uom.search([('name', '=', "Unit")])
|
||||
template = Template(
|
||||
name="Template", list_price=list_price, default_uom=unit)
|
||||
template.save()
|
||||
product = Product(template=template)
|
||||
product.save()
|
||||
return product
|
||||
|
||||
@with_transaction()
|
||||
def test_price_list_start_date(self):
|
||||
"Test price list with start date"
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
today = Date.today()
|
||||
tomorrow = today + datetime.timedelta(days=1)
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
product = self.create_product()
|
||||
uom = product.default_uom
|
||||
price_list = self.create_price_list('start_date', tomorrow)
|
||||
|
||||
self.assertEqual(
|
||||
price_list.compute(
|
||||
product, 1, uom, pattern={'date': today}),
|
||||
Decimal(10))
|
||||
self.assertEqual(
|
||||
price_list.compute(
|
||||
product, 1, uom, pattern={'date': tomorrow}),
|
||||
Decimal(9))
|
||||
|
||||
@with_transaction()
|
||||
def test_price_list_end_date(self):
|
||||
"Test price list with end date"
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
today = Date.today()
|
||||
yesterday = today - datetime.timedelta(days=1)
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
product = self.create_product()
|
||||
uom = product.default_uom
|
||||
price_list = self.create_price_list('end_date', yesterday)
|
||||
|
||||
self.assertEqual(
|
||||
price_list.compute(
|
||||
product, 1, uom, pattern={'date': today}),
|
||||
Decimal(10))
|
||||
self.assertEqual(
|
||||
price_list.compute(
|
||||
product, 1, uom, pattern={'date': yesterday}),
|
||||
Decimal(9))
|
||||
|
||||
@with_transaction()
|
||||
def test_price_list_with_context_date(self):
|
||||
"Test price list with context date"
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
today = Date.today()
|
||||
tomorrow = today + datetime.timedelta(days=1)
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
product = self.create_product()
|
||||
uom = product.default_uom
|
||||
price_list = self.create_price_list('start_date', tomorrow)
|
||||
|
||||
with Transaction().set_context(date=today):
|
||||
self.assertEqual(
|
||||
price_list.compute(product, 1, uom),
|
||||
Decimal(10))
|
||||
with Transaction().set_context(date=tomorrow):
|
||||
self.assertEqual(
|
||||
price_list.compute(product, 1, uom),
|
||||
Decimal(9))
|
||||
|
||||
@with_transaction()
|
||||
def test_price_list_cache(self):
|
||||
"Test price list cache"
|
||||
pool = Pool()
|
||||
Cache = pool.get('product.price_list.cache')
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
today = Date.today()
|
||||
tomorrow = today + datetime.timedelta(days=1)
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
product = self.create_product()
|
||||
uom = product.default_uom
|
||||
price_list = self.create_price_list('start_date', tomorrow)
|
||||
|
||||
price_list.fill_cache()
|
||||
|
||||
caches = Cache.search([])
|
||||
self.assertEqual(len(caches), 2)
|
||||
|
||||
for date, result in [
|
||||
(today, Decimal(10)),
|
||||
(tomorrow, Decimal(9)),
|
||||
]:
|
||||
with self.subTest(date=date):
|
||||
with Transaction().set_context(date=date):
|
||||
cache = Cache.get(price_list, product)
|
||||
self.assertEqual(cache.get_unit_price(1, uom), result)
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
30
modules/product_price_list_dates/tryton.cfg
Normal file
30
modules/product_price_list_dates/tryton.cfg
Normal file
@@ -0,0 +1,30 @@
|
||||
[tryton]
|
||||
version=7.8.0
|
||||
depends:
|
||||
ir
|
||||
product_price_list
|
||||
extras_depend:
|
||||
product_price_list_cache
|
||||
purchase_price_list
|
||||
sale_price_list
|
||||
xml:
|
||||
product.xml
|
||||
|
||||
[register]
|
||||
model:
|
||||
product.PriceList
|
||||
product.PriceListLine
|
||||
product.PriceListLineContext
|
||||
|
||||
[register product_price_list_cache]
|
||||
model:
|
||||
product.PriceListCache
|
||||
|
||||
[register purchase_price_list]
|
||||
model:
|
||||
purchase.Line
|
||||
|
||||
[register sale_price_list]
|
||||
model:
|
||||
sale.Line
|
||||
product.SaleContext
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form" position="inside">
|
||||
<newline/>
|
||||
<label name="date"/>
|
||||
<field name="date"/>
|
||||
<newline/>
|
||||
</xpath>
|
||||
</data>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/field[@name='sequence']" position="after">
|
||||
<label name="start_date"/>
|
||||
<group id="start_end_date" col="3">
|
||||
<field name="start_date"/>
|
||||
<label name="end_date"/>
|
||||
<field name="end_date"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</data>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='sequence']" position="after">
|
||||
<field name="start_date"/>
|
||||
<field name="end_date"/>
|
||||
</xpath>
|
||||
</data>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='category']" position="before">
|
||||
<field name="start_date"/>
|
||||
<field name="end_date"/>
|
||||
</xpath>
|
||||
</data>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form" position="inside">
|
||||
<field name="date" invisible="1" colspan="4"/>
|
||||
</xpath>
|
||||
</data>
|
||||
Reference in New Issue
Block a user