Add cron to deactivate variants with stock 0 | #046284
This commit is contained in:
parent
0cc6648220
commit
23e511735f
|
@ -25,6 +25,8 @@ def register():
|
|||
product.Certification,
|
||||
product.Container,
|
||||
product.Product,
|
||||
product.ProductConfiguration,
|
||||
product.Cron,
|
||||
product.ProductCrop,
|
||||
product.ProductDO,
|
||||
product.ProductEcological,
|
||||
|
|
44
product.py
44
product.py
|
@ -1,12 +1,14 @@
|
|||
# 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 datetime import datetime
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.pyson import Eval
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
from trytond.modules.agronomics.wine import WineMixin
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class Certification(ModelSQL, ModelView):
|
||||
|
@ -29,6 +31,12 @@ class Container(ModelSQL, ModelView):
|
|||
capacity = fields.Numeric('Capacity', digits=(16, 2))
|
||||
|
||||
|
||||
class ProductConfiguration(metaclass=PoolMeta):
|
||||
__name__ = 'product.configuration'
|
||||
|
||||
variant_deactivation_time = fields.TimeDelta('Variant Deactivation Time')
|
||||
|
||||
|
||||
class Template(metaclass=PoolMeta):
|
||||
__name__ = 'product.template'
|
||||
|
||||
|
@ -55,6 +63,8 @@ class Template(metaclass=PoolMeta):
|
|||
|
||||
quality_weighing = fields.Many2One('quality.template', 'Quality Weighing')
|
||||
|
||||
variant_deactivate_stock_zero = fields.Boolean('Variant Deactivate Stock 0')
|
||||
|
||||
def get_capacity(self, name):
|
||||
if self.container:
|
||||
return self.container.capacity
|
||||
|
@ -109,6 +119,26 @@ class Product(WineMixin, metaclass=PoolMeta):
|
|||
'bottled-wine']
|
||||
)}, depends=['agronomic_type']), 'get_alcohol_volume')
|
||||
|
||||
@classmethod
|
||||
def deactivate_no_stock_variants_cron(cls):
|
||||
pool = Pool()
|
||||
Location = pool.get('stock.location')
|
||||
ProductConfiguration = pool.get('product.configuration')
|
||||
config = ProductConfiguration(1)
|
||||
locations = Location.search(['type', '=', 'warehouse'])
|
||||
locations = [location.id for location in locations]
|
||||
with Transaction().set_context(locations=locations, with_childs=True):
|
||||
products = cls.search(
|
||||
[
|
||||
('quantity', '=', 0),
|
||||
('template.variant_deactivate_stock_zero', '=', True),
|
||||
('create_date', '<',
|
||||
(datetime.now() - config.variant_deactivation_time))
|
||||
])
|
||||
for product in products:
|
||||
product.active = False
|
||||
cls.save(products)
|
||||
|
||||
@classmethod
|
||||
def validate(cls, products):
|
||||
for product in products:
|
||||
|
@ -130,6 +160,18 @@ class Product(WineMixin, metaclass=PoolMeta):
|
|||
Decimal(str(10 ** -self.__class__.alcohol_volume.digits[1])))
|
||||
|
||||
|
||||
class Cron(metaclass=PoolMeta):
|
||||
__name__ = 'ir.cron'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Cron, cls).__setup__()
|
||||
cls.method.selection.append(
|
||||
('product.product|deactivate_no_stock_variants_cron',
|
||||
"Deactivate Variants"),
|
||||
)
|
||||
|
||||
|
||||
class ProductCrop(ModelSQL):
|
||||
"Product - Crop"
|
||||
__name__ = 'product.product-agronomics.crop'
|
||||
|
|
14
product.xml
14
product.xml
|
@ -79,6 +79,20 @@
|
|||
<field name="action" ref="act_product_qualitative_test_lines"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.cron" id="cron_variant_deactivation">
|
||||
<field name="active" eval="True" />
|
||||
<field name="interval_number" eval="24" />
|
||||
<field name="interval_type">hours</field>
|
||||
<field name="method">product.product|deactivate_no_stock_variants_cron</field>
|
||||
</record>
|
||||
|
||||
<!-- Product Configuration-->
|
||||
<record model="ir.ui.view" id="product_configuration_view_form">
|
||||
<field name="model">product.configuration</field>
|
||||
<field name="name">product_configuration_form</field>
|
||||
<field name="inherit" ref="product.product_configuration_view_form"/>
|
||||
</record>
|
||||
|
||||
<!-- Certification -->
|
||||
<record model="ir.ui.view" id="certification_view_form">
|
||||
<field name="model">agronomics.certification</field>
|
||||
|
|
|
@ -11,6 +11,8 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="capacity"/>
|
||||
<label name="quality_weighing"/>
|
||||
<field name="quality_weighing"/>
|
||||
<label name="variant_deactivate_stock_zero"/>
|
||||
<field name="variant_deactivate_stock_zero"/>
|
||||
</xpath>
|
||||
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue