fix create inventory
This commit is contained in:
parent
b090f21359
commit
b4407b609a
|
@ -23,7 +23,6 @@ def register():
|
|||
shipment.ShipmentDetailedStart,
|
||||
inventory.Inventory,
|
||||
inventory.CreateInventoriesStart,
|
||||
inventory.InventoryProductCategory,
|
||||
module='stock_co', type_='model')
|
||||
Pool.register(
|
||||
shipment.ShipmentDetailed,
|
||||
|
|
101
inventory.py
101
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)
|
||||
|
|
|
@ -9,7 +9,8 @@ this repository contains the full copyright notices and license terms. -->
|
|||
</xpath>
|
||||
<xpath
|
||||
expr="/form/field[@name='complete_lines']" position="after">
|
||||
<newline/>
|
||||
<field name="categories" colspan="4"/>
|
||||
<label name="category" />
|
||||
<field name="category" />
|
||||
<field name="products" colspan="4"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
|
@ -9,6 +9,16 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<label name="approved_by"/>
|
||||
<field name="approved_by"/>
|
||||
</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
|
||||
expr="/form/field[@name='lines']" position="replace">
|
||||
<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"/>
|
||||
</page>
|
||||
<page string="Other Info" id="info">
|
||||
<field name="categories" colspan="4"/>
|
||||
<label name="comment"/>
|
||||
<field name="comment" yexpand="0" width="25"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</xpath>
|
||||
|
|
Loading…
Reference in New Issue