Change supply_on_sale into selection
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Change supply_on_sale into selection
|
||||
* Remove support for Python 3.7
|
||||
* Add support for Python 3.11
|
||||
* Notify when product is supplied on sale and has purchase order point
|
||||
|
||||
@@ -1,20 +1,47 @@
|
||||
# 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 sql import Literal
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class Template(metaclass=PoolMeta):
|
||||
__name__ = 'product.template'
|
||||
|
||||
supply_on_sale = fields.Boolean('Supply On Sale',
|
||||
supply_on_sale = fields.Selection([
|
||||
(None, "Never"),
|
||||
('always', "Always"),
|
||||
], "Supply On Sale",
|
||||
states={
|
||||
'invisible': ~Eval('purchasable') | ~Eval('salable'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def __resgister__(cls, module):
|
||||
table_h = cls.__table_handler__(module)
|
||||
table = cls.__table__()
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
migrate_supply_on_sale = table_h.column_is_type(
|
||||
'supply_on_sale', 'BOOL')
|
||||
if migrate_supply_on_sale:
|
||||
table_h.column_rename('supply_on_sale', '_temp_supply_on_sale')
|
||||
|
||||
super().__register__(module)
|
||||
|
||||
# Migration from 6.6: convert supply_on_sale from boolean to selection
|
||||
if migrate_supply_on_sale:
|
||||
cursor.execute(*table.update(
|
||||
[table.supply_on_sale],
|
||||
['always'],
|
||||
where=table._temp_supply_on_sale == Literal(True)))
|
||||
table_h.drop_column('_temp_supply_on_sale')
|
||||
|
||||
@fields.depends(methods=['_notify_order_point'])
|
||||
def on_change_notify(self):
|
||||
notifications = super().on_change_notify()
|
||||
|
||||
@@ -121,7 +121,7 @@ class Line(metaclass=PoolMeta):
|
||||
or any(m.state not in ['staging', 'cancelled']
|
||||
for m in self.moves)):
|
||||
return False
|
||||
return self.product.supply_on_sale
|
||||
return bool(self.product.supply_on_sale)
|
||||
|
||||
def get_move(self, shipment_type):
|
||||
move = super().get_move(shipment_type)
|
||||
|
||||
@@ -99,7 +99,7 @@ Create product::
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.supply_on_sale = True
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
@@ -208,7 +208,7 @@ not create a new purchase request::
|
||||
>>> changing_template.salable = True
|
||||
>>> changing_template.list_price = Decimal('10')
|
||||
>>> changing_template.account_category = account_category
|
||||
>>> changing_template.supply_on_sale = False
|
||||
>>> changing_template.supply_on_sale = None
|
||||
>>> changing_template.save()
|
||||
>>> changing_product, = changing_template.products
|
||||
|
||||
@@ -247,7 +247,7 @@ not create a new purchase request::
|
||||
>>> shipment.click('pack')
|
||||
|
||||
>>> set_user(admin_user)
|
||||
>>> changing_template.supply_on_sale = True
|
||||
>>> changing_template.supply_on_sale = 'always'
|
||||
>>> changing_template.save()
|
||||
|
||||
>>> set_user(stock_user)
|
||||
|
||||
@@ -73,7 +73,7 @@ Create product::
|
||||
>>> template.salable = True
|
||||
>>> template.purchasable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.supply_on_sale = True
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
@@ -210,7 +210,7 @@ class ProductSupplier(metaclass=PoolMeta):
|
||||
def on_change_with_drop_shipment_available(self, name=None):
|
||||
product = self.product or self.template
|
||||
if product and product.type in {'goods', 'assets'}:
|
||||
return product.supply_on_sale
|
||||
return bool(product.supply_on_sale)
|
||||
|
||||
|
||||
class RequestCreatePurchase(metaclass=PoolMeta):
|
||||
|
||||
@@ -123,7 +123,7 @@ Create product::
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.supply_on_sale = True
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ Create product::
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.supply_on_sale = True
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ Create product::
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.supply_on_sale = True
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
@@ -53,7 +53,7 @@ Create product::
|
||||
>>> template.type = 'goods'
|
||||
>>> template.producible = True
|
||||
>>> template.salable = True
|
||||
>>> template.supply_on_sale = True
|
||||
>>> template.supply_on_sale = 'always'
|
||||
>>> template.list_price = Decimal(30)
|
||||
>>> template.account_category = account_category
|
||||
>>> product, = template.products
|
||||
|
||||
Reference in New Issue
Block a user