Add cron to deactivate variants with stock 0 | #046284
This commit is contained in:
parent
f1de3ee6e0
commit
0b3999e996
|
@ -27,6 +27,8 @@ def register():
|
|||
product.Certification,
|
||||
product.Container,
|
||||
product.Product,
|
||||
product.ProductConfiguration,
|
||||
product.Cron,
|
||||
product.ProductCrop,
|
||||
product.ProductDO,
|
||||
product.ProductEcological,
|
||||
|
|
72
locale/ca.po
72
locale/ca.po
|
@ -226,18 +226,10 @@ msgctxt "field:agronomics.weighing,denomination_origin:"
|
|||
msgid "Denomination of Origin"
|
||||
msgstr "Denominació d'origen"
|
||||
|
||||
msgctxt "field:agronomics.weighing,do:"
|
||||
msgid "Denomination Origin"
|
||||
msgstr "Denominació d'origen"
|
||||
|
||||
msgctxt "field:agronomics.weighing,ecological:"
|
||||
msgid "Ecological"
|
||||
msgstr "Ecològic"
|
||||
|
||||
msgctxt "field:agronomics.weighing,net_weight:"
|
||||
msgid "Net Weight"
|
||||
msgstr "Pes net"
|
||||
|
||||
msgctxt "field:agronomics.weighing,netweight:"
|
||||
msgid "Net Weight"
|
||||
msgstr "Pes net"
|
||||
|
@ -302,10 +294,6 @@ msgctxt "field:agronomics.weighing-agronomics.do,weighing:"
|
|||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,Plantation:"
|
||||
msgid "Plantation"
|
||||
msgstr "Plantacións"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,plantation:"
|
||||
msgid "Plantation"
|
||||
msgstr "Plantacións"
|
||||
|
@ -314,14 +302,6 @@ msgctxt "field:agronomics.weighing-agronomics.plantation,weighing:"
|
|||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantations,Plantation:"
|
||||
msgid "Plantation"
|
||||
msgstr "Plantacións"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantations,weighing:"
|
||||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing.center,name:"
|
||||
msgid "Name"
|
||||
msgstr "Nom"
|
||||
|
@ -336,7 +316,11 @@ msgstr "Parceles"
|
|||
|
||||
msgctxt "field:party.party,plantations:"
|
||||
msgid "Plantation"
|
||||
msgstr "Plantacións"
|
||||
msgstr "Plantació"
|
||||
|
||||
msgctxt "field:product.configuration,variant_deactivation_time:"
|
||||
msgid "Variant Deactivation Time"
|
||||
msgstr "Temps per desactivar variants"
|
||||
|
||||
msgctxt "field:product.product,agronomic_type:"
|
||||
msgid "Agronomic Type"
|
||||
|
@ -390,6 +374,10 @@ msgctxt "field:product.product,shipment_out_quality_template:"
|
|||
msgid "Shipment Out Quality Template"
|
||||
msgstr "Plantilla qualitat albarà sortida"
|
||||
|
||||
msgctxt "field:product.product,variant_deactivate_stock_zero:"
|
||||
msgid "Variant Deactivate Stock 0"
|
||||
msgstr "Desactivar variant amb estoc a 0"
|
||||
|
||||
msgctxt "field:product.product,varieties:"
|
||||
msgid "Varieties"
|
||||
msgstr "Varietats"
|
||||
|
@ -792,15 +780,7 @@ msgstr "Ecològic"
|
|||
|
||||
msgctxt "field:product.product-agronomics.ecological,product:"
|
||||
msgid "Product"
|
||||
msgstr "Productes"
|
||||
|
||||
msgctxt "field:product.product-product.taxon,product:"
|
||||
msgid "Product"
|
||||
msgstr "Productes"
|
||||
|
||||
msgctxt "field:product.product-product.taxon,variety:"
|
||||
msgid "Variety"
|
||||
msgstr "Varietat"
|
||||
msgstr "Producte"
|
||||
|
||||
msgctxt "field:product.template,agronomic_type:"
|
||||
msgid "Agronomic Type"
|
||||
|
@ -818,6 +798,10 @@ msgctxt "field:product.template,quality_weighing:"
|
|||
msgid "Quality Weighing"
|
||||
msgstr "Qualitat pesada"
|
||||
|
||||
msgctxt "field:product.template,variant_deactivate_stock_zero:"
|
||||
msgid "Variant Deactivate Stock 0"
|
||||
msgstr "Desactivar variant amb estoc 0"
|
||||
|
||||
msgctxt "field:product.variety,percent:"
|
||||
msgid "Percent"
|
||||
msgstr "Percentatge"
|
||||
|
@ -1135,10 +1119,6 @@ msgctxt "model:agronomics.weighing-agronomics.plantation,name:"
|
|||
msgid "Weighing - Plantations"
|
||||
msgstr "Pesada - Plantacions"
|
||||
|
||||
msgctxt "model:agronomics.weighing-agronomics.plantations,name:"
|
||||
msgid "Weighing - Plantations"
|
||||
msgstr "Pesada - Plantacions"
|
||||
|
||||
msgctxt "model:agronomics.weighing.center,name:"
|
||||
msgid "Weighing Center"
|
||||
msgstr "Centre de pesada"
|
||||
|
@ -1445,10 +1425,6 @@ msgctxt "model:product.product-agronomics.ecological,name:"
|
|||
msgid "Product - Ecological"
|
||||
msgstr "Producte - Ecològic"
|
||||
|
||||
msgctxt "model:product.product-product.taxon,name:"
|
||||
msgid "Product - Variety"
|
||||
msgstr "Producte - Varietat"
|
||||
|
||||
msgctxt "model:product.variety,name:"
|
||||
msgid "Product Variety"
|
||||
msgstr "Varietat"
|
||||
|
@ -1714,6 +1690,10 @@ msgctxt "selection:agronomics.weighing,state:"
|
|||
msgid "Processing"
|
||||
msgstr "Processos"
|
||||
|
||||
msgctxt "selection:ir.cron,method:"
|
||||
msgid "Deactivate Variants"
|
||||
msgstr "Desactivar variants"
|
||||
|
||||
msgctxt "selection:product.product,agronomic_type:"
|
||||
msgid "Bottled Wine"
|
||||
msgstr "Vi embotellat"
|
||||
|
@ -1818,6 +1798,22 @@ msgctxt "view:product.product:"
|
|||
msgid "Agronomics"
|
||||
msgstr "Agronomics"
|
||||
|
||||
msgctxt "view:product.product:"
|
||||
msgid "Quality"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "view:production.cost_price.distribution:"
|
||||
msgid "%"
|
||||
msgstr "%"
|
||||
|
||||
msgctxt "view:production:"
|
||||
msgid "Cost Distribution"
|
||||
msgstr "Distribució de costos"
|
||||
|
||||
msgctxt "view:production:"
|
||||
msgid "Total"
|
||||
msgstr "Total"
|
||||
|
||||
msgctxt ""
|
||||
"wizard_button:production.cost_price.distribution.template.from.production.template,ask,create_cost_distributions:"
|
||||
msgid "Create"
|
||||
|
|
69
locale/es.po
69
locale/es.po
|
@ -226,18 +226,10 @@ msgctxt "field:agronomics.weighing,denomination_origin:"
|
|||
msgid "Denomination of Origin"
|
||||
msgstr "Denominación de origen"
|
||||
|
||||
msgctxt "field:agronomics.weighing,do:"
|
||||
msgid "Denomination Origin"
|
||||
msgstr "Denominación de origen"
|
||||
|
||||
msgctxt "field:agronomics.weighing,ecological:"
|
||||
msgid "Ecological"
|
||||
msgstr "Ecológico"
|
||||
|
||||
msgctxt "field:agronomics.weighing,net_weight:"
|
||||
msgid "Net Weight"
|
||||
msgstr "Peso neto"
|
||||
|
||||
msgctxt "field:agronomics.weighing,netweight:"
|
||||
msgid "Net Weight"
|
||||
msgstr "Peso neto"
|
||||
|
@ -302,10 +294,6 @@ msgctxt "field:agronomics.weighing-agronomics.do,weighing:"
|
|||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,Plantation:"
|
||||
msgid "Plantation"
|
||||
msgstr "Plantaciónes"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantation,plantation:"
|
||||
msgid "Plantation"
|
||||
msgstr "Plantaciónes"
|
||||
|
@ -314,14 +302,6 @@ msgctxt "field:agronomics.weighing-agronomics.plantation,weighing:"
|
|||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantations,Plantation:"
|
||||
msgid "Plantation"
|
||||
msgstr "Plantaciónes"
|
||||
|
||||
msgctxt "field:agronomics.weighing-agronomics.plantations,weighing:"
|
||||
msgid "Weighing"
|
||||
msgstr "Pesada"
|
||||
|
||||
msgctxt "field:agronomics.weighing.center,name:"
|
||||
msgid "Name"
|
||||
msgstr "Nombre"
|
||||
|
@ -338,6 +318,10 @@ msgctxt "field:party.party,plantations:"
|
|||
msgid "Plantation"
|
||||
msgstr "Plantaciónes"
|
||||
|
||||
msgctxt "field:product.configuration,variant_deactivation_time:"
|
||||
msgid "Variant Deactivation Time"
|
||||
msgstr "Tiempo para desactivar variantes"
|
||||
|
||||
msgctxt "field:product.product,agronomic_type:"
|
||||
msgid "Agronomic Type"
|
||||
msgstr "Tipo Agronómico"
|
||||
|
@ -390,6 +374,10 @@ msgctxt "field:product.product,shipment_out_quality_template:"
|
|||
msgid "Shipment Out Quality Template"
|
||||
msgstr "Plantilla calidad albarán de salida"
|
||||
|
||||
msgctxt "field:product.product,variant_deactivate_stock_zero:"
|
||||
msgid "Variant Deactivate Stock 0"
|
||||
msgstr "Desactivar variante con stock a 0"
|
||||
|
||||
msgctxt "field:product.product,varieties:"
|
||||
msgid "Varieties"
|
||||
msgstr "Variedades"
|
||||
|
@ -794,14 +782,6 @@ msgctxt "field:product.product-agronomics.ecological,product:"
|
|||
msgid "Product"
|
||||
msgstr "Productos"
|
||||
|
||||
msgctxt "field:product.product-product.taxon,product:"
|
||||
msgid "Product"
|
||||
msgstr "Productos"
|
||||
|
||||
msgctxt "field:product.product-product.taxon,variety:"
|
||||
msgid "Variety"
|
||||
msgstr "Variedad"
|
||||
|
||||
msgctxt "field:product.template,agronomic_type:"
|
||||
msgid "Agronomic Type"
|
||||
msgstr "Tipo Agronómico"
|
||||
|
@ -818,6 +798,10 @@ msgctxt "field:product.template,quality_weighing:"
|
|||
msgid "Quality Weighing"
|
||||
msgstr "Calidad pesada"
|
||||
|
||||
msgctxt "field:product.template,variant_deactivate_stock_zero:"
|
||||
msgid "Variant Deactivate Stock 0"
|
||||
msgstr "Desactivar variante con estoc 0"
|
||||
|
||||
msgctxt "field:product.variety,percent:"
|
||||
msgid "Percent"
|
||||
msgstr "Porcentaje"
|
||||
|
@ -966,7 +950,7 @@ msgid "Uom"
|
|||
msgstr "UdM"
|
||||
|
||||
msgctxt "field:production.template,cost_distribution_template:"
|
||||
msgid "Default cost distribution templatea"
|
||||
msgid "Default cost distribution template"
|
||||
msgstr "Plantilla de distribución de costos predeterminada"
|
||||
|
||||
msgctxt "field:production.template,cost_distribution_templates:"
|
||||
|
@ -1135,10 +1119,6 @@ msgctxt "model:agronomics.weighing-agronomics.plantation,name:"
|
|||
msgid "Weighing - Plantations"
|
||||
msgstr "Pesada - Plantación"
|
||||
|
||||
msgctxt "model:agronomics.weighing-agronomics.plantations,name:"
|
||||
msgid "Weighing - Plantations"
|
||||
msgstr "Pesada - Plantación"
|
||||
|
||||
msgctxt "model:agronomics.weighing.center,name:"
|
||||
msgid "Weighing Center"
|
||||
msgstr "Centro de pesada"
|
||||
|
@ -1195,9 +1175,10 @@ msgctxt "model:ir.action,name:act_product_quantitative_test_lines"
|
|||
msgid "Quantitative Lines"
|
||||
msgstr "Líneas cuantitativas"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "model:ir.action,name:act_production_cost_distribution_template_tree"
|
||||
msgid "Templates Cost Price Distribution"
|
||||
msgstr ""
|
||||
msgstr "Distribución de precios de costes de plantillas"
|
||||
|
||||
msgctxt "model:ir.action,name:act_production_cost_price_distribution_tree"
|
||||
msgid "Cost Price Distribution"
|
||||
|
@ -1446,10 +1427,6 @@ msgctxt "model:product.product-agronomics.ecological,name:"
|
|||
msgid "Product - Ecological"
|
||||
msgstr "Producto - Ecológico"
|
||||
|
||||
msgctxt "model:product.product-product.taxon,name:"
|
||||
msgid "Product - Variety"
|
||||
msgstr "Producto - Variedad"
|
||||
|
||||
msgctxt "model:product.variety,name:"
|
||||
msgid "Product Variety"
|
||||
msgstr "Variedad de producto"
|
||||
|
@ -1715,6 +1692,10 @@ msgctxt "selection:agronomics.weighing,state:"
|
|||
msgid "Processing"
|
||||
msgstr "Procesos"
|
||||
|
||||
msgctxt "selection:ir.cron,method:"
|
||||
msgid "Deactivate Variants"
|
||||
msgstr "Desactivar Variantes"
|
||||
|
||||
msgctxt "selection:product.product,agronomic_type:"
|
||||
msgid "Bottled Wine"
|
||||
msgstr "Vino embotellado"
|
||||
|
@ -1823,6 +1804,18 @@ msgctxt "view:product.product:"
|
|||
msgid "Quality"
|
||||
msgstr "Calidad"
|
||||
|
||||
msgctxt "view:production.cost_price.distribution:"
|
||||
msgid "%"
|
||||
msgstr "%"
|
||||
|
||||
msgctxt "view:production:"
|
||||
msgid "Cost Distribution"
|
||||
msgstr "Distribución de costes"
|
||||
|
||||
msgctxt "view:production:"
|
||||
msgid "Total"
|
||||
msgstr "Total"
|
||||
|
||||
msgctxt ""
|
||||
"wizard_button:production.cost_price.distribution.template.from.production.template,ask,create_cost_distributions:"
|
||||
msgid "Create"
|
||||
|
|
45
product.py
45
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 Pool, PoolMeta
|
||||
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'
|
||||
|
||||
|
@ -56,6 +64,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
|
||||
|
@ -106,6 +116,27 @@ class Product(WineMixin, metaclass=PoolMeta):
|
|||
quality_samples = fields.Many2Many('product.product-quality.sample',
|
||||
'product', 'sample', 'Quality Samples')
|
||||
|
||||
@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):
|
||||
if config.variant_deactivation_time:
|
||||
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:
|
||||
|
@ -127,6 +158,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>
|
||||
|
|
|
@ -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="/form" position="inside">
|
||||
<label name="variant_deactivation_time"/>
|
||||
<field name="variant_deactivation_time"/>
|
||||
</xpath>
|
||||
</data>
|
|
@ -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