fix create inventory

This commit is contained in:
wilson gomez 2021-10-12 11:06:49 -05:00
parent b090f21359
commit b4407b609a
4 changed files with 84 additions and 36 deletions

View file

@ -23,7 +23,6 @@ def register():
shipment.ShipmentDetailedStart, shipment.ShipmentDetailedStart,
inventory.Inventory, inventory.Inventory,
inventory.CreateInventoriesStart, inventory.CreateInventoriesStart,
inventory.InventoryProductCategory,
module='stock_co', type_='model') module='stock_co', type_='model')
Pool.register( Pool.register(
shipment.ShipmentDetailed, shipment.ShipmentDetailed,

View file

@ -1,15 +1,20 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of # This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms. # 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.pool import Pool, PoolMeta
from trytond.modules.company.model import employee_field from trytond.modules.company.model import employee_field
from trytond.pyson import Eval, If
class CreateInventoriesStart(metaclass=PoolMeta): class CreateInventoriesStart(metaclass=PoolMeta):
__name__ = 'stock.inventory.create.start' __name__ = 'stock.inventory.create.start'
assign_to = employee_field("Assign To") assign_to = employee_field('Assing To')
categories = fields.Many2Many('product.category', None, None, 'Product Categories') 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): class CreateInventories(metaclass=PoolMeta):
@ -17,46 +22,78 @@ class CreateInventories(metaclass=PoolMeta):
def get_inventory(self, location, Inventory): def get_inventory(self, location, Inventory):
inventory = super(CreateInventories, self).get_inventory(location, Inventory) inventory = super(CreateInventories, self).get_inventory(location, Inventory)
if self.start.categories: if self.start.products:
self.start.complete_lines = False self.start.complete_lines = False
pool = Pool() products = [s.id for s in self.start.products]
Product = pool.get('product.product') prd_ids = [{'product': p} for p in products]
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]
inventory.assign_to = self.start.assign_to inventory.assign_to = self.start.assign_to
inventory.lines = prd_ids inventory.lines = prd_ids
return inventory 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): class Inventory(metaclass=PoolMeta):
'Stock Inventory' 'Stock Inventory'
__name__ = 'stock.inventory' __name__ = 'stock.inventory'
assign_to = employee_field("Assign To") assign_to = employee_field('Assing To')
approved_by = employee_field("Approved By") approved_by = employee_field("Approved By")
categories = fields.Many2Many('stock.inventory.product_category', 'inventory', comment = fields.Text('Comment')
'category', 'Product Categories', states={'readonly': True}) 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): # class InventoryProductCategory(ModelSQL):
"Inventory -Product Category" # "Inventory -Product Category"
__name__ = "stock.inventory.product_category" # __name__ = "stock.inventory.product_category"
_table = 'stock_inventory_product_category_rel' # _table = 'stock_inventory_product_category_rel'
inventory = fields.Many2One('stock.inventory', 'Inventory', # inventory = fields.Many2One('stock.inventory', 'Inventory',
ondelete='CASCADE', select=True, required=True) # ondelete='CASCADE', select=True, required=True)
category = fields.Many2One('product.category', 'Product Category', # category = fields.Many2One('product.category', 'Product Category',
ondelete='CASCADE', select=True, required=True) # ondelete='CASCADE', select=True, required=True)

View file

@ -9,7 +9,8 @@ this repository contains the full copyright notices and license terms. -->
</xpath> </xpath>
<xpath <xpath
expr="/form/field[@name='complete_lines']" position="after"> expr="/form/field[@name='complete_lines']" position="after">
<newline/> <label name="category" />
<field name="categories" colspan="4"/> <field name="category" />
<field name="products" colspan="4"/>
</xpath> </xpath>
</data> </data>

View file

@ -9,6 +9,16 @@ this repository contains the full copyright notices and license terms. -->
<label name="approved_by"/> <label name="approved_by"/>
<field name="approved_by"/> <field name="approved_by"/>
</xpath> </xpath>
<xpath
expr="/form/field[@name='empty_quantity']" position="after">
<label name="complete_line"/>
<field name="complete_line"/>
</xpath>
<xpath
expr="/form/group[@id='buttons']/button[@name='count']" position="after">
<button name="draft" string="Draft"/>
<button name="pre_count" string="Pre-count"/>
</xpath>
<xpath <xpath
expr="/form/field[@name='lines']" position="replace"> expr="/form/field[@name='lines']" position="replace">
<notebook colspan="4"> <notebook colspan="4">
@ -16,7 +26,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="lines" colspan="4" view_ids="stock.inventory_line_view_list_simple"/> <field name="lines" colspan="4" view_ids="stock.inventory_line_view_list_simple"/>
</page> </page>
<page string="Other Info" id="info"> <page string="Other Info" id="info">
<field name="categories" colspan="4"/> <label name="comment"/>
<field name="comment" yexpand="0" width="25"/>
</page> </page>
</notebook> </notebook>
</xpath> </xpath>