diff --git a/__init__.py b/__init__.py index 8c96417..95e4b75 100644 --- a/__init__.py +++ b/__init__.py @@ -23,7 +23,6 @@ def register(): shipment.ShipmentDetailedStart, inventory.Inventory, inventory.CreateInventoriesStart, - inventory.InventoryProductCategory, module='stock_co', type_='model') Pool.register( shipment.ShipmentDetailed, diff --git a/inventory.py b/inventory.py index 3adecbf..0f7b142 100644 --- a/inventory.py +++ b/inventory.py @@ -1,15 +1,20 @@ # 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, ModelSQL +from trytond.model import fields, ModelSQL, ModelView, Workflow from trytond.pool import Pool, PoolMeta from trytond.modules.company.model import employee_field +from trytond.pyson import Eval, If class CreateInventoriesStart(metaclass=PoolMeta): __name__ = 'stock.inventory.create.start' - assign_to = employee_field("Assign To") - categories = fields.Many2Many('product.category', None, None, 'Product Categories') + assign_to = employee_field('Assing To') + category = fields.Many2One('product.category', 'Category', 'Product Categories') + products = fields.Many2Many('product.product', None, None, 'Products', + domain=[If(Eval('category'), + ('template.categories', '=', Eval('category')), ())], + depends=['categories']) class CreateInventories(metaclass=PoolMeta): @@ -17,46 +22,78 @@ class CreateInventories(metaclass=PoolMeta): def get_inventory(self, location, Inventory): inventory = super(CreateInventories, self).get_inventory(location, Inventory) - if self.start.categories: + if self.start.products: self.start.complete_lines = False - pool = Pool() - Product = pool.get('product.product') - categories = [s.id for s in self.start.categories] - products = Product.search_read([ - ('template.categories', 'in', categories) - ]) - prd_ids = [{'product': p['id']} for p in products] + products = [s.id for s in self.start.products] + prd_ids = [{'product': p} for p in products] inventory.assign_to = self.start.assign_to inventory.lines = prd_ids return inventory - def do_create_(self, action): - action, data = super(CreateInventories, self).do_create_(action) - if self.start.categories: - Inventory = Pool().get('stock.inventory') - inventories = Inventory.browse(data['res_id']) - Inventory.write(inventories, { - 'categories': [('add', self.start.categories)] - }) - return action, data - class Inventory(metaclass=PoolMeta): 'Stock Inventory' __name__ = 'stock.inventory' - assign_to = employee_field("Assign To") + assign_to = employee_field('Assing To') approved_by = employee_field("Approved By") - categories = fields.Many2Many('stock.inventory.product_category', 'inventory', - 'category', 'Product Categories', states={'readonly': True}) + comment = fields.Text('Comment') + complete_line = fields.Boolean( + "Complete", + help="Add an inventory line for each missing product.") + + @classmethod + def __setup__(cls): + super(Inventory, cls).__setup__() + cls.state.selection.extend([('pre_count', 'Pre-count'), ]) + cls._transitions |= set(( + ('draft', 'pre_count'), + ('pre_count', 'done'), + ('pre_count', 'draft'), + ('draft', 'cancelled'), + )) + cls._buttons.update({ + 'pre_count': { + 'invisible': Eval('state') != 'draft', + 'depends': ['state'], + }, + 'draft': { + 'invisible': Eval('state') != 'pre_count', + 'depends': ['state'], + }, + }) + + @classmethod + @ModelView.button + @Workflow.transition('pre_count') + def pre_count(cls, inventories): + pass + + @classmethod + @ModelView.button + @Workflow.transition('draft') + def draft(cls, inventories): + pass + + @classmethod + @ModelView.button_action('stock.wizard_inventory_count') + def count(cls, inventories): + complete_inv = {'yes': [], 'no': []} + for inventory in inventories: + if inventory.complete_line: + complete_inv['yes'].append(inventory) + else: + complete_inv['no'].append(inventory) + cls.complete_lines(complete_inv['yes'], fill=True) + cls.complete_lines(complete_inv['no'], fill=False) -class InventoryProductCategory(ModelSQL): - "Inventory -Product Category" - __name__ = "stock.inventory.product_category" - _table = 'stock_inventory_product_category_rel' - inventory = fields.Many2One('stock.inventory', 'Inventory', - ondelete='CASCADE', select=True, required=True) - category = fields.Many2One('product.category', 'Product Category', - ondelete='CASCADE', select=True, required=True) +# class InventoryProductCategory(ModelSQL): +# "Inventory -Product Category" +# __name__ = "stock.inventory.product_category" +# _table = 'stock_inventory_product_category_rel' +# inventory = fields.Many2One('stock.inventory', 'Inventory', +# ondelete='CASCADE', select=True, required=True) +# category = fields.Many2One('product.category', 'Product Category', +# ondelete='CASCADE', select=True, required=True) diff --git a/view/inventory_create_start_form.xml b/view/inventory_create_start_form.xml index d9233f4..da00a87 100644 --- a/view/inventory_create_start_form.xml +++ b/view/inventory_create_start_form.xml @@ -9,7 +9,8 @@ this repository contains the full copyright notices and license terms. --> - - + diff --git a/view/inventory_form.xml b/view/inventory_form.xml index 579884b..08fb8b8 100644 --- a/view/inventory_form.xml +++ b/view/inventory_form.xml @@ -9,6 +9,16 @@ this repository contains the full copyright notices and license terms. -->