diff --git a/__init__.py b/__init__.py index e07d156a81..a1f197c460 100644 --- a/__init__.py +++ b/__init__.py @@ -11,13 +11,16 @@ from .party import PartyReplace def register(): Pool.register( Configuration, + ConfigurationSequence, ShipmentDrop, Move, SaleConfig, + SaleConfigSaleDropLocation, Sale, SaleLine, PurchaseRequest, PurchaseConfig, + PurchaseConfigPurchaseDropLocation, Purchase, PurchaseLine, ProductSupplier, diff --git a/purchase.py b/purchase.py index f54ca013a0..9ce6be4d15 100644 --- a/purchase.py +++ b/purchase.py @@ -1,13 +1,18 @@ # 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 import backend +from trytond.model import ModelSQL, ValueMixin, fields from trytond.pyson import Eval from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction +from trytond.tools.multivalue import migrate_property -__all__ = ['PurchaseRequest', 'PurchaseConfig', 'Purchase', 'PurchaseLine', +__all__ = ['PurchaseRequest', 'PurchaseConfig', + 'PurchaseConfigPurchaseDropLocation', 'Purchase', 'PurchaseLine', 'ProductSupplier', 'CreatePurchase', 'PurchaseHandleShipmentException'] +purchase_drop_location = fields.Many2One( + 'stock.location', "Purchase Drop Location", domain=[('type', '=', 'drop')]) class PurchaseRequest: @@ -31,9 +36,44 @@ class PurchaseConfig: __metaclass__ = PoolMeta __name__ = 'purchase.configuration' - purchase_drop_location = fields.Property( - fields.Many2One('stock.location', 'Purchase Drop Location', - domain=[('type', '=', 'drop')])) + purchase_drop_location = fields.MultiValue(purchase_drop_location) + + @classmethod + def default_purchase_drop_location(cls, **pattern): + return cls.multivalue_model( + 'purchase_drop_location').default_purchase_drop_location() + + +class PurchaseConfigPurchaseDropLocation(ModelSQL, ValueMixin): + "Purchase Configuration Purchase Drop Location" + __name__ = 'purchase.configuration.purchase_drop_location' + purchase_drop_location = purchase_drop_location + + @classmethod + def __register__(cls, module_name): + TableHandler = backend.get('TableHandler') + exist = TableHandler.table_exist(cls._table) + + super(PurchaseConfigPurchaseDropLocation, cls).__register__( + module_name) + + if not exist: + cls._migrate_property([], [], []) + + @classmethod + def _migrate_property(cls, field_names, value_names, fields): + field_names.append('purchase_drop_location') + value_names.append('purchase_drop_location') + migrate_property( + 'purchase.configuration', field_names, cls, value_names, + fields=fields) + + @classmethod + def default_purchase_drop_location(cls): + pool = Pool() + ModelData = pool.get('ir.model.data') + return ModelData.get_id( + 'sale_supply_drop_shipment', 'location_drop') class Purchase: diff --git a/sale.py b/sale.py index e1f1a7c9e2..f482b18799 100644 --- a/sale.py +++ b/sale.py @@ -1,20 +1,59 @@ # 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 import backend +from trytond.model import ModelSQL, ValueMixin, fields from trytond.pyson import Eval from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction +from trytond.tools.multivalue import migrate_property -__all__ = ['SaleConfig', 'Sale', 'SaleLine'] +__all__ = ['SaleConfig', 'SaleConfigSaleDropLocation', 'Sale', 'SaleLine'] +sale_drop_location = fields.Many2One( + 'stock.location', "Sale Drop Location", domain=[('type', '=', 'drop')]) class SaleConfig: __metaclass__ = PoolMeta __name__ = 'sale.configuration' - sale_drop_location = fields.Property( - fields.Many2One('stock.location', 'Sale Drop Location', - domain=[('type', '=', 'drop')])) + sale_drop_location = fields.MultiValue(sale_drop_location) + + @classmethod + def default_sale_drop_location(cls, **pattern): + return cls.multivalue_model( + 'sale_drop_location').default_sale_drop_location() + + +class SaleConfigSaleDropLocation(ModelSQL, ValueMixin): + "Sale Configuration Sale Drop Location" + __name__ = 'sale.configuration.sale_drop_location' + sale_drop_location = sale_drop_location + + @classmethod + def __register__(cls, module_name): + TableHandler = backend.get('TableHandler') + exist = TableHandler.table_exist(cls._table) + + super(SaleConfigSaleDropLocation, cls).__register__( + module_name) + + if not exist: + cls._migrate_property([], [], []) + + @classmethod + def _migrate_property(cls, field_names, value_names, fields): + field_names.append('sale_drop_location') + value_names.append('sale_drop_location') + migrate_property( + 'sale.configuration', field_names, cls, value_names, + fields=fields) + + @classmethod + def default_sale_drop_location(cls): + pool = Pool() + ModelData = pool.get('ir.model.data') + return ModelData.get_id( + 'sale_supply_drop_shipment', 'location_drop') class Sale: diff --git a/stock.py b/stock.py index 0455227c8a..3713a7b892 100644 --- a/stock.py +++ b/stock.py @@ -6,6 +6,7 @@ from decimal import Decimal from sql.operators import Concat from sql.aggregate import Count +from trytond import backend from trytond.model import Workflow, ModelView, ModelSQL, fields from trytond.pyson import Eval, If from trytond.pool import Pool, PoolMeta @@ -13,19 +14,71 @@ from trytond.transaction import Transaction from trytond.tools import grouped_slice -__all__ = ['Configuration', 'ShipmentDrop', 'Move'] +__all__ = ['Configuration', 'ConfigurationSequence', 'ShipmentDrop', 'Move'] class Configuration: __metaclass__ = PoolMeta __name__ = 'stock.configuration' - shipment_drop_sequence = fields.Property(fields.Many2One('ir.sequence', - 'Drop Shipment Sequence', domain=[ + shipment_drop_sequence = fields.MultiValue(fields.Many2One( + 'ir.sequence', "Drop Shipment Sequence", required=True, + domain=[ ('company', 'in', [Eval('context', {}).get('company', -1), None]), ('code', '=', 'stock.shipment.drop'), - ], required=True)) + ])) + + @classmethod + def multivalue_model(cls, field): + pool = Pool() + if field == 'shipment_drop_sequence': + return pool.get('stock.configuration.sequence') + return super(Configuration, cls).multivalue_model(field) + + @classmethod + def default_shipment_drop_sequence(cls, **pattern): + return cls.multivalue_model( + 'shipment_drop_sequence').default_shipment_drop_sequence() + + +class ConfigurationSequence: + __metaclass__ = PoolMeta + __name__ = 'stock.configuration.sequence' + shipment_drop_sequence = fields.Many2One( + 'ir.sequence', "Drop Shipment Sequence", required=True, + domain=[ + ('company', 'in', [Eval('company', -1), None]), + ('code', '=', 'stock.shipment.drop'), + ], + depends=['company']) + + @classmethod + def __register__(cls, module_name): + TableHandler = backend.get('TableHandler') + exist = TableHandler.table_exist(cls._table) + if exist: + table = TableHandler(cls, module_name) + exist &= table.column_exist('shipment_drop_sequence') + + super(ConfigurationSequence, cls).__register__(module_name) + + if not exist: + cls._migrate_property([], [], []) + + @classmethod + def _migrate_property(cls, field_names, value_names, fields): + field_names.append('shipment_drop_sequence') + value_names.append('shipment_drop_sequence') + super(ConfigurationSequence, cls)._migrate_property( + field_names, value_names, fields) + + @classmethod + def default_shipment_drop_sequence(cls): + pool = Pool() + ModelData = pool.get('ir.model.data') + return ModelData.get_id( + 'sale_supply_drop_shipment', 'sequence_shipment_drop') class ShipmentDrop(Workflow, ModelSQL, ModelView): diff --git a/stock.xml b/stock.xml index 1e960c933f..fa59c5ae5e 100644 --- a/stock.xml +++ b/stock.xml @@ -202,24 +202,5 @@ this repository contains the full copyright notices and license terms. --> drop - - - - - - - - - - - - - -